Mercurial > vim
annotate src/filepath.c @ 31922:440256d03990 v9.0.1293
patch 9.0.1293: the set_num_option() is too long
Commit: https://github.com/vim/vim/commit/0caaf1e46511f7a92e036f05e6aa9d5992540117
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Feb 9 12:23:17 2023 +0000
patch 9.0.1293: the set_num_option() is too long
Problem: The set_num_option() is too long.
Solution: Move code to separate functions. (Yegappan Lakshmanan,
closes #11954)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 Feb 2023 13:30:04 +0100 |
parents | 5948cc887603 |
children | 2c09e40ce3da |
rev | line source |
---|---|
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
18872
410155e75efa
patch 8.1.2422: "make depend" does not work correctly for libvterm
Bram Moolenaar <Bram@vim.org>
parents:
18779
diff
changeset
|
11 * filepath.c: dealing with file names and paths. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 #ifdef MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 * Functions for ":8" filename modifier: get 8.3 version of a filename. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * Get the short path (8.3) for the filename in "fnamep". |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * Only works for a valid file name. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * When the path gets longer "fnamep" is changed and the allocated buffer |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 * is put in "bufp". |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 * *fnamelen is the length of "fnamep" and set to 0 for a nonexistent path. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 * Returns OK on success, FAIL on failure. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 static int |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 get_short_pathname(char_u **fnamep, char_u **bufp, int *fnamelen) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 int l, len; |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
33 WCHAR *newbuf; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
34 WCHAR *wfname; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
35 |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
36 len = MAXPATHL; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
37 newbuf = malloc(len * sizeof(*newbuf)); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
38 if (newbuf == NULL) |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
39 return FAIL; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
40 |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
41 wfname = enc_to_utf16(*fnamep, NULL); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
42 if (wfname == NULL) |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
43 { |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
44 vim_free(newbuf); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
45 return FAIL; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
46 } |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
47 |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
48 l = GetShortPathNameW(wfname, newbuf, len); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 if (l > len - 1) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
51 // If that doesn't work (not enough space), then save the string |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
52 // and try again with a new buffer big enough. |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
53 WCHAR *newbuf_t = newbuf; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
54 newbuf = vim_realloc(newbuf, (l + 1) * sizeof(*newbuf)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 if (newbuf == NULL) |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
56 { |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
57 vim_free(wfname); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
58 vim_free(newbuf_t); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 return FAIL; |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
60 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
61 // Really should always succeed, as the buffer is big enough. |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
62 l = GetShortPathNameW(wfname, newbuf, l+1); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 } |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
64 if (l != 0) |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
65 { |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
66 char_u *p = utf16_to_enc(newbuf, NULL); |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
67 |
18479
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
68 if (p != NULL) |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
69 { |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
70 vim_free(*bufp); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
71 *fnamep = *bufp = p; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
72 } |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
73 else |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
74 { |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
75 vim_free(wfname); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
76 vim_free(newbuf); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
77 return FAIL; |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
78 } |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
79 } |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
80 vim_free(wfname); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
81 vim_free(newbuf); |
cbea1392c393
patch 8.1.2234: get_short_pathname() fails depending on encoding
Bram Moolenaar <Bram@vim.org>
parents:
18261
diff
changeset
|
82 |
18516
9676dc5fd705
patch 8.1.2252: compiler warning for int size
Bram Moolenaar <Bram@vim.org>
parents:
18479
diff
changeset
|
83 *fnamelen = l == 0 ? l : (int)STRLEN(*bufp); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 return OK; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 * Get the short path (8.3) for the filename in "fname". The converted |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 * path is returned in "bufp". |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 * Some of the directories specified in "fname" may not exist. This function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 * will shorten the existing directories at the beginning of the path and then |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 * append the remaining non-existing path. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 * fname - Pointer to the filename to shorten. On return, contains the |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 * pointer to the shortened pathname |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 * bufp - Pointer to an allocated buffer for the filename. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 * fnamelen - Length of the filename pointed to by fname |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 * Returns OK on success (or nothing done) and FAIL on failure (out of memory). |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 static int |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 shortpath_for_invalid_fname( |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 char_u **fname, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 char_u **bufp, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 int *fnamelen) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 char_u *short_fname, *save_fname, *pbuf_unused; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 char_u *endp, *save_endp; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
110 char_u ch; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 int old_len, len; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
112 int new_len, sfx_len; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 int retval = OK; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
115 // Make a copy |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 old_len = *fnamelen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 save_fname = vim_strnsave(*fname, old_len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 pbuf_unused = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 short_fname = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
121 endp = save_fname + old_len - 1; // Find the end of the copy |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 save_endp = endp; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
123 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 * Try shortening the supplied path till it succeeds by removing one |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 * directory at a time from the tail of the path. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 len = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 for (;;) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
131 // go back one path-separator |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 while (endp > save_fname && !after_pathsep(save_fname, endp + 1)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 --endp; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 if (endp <= save_fname) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
135 break; // processed the complete path |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 * Replace the path separator with a NUL and try to shorten the |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 * resulting path. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 ch = *endp; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 *endp = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 short_fname = save_fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 len = (int)STRLEN(short_fname) + 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 if (get_short_pathname(&short_fname, &pbuf_unused, &len) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 retval = FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 goto theend; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
150 *endp = ch; // preserve the string |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 if (len > 0) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
153 break; // successfully shortened the path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
154 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
155 // failed to shorten the path. Skip the path separator |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 --endp; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 if (len > 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 * Succeeded in shortening the path. Now concatenate the shortened |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 * path with the remaining path at the tail. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18516
diff
changeset
|
166 // Compute the length of the new path. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 sfx_len = (int)(save_endp - endp) + 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 new_len = len + sfx_len; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 *fnamelen = new_len; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 if (new_len > old_len) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
174 // There is not enough space in the currently allocated string, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
175 // copy it to a buffer big enough. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 *fname = *bufp = vim_strnsave(short_fname, new_len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 if (*fname == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 retval = FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 goto theend; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
185 // Transfer short_fname to the main buffer (it's big enough), |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
186 // unless get_short_pathname() did its work in-place. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 *fname = *bufp = save_fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 if (short_fname != save_fname) |
28021
d4b549180a07
patch 8.2.4535: filename modifer ":8" removes the filename
Bram Moolenaar <Bram@vim.org>
parents:
27784
diff
changeset
|
189 STRNCPY(save_fname, short_fname, len); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 save_fname = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
193 // concat the not-shortened part of the path |
29113
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28881
diff
changeset
|
194 if ((*fname + len) != endp) |
495d55210aac
patch 8.2.5077: various warnings from clang on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
28881
diff
changeset
|
195 vim_strncpy(*fname + len, endp, sfx_len); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 (*fname)[new_len] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 theend: |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 vim_free(pbuf_unused); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 vim_free(save_fname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 return retval; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 * Get a pathname for a partial path. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 * Returns OK for success, FAIL for failure. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 static int |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 shortpath_for_partial( |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 char_u **fnamep, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 char_u **bufp, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 int *fnamelen) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 int sepcount, len, tflen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 char_u *p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 char_u *pbuf, *tfname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 int hasTilde; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
221 // Count up the path separators from the RHS.. so we know which part |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
222 // of the path to return. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 sepcount = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 for (p = *fnamep; p < *fnamep + *fnamelen; MB_PTR_ADV(p)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 if (vim_ispathsep(*p)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 ++sepcount; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
228 // Need full path first (use expand_env() to remove a "~/") |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 hasTilde = (**fnamep == '~'); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 if (hasTilde) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 pbuf = tfname = expand_env_save(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 pbuf = tfname = FullName_save(*fnamep, FALSE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 len = tflen = (int)STRLEN(tfname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 if (get_short_pathname(&tfname, &pbuf, &len) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 return FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 if (len == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
242 // Don't have a valid filename, so shorten the rest of the |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
243 // path if we can. This CAN give us invalid 8.3 filenames, but |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
244 // there's not a lot of point in guessing what it might be. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 len = tflen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 if (shortpath_for_invalid_fname(&tfname, &pbuf, &len) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 return FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
250 // Count the paths backward to find the beginning of the desired string. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 for (p = tfname + len - 1; p >= tfname; --p) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 if (has_mbyte) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 p -= mb_head_off(tfname, p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 if (vim_ispathsep(*p)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 if (sepcount == 0 || (hasTilde && sepcount == 1)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 sepcount --; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 if (hasTilde) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 --p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 if (p >= tfname) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 *p = '~'; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 return FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 ++p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
274 // Copy in the string - p indexes into tfname - allocated at pbuf |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 *fnamelen = (int)STRLEN(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 *bufp = pbuf; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 *fnamep = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 return OK; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 #endif // MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 * Adjust a filename, according to a string of modifiers. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 * *fnamep must be NUL terminated when called. When returning, the length is |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 * determined by *fnamelen. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 * Returns VALID_ flags or -1 for failure. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 * When there is an error, *fnamep is set to NULL. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 int |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 modify_fname( |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 char_u *src, // string with modifiers |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 int tilde_file, // "~" is a file name, not $HOME |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 int *usedlen, // characters after src that are used |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 char_u **fnamep, // file name so far |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 char_u **bufp, // buffer for allocated file name or NULL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 int *fnamelen) // length of fnamep |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 int valid = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 char_u *tail; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 char_u *s, *p, *pbuf; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 char_u dirname[MAXPATHL]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 int c; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 int has_fullname = 0; |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
306 int has_homerelative = 0; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 #ifdef MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 char_u *fname_start = *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 int has_shortname = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 repeat: |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
313 // ":p" - full path/file_name |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 if (src[*usedlen] == ':' && src[*usedlen + 1] == 'p') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 has_fullname = 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 valid |= VALID_PATH; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
321 // Expand "~/path" for all systems and "~user/path" for Unix and VMS |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 if ((*fnamep)[0] == '~' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 #if !defined(UNIX) && !(defined(VMS) && defined(USER_HOME)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 && ((*fnamep)[1] == '/' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 # ifdef BACKSLASH_IN_FILENAME |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 || (*fnamep)[1] == '\\' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 || (*fnamep)[1] == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 && !(tilde_file && (*fnamep)[1] == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 ) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 *fnamep = expand_env_save(*fnamep); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
334 vim_free(*bufp); // free any allocated file name |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 *bufp = *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 if (*fnamep == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
340 // When "/." or "/.." is used: force expansion to get rid of it. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 for (p = *fnamep; *p != NUL; MB_PTR_ADV(p)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 if (vim_ispathsep(*p) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 && p[1] == '.' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 && (p[2] == NUL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 || vim_ispathsep(p[2]) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 || (p[2] == '.' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 && (p[3] == NUL || vim_ispathsep(p[3]))))) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
352 // FullName_save() is slow, don't use it when not needed. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 if (*p != NUL || !vim_isAbsName(*fnamep)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 *fnamep = FullName_save(*fnamep, *p != NUL); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
356 vim_free(*bufp); // free any allocated file name |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 *bufp = *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 if (*fnamep == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 #ifdef MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 # if _WIN32_WINNT >= 0x0500 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 if (vim_strchr(*fnamep, '~') != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 // Expand 8.3 filename to full path. Needed to make sure the same |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 // file does not have two different names. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 // Note: problem does not occur if _WIN32_WINNT < 0x0500. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 WCHAR *wfname = enc_to_utf16(*fnamep, NULL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 WCHAR buf[_MAX_PATH]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 if (wfname != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 if (GetLongPathNameW(wfname, buf, _MAX_PATH)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 { |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
376 char_u *q = utf16_to_enc(buf, NULL); |
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
377 |
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
378 if (q != NULL) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 vim_free(*bufp); // free any allocated file name |
27523
4c7bb6fd383f
patch 8.2.4289: warnings reported by MSVC
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
381 *bufp = *fnamep = q; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 vim_free(wfname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 #endif |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
389 // Append a path separator to a directory. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 if (mch_isdir(*fnamep)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
392 // Make room for one or two extra characters. |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
393 *fnamep = vim_strnsave(*fnamep, STRLEN(*fnamep) + 2); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
394 vim_free(*bufp); // free any allocated file name |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 *bufp = *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 if (*fnamep == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 add_pathsep(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
402 // ":." - path relative to the current directory |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
403 // ":~" - path relative to the home directory |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
404 // ":8" - shortname path - postponed till after |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 while (src[*usedlen] == ':' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 && ((c = src[*usedlen + 1]) == '.' || c == '~' || c == '8')) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 if (c == '8') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 #ifdef MSWIN |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
412 has_shortname = 1; // Postpone this. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 continue; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 pbuf = NULL; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
417 // Need full path first (use expand_env() to remove a "~/") |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
418 if (!has_fullname && !has_homerelative) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 { |
27621
9a8992489b71
patch 8.2.4337: part of condition is always true
Bram Moolenaar <Bram@vim.org>
parents:
27523
diff
changeset
|
420 if (**fnamep == '~') |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 p = pbuf = expand_env_save(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 p = pbuf = FullName_save(*fnamep, FALSE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 p = *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 has_fullname = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 if (p != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 if (c == '.') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 { |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
434 size_t namelen; |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
435 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 mch_dirname(dirname, MAXPATHL); |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
437 if (has_homerelative) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 { |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
439 s = vim_strsave(dirname); |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
440 if (s != NULL) |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
441 { |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
442 home_replace(NULL, s, dirname, MAXPATHL, TRUE); |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
443 vim_free(s); |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
444 } |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
445 } |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
446 namelen = STRLEN(dirname); |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
447 |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
448 // Do not call shorten_fname() here since it removes the prefix |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
449 // even though the path does not have a prefix. |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
450 if (fnamencmp(p, dirname, namelen) == 0) |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
451 { |
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
452 p += namelen; |
19314
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
453 if (vim_ispathsep(*p)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 { |
19314
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
455 while (*p && vim_ispathsep(*p)) |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
456 ++p; |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
457 *fnamep = p; |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
458 if (pbuf != NULL) |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
459 { |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
460 // free any allocated file name |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
461 vim_free(*bufp); |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
462 *bufp = pbuf; |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
463 pbuf = NULL; |
782f410c5df3
patch 8.2.0215: wrong file name shortening
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
464 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 home_replace(NULL, p, dirname, MAXPATHL, TRUE); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
471 // Only replace it when it starts with '~' |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 if (*dirname == '~') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 s = vim_strsave(dirname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 if (s != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 *fnamep = s; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 *bufp = s; |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
480 has_homerelative = TRUE; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 vim_free(pbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 tail = gettail(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 *fnamelen = (int)STRLEN(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
491 // ":h" - head, remove "/file_name", can be repeated |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
492 // Don't remove the first "/" or "c:\" |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 valid |= VALID_HEAD; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 s = get_past_head(*fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 while (tail > s && after_pathsep(s, tail)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 MB_PTR_BACK(*fnamep, tail); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 *fnamelen = (int)(tail - *fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 #ifdef VMS |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 if (*fnamelen > 0) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
503 *fnamelen += 1; // the path separator is part of the path |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 if (*fnamelen == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
507 // Result is empty. Turn it into "." to make ":cd %:h" work. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 p = vim_strsave((char_u *)"."); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 if (p == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 *bufp = *fnamep = tail = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 *fnamelen = 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 while (tail > s && !after_pathsep(s, tail)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 MB_PTR_BACK(*fnamep, tail); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
522 // ":8" - shortname |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 if (src[*usedlen] == ':' && src[*usedlen + 1] == '8') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 #ifdef MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 has_shortname = 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 #ifdef MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 * Handle ":8" after we have done 'heads' and before we do 'tails'. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 if (has_shortname) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
537 // Copy the string if it is shortened by :h and when it wasn't copied |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
538 // yet, because we are going to change it in place. Avoids changing |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
539 // the buffer name for "%:8". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 if (*fnamelen < (int)STRLEN(*fnamep) || *fnamep == fname_start) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 p = vim_strnsave(*fnamep, *fnamelen); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 if (p == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 *bufp = *fnamep = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
549 // Split into two implementations - makes it easier. First is where |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
550 // there isn't a full name already, second is where there is. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 if (!has_fullname && !vim_isAbsName(*fnamep)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 if (shortpath_for_partial(fnamep, bufp, fnamelen) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 int l = *fnamelen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
560 // Simple case, already have the full-name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
561 // Nearly always shorter, so try first time. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 if (get_short_pathname(fnamep, bufp, &l) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 if (l == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
567 // Couldn't find the filename, search the paths. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 l = *fnamelen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 if (shortpath_for_invalid_fname(fnamep, bufp, &l) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 *fnamelen = l; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 #endif // MSWIN |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
577 // ":t" - tail, just the basename |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 if (src[*usedlen] == ':' && src[*usedlen + 1] == 't') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 *fnamelen -= (int)(tail - *fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 *fnamep = tail; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
585 // ":e" - extension, can be repeated |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
586 // ":r" - root, without extension, can be repeated |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 while (src[*usedlen] == ':' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 && (src[*usedlen + 1] == 'e' || src[*usedlen + 1] == 'r')) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
590 // find a '.' in the tail: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
591 // - for second :e: before the current fname |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
592 // - otherwise: The last '.' |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 if (src[*usedlen + 1] == 'e' && *fnamep > tail) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 s = *fnamep - 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 s = *fnamep + *fnamelen - 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 for ( ; s > tail; --s) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 if (s[0] == '.') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 break; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
600 if (src[*usedlen + 1] == 'e') // :e |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 if (s > tail) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 *fnamelen += (int)(*fnamep - (s + 1)); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 *fnamep = s + 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 #ifdef VMS |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
607 // cut version from the extension |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 s = *fnamep + *fnamelen - 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 for ( ; s > *fnamep; --s) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 if (s[0] == ';') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 if (s > *fnamep) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 *fnamelen = s - *fnamep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 else if (*fnamep <= tail) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 *fnamelen = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
619 else // :r |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 { |
18261
8d09b7f53c71
patch 8.1.2125: fnamemodify() fails when repeating :e
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
621 char_u *limit = *fnamep; |
8d09b7f53c71
patch 8.1.2125: fnamemodify() fails when repeating :e
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
622 |
8d09b7f53c71
patch 8.1.2125: fnamemodify() fails when repeating :e
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
623 if (limit < tail) |
8d09b7f53c71
patch 8.1.2125: fnamemodify() fails when repeating :e
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
624 limit = tail; |
8d09b7f53c71
patch 8.1.2125: fnamemodify() fails when repeating :e
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
625 if (s > limit) // remove one extension |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 *fnamelen = (int)(s - *fnamep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
631 // ":s?pat?foo?" - substitute |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
632 // ":gs?pat?foo?" - global substitute |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 if (src[*usedlen] == ':' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 && (src[*usedlen + 1] == 's' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 || (src[*usedlen + 1] == 'g' && src[*usedlen + 2] == 's'))) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 char_u *str; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 char_u *pat; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 char_u *sub; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 int sep; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 char_u *flags; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 int didit = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 flags = (char_u *)""; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 s = src + *usedlen + 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 if (src[*usedlen + 1] == 'g') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 flags = (char_u *)"g"; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 ++s; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 sep = *s++; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 if (sep) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
655 // find end of pattern |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 p = vim_strchr(s, sep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 if (p != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
659 pat = vim_strnsave(s, p - s); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 if (pat != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 s = p + 1; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
663 // find end of substitution |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 p = vim_strchr(s, sep); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 if (p != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
667 sub = vim_strnsave(s, p - s); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 str = vim_strnsave(*fnamep, *fnamelen); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 if (sub != NULL && str != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 *usedlen = (int)(p + 1 - src); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 s = do_string_sub(str, pat, sub, NULL, flags); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 if (s != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 *fnamep = s; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 *fnamelen = (int)STRLEN(s); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 *bufp = s; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 didit = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 vim_free(sub); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 vim_free(str); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 vim_free(pat); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
688 // after using ":s", repeat all the modifiers |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 if (didit) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 goto repeat; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
696 // vim_strsave_shellescape() needs a NUL terminated string. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 c = (*fnamep)[*fnamelen]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 if (c != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 (*fnamep)[*fnamelen] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 p = vim_strsave_shellescape(*fnamep, FALSE, FALSE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 if (c != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 (*fnamep)[*fnamelen] = c; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 if (p == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 return -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 vim_free(*bufp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 *bufp = *fnamep = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 *fnamelen = (int)STRLEN(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 *usedlen += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 return valid; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 |
22389
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
714 /* |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
715 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname" |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
716 * "trim_len" specifies how many characters to keep for each directory. |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
717 * Must be 1 or more. |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
718 * It's done in-place. |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
719 */ |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
720 static void |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
721 shorten_dir_len(char_u *str, int trim_len) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
722 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
723 char_u *tail, *s, *d; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
724 int skip = FALSE; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
725 int dirchunk_len = 0; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
726 |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
727 tail = gettail(str); |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
728 d = str; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
729 for (s = str; ; ++s) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
730 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
731 if (s >= tail) // copy the whole tail |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
732 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
733 *d++ = *s; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
734 if (*s == NUL) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
735 break; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
736 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
737 else if (vim_ispathsep(*s)) // copy '/' and next char |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
738 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
739 *d++ = *s; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
740 skip = FALSE; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
741 dirchunk_len = 0; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
742 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
743 else if (!skip) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
744 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
745 *d++ = *s; // copy next char |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
746 if (*s != '~' && *s != '.') // and leading "~" and "." |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
747 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
748 ++dirchunk_len; // only count word chars for the size |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
749 |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
750 // keep copying chars until we have our preferred length (or |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
751 // until the above if/else branches move us along) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
752 if (dirchunk_len >= trim_len) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
753 skip = TRUE; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
754 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
755 |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
756 if (has_mbyte) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
757 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
758 int l = mb_ptr2len(s); |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
759 |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
760 while (--l > 0) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
761 *d++ = *++s; |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
762 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
763 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
764 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
765 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
766 |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
767 /* |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
768 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname" |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
769 * It's done in-place. |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
770 */ |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
771 void |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
772 shorten_dir(char_u *str) |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
773 { |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
774 shorten_dir_len(str, 1); |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
775 } |
995f5e061e27
patch 8.2.1743: cannot build without the eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22385
diff
changeset
|
776 |
29371
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
777 /* |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
778 * Return TRUE if "fname" is a readable file. |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
779 */ |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
780 int |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
781 file_is_readable(char_u *fname) |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
782 { |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
783 int fd; |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
784 |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
785 #ifndef O_NONBLOCK |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
786 # define O_NONBLOCK 0 |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
787 #endif |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
788 if (*fname && !mch_isdir(fname) |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
789 && (fd = mch_open((char *)fname, O_RDONLY | O_NONBLOCK, 0)) >= 0) |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
790 { |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
791 close(fd); |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
792 return TRUE; |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
793 } |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
794 return FALSE; |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
795 } |
f8b07c537036
patch 9.0.0028: MS-Windows: tests fail if there is a "runtime" directory
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
796 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 #if defined(FEAT_EVAL) || defined(PROTO) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 * "chdir(dir)" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 f_chdir(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 char_u *cwd; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 cdscope_T scope = CDSCOPE_GLOBAL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 if (argvars[0].v_type != VAR_STRING) |
24250
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24246
diff
changeset
|
812 { |
19299
8b710057093c
patch 8.2.0208: fnamemodify() does not apply ":~" when followed by ":."
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
813 // Returning an empty string means it failed. |
20711
d91b8d1e5198
patch 8.2.0909: cannot go back to the previous local directory
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
814 // No error message, for historic reasons. |
24250
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24246
diff
changeset
|
815 if (in_vim9script()) |
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24246
diff
changeset
|
816 (void) check_for_string_arg(argvars, 0); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 return; |
24250
01b274c3f69b
patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24246
diff
changeset
|
818 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 // Return the current directory |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 cwd = alloc(MAXPATHL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 if (cwd != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 if (mch_dirname(cwd, MAXPATHL) != FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 #ifdef BACKSLASH_IN_FILENAME |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 slash_adjust(cwd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 rettv->vval.v_string = vim_strsave(cwd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 vim_free(cwd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 if (curwin->w_localdir != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 scope = CDSCOPE_WINDOW; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 else if (curtab->tp_localdir != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 scope = CDSCOPE_TABPAGE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 if (!changedir_func(argvars[0].vval.v_string, TRUE, scope)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 // Directory change failed |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 VIM_CLEAR(rettv->vval.v_string); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 * "delete()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 f_delete(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 char_u nbuf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 char_u *name; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 char_u *flags; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 rettv->vval.v_number = -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 if (check_restricted() || check_secure()) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
858 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
859 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
860 || check_for_opt_string_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
861 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
862 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 name = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 if (name == NULL || *name == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26173
diff
changeset
|
866 emsg(_(e_invalid_argument)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 if (argvars[1].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 flags = tv_get_string_buf(&argvars[1], nbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 flags = (char_u *)""; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 if (*flags == NUL) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
876 // delete a file |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 rettv->vval.v_number = mch_remove(name) == 0 ? 0 : -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 else if (STRCMP(flags, "d") == 0) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
879 // delete an empty directory |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 rettv->vval.v_number = mch_rmdir(name) == 0 ? 0 : -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 else if (STRCMP(flags, "rf") == 0) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
882 // delete a directory recursively |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 rettv->vval.v_number = delete_recursive(name); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 else |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24822
diff
changeset
|
885 semsg(_(e_invalid_expression_str), flags); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 * "executable()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 f_executable(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 { |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
894 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
895 return; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
897 // Check in $PATH and also check directly if there is a directory name. |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
898 rettv->vval.v_number = mch_can_exe(tv_get_string(&argvars[0]), NULL, TRUE); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 * "exepath()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 f_exepath(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 char_u *p = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
909 if (in_vim9script() && check_for_nonempty_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
910 return; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 (void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 rettv->vval.v_string = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 * "filereadable()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 f_filereadable(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 { |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
922 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
923 return; |
28255
48b9ffd40f38
patch 8.2.4653: "import autoload" does not check the file name
Bram Moolenaar <Bram@vim.org>
parents:
28021
diff
changeset
|
924 rettv->vval.v_number = file_is_readable(tv_get_string(&argvars[0])); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 * Return 0 for not writable, 1 for writable file, 2 for a dir which we have |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 * rights to write into. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 f_filewritable(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 { |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
934 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
935 return; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 rettv->vval.v_number = filewritable(tv_get_string(&argvars[0])); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
17986
diff
changeset
|
939 static void |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 findfilendir( |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 typval_T *argvars UNUSED, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 typval_T *rettv, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 int find_what UNUSED) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 char_u *fresult = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 char_u *path = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 char_u *p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 char_u pathbuf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 int count = 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 int first = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 int error = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 rettv->v_type = VAR_STRING; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
956 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
957 && (check_for_nonempty_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
958 || check_for_opt_string_arg(argvars, 1) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
959 || (argvars[1].v_type != VAR_UNKNOWN |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
960 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
961 return; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 fname = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 if (argvars[1].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 p = tv_get_string_buf_chk(&argvars[1], pathbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 if (p == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 error = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 if (*p != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 path = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 if (argvars[2].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 count = (int)tv_get_number_chk(&argvars[2], &error); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 if (count < 0 && rettv_list_alloc(rettv) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 error = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 if (*fname != NUL && !error) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 do |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 if (rettv->v_type == VAR_STRING || rettv->v_type == VAR_LIST) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 vim_free(fresult); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 fresult = find_file_in_path_option(first ? fname : NULL, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 first ? (int)STRLEN(fname) : 0, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 0, first, path, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 find_what, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 curbuf->b_ffname, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 find_what == FINDFILE_DIR |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 ? (char_u *)"" : curbuf->b_p_sua); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 first = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 if (fresult != NULL && rettv->v_type == VAR_LIST) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 list_append_string(rettv->vval.v_list, fresult, -1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 } while ((rettv->v_type == VAR_LIST || --count > 0) && fresult != NULL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 if (rettv->v_type == VAR_STRING) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 rettv->vval.v_string = fresult; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 * "finddir({fname}[, {path}[, {count}]])" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 f_finddir(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 findfilendir(argvars, rettv, FINDFILE_DIR); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 * "findfile({fname}[, {path}[, {count}]])" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 f_findfile(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 findfilendir(argvars, rettv, FINDFILE_FILE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 * "fnamemodify({fname}, {mods})" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 f_fnamemodify(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 char_u *mods; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 int usedlen = 0; |
23181
5f69af863502
patch 8.2.2136: Vim9: Using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1035 int len = 0; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 char_u *fbuf = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 char_u buf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1039 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1040 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1041 || check_for_string_arg(argvars, 1) == FAIL)) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1042 return; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1043 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 fname = tv_get_string_chk(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 mods = tv_get_string_buf_chk(&argvars[1], buf); |
23181
5f69af863502
patch 8.2.2136: Vim9: Using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1046 if (mods == NULL || fname == NULL) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 fname = NULL; |
23181
5f69af863502
patch 8.2.2136: Vim9: Using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1048 else |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 len = (int)STRLEN(fname); |
23181
5f69af863502
patch 8.2.2136: Vim9: Using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1051 if (mods != NULL && *mods != NUL) |
5f69af863502
patch 8.2.2136: Vim9: Using uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
23175
diff
changeset
|
1052 (void)modify_fname(mods, FALSE, &usedlen, &fname, &fbuf, &len); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 if (fname == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 rettv->vval.v_string = vim_strnsave(fname, len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 vim_free(fbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 * "getcwd()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 * Return the current working directory of a window in a tab page. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 * First optional argument 'winnr' is the window number or -1 and the second |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 * optional argument 'tabnr' is the tab page number. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 * If no arguments are supplied, then return the directory of the current |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 * window. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 * If only 'winnr' is specified and is not -1 or 0 then return the directory of |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 * the specified window. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 * If 'winnr' is 0 then return the directory of the current window. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 * If both 'winnr and 'tabnr' are specified and 'winnr' is -1 then return the |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 * directory of the specified tab page. Otherwise return the directory of the |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 * specified window in the specified tab page. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 * If the window or the tab page doesn't exist then return NULL. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 f_getcwd(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 win_T *wp = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 tabpage_T *tp = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 char_u *cwd; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 int global = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1091 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1092 && (check_for_opt_number_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1093 || (argvars[0].v_type != VAR_UNKNOWN |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1094 && check_for_opt_number_arg(argvars, 1) == FAIL))) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1095 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1096 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 if (argvars[0].v_type == VAR_NUMBER |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 && argvars[0].vval.v_number == -1 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 && argvars[1].v_type == VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 global = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 wp = find_tabwin(&argvars[0], &argvars[1], &tp); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 |
26173
460790b520dd
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1104 if (wp != NULL && wp->w_localdir != NULL |
460790b520dd
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1105 && argvars[0].v_type != VAR_UNKNOWN) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 rettv->vval.v_string = vim_strsave(wp->w_localdir); |
26173
460790b520dd
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1107 else if (tp != NULL && tp->tp_localdir != NULL |
460790b520dd
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1108 && argvars[0].v_type != VAR_UNKNOWN) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 rettv->vval.v_string = vim_strsave(tp->tp_localdir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 else if (wp != NULL || tp != NULL || global) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 { |
26173
460790b520dd
patch 8.2.3618: getcwd() is unclear about how 'autochdir' is used
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
1112 if (globaldir != NULL && argvars[0].v_type != VAR_UNKNOWN) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 rettv->vval.v_string = vim_strsave(globaldir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 cwd = alloc(MAXPATHL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 if (cwd != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 if (mch_dirname(cwd, MAXPATHL) != FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 rettv->vval.v_string = vim_strsave(cwd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 vim_free(cwd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 #ifdef BACKSLASH_IN_FILENAME |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 if (rettv->vval.v_string != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 slash_adjust(rettv->vval.v_string); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 /* |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1132 * Convert "st" to file permission string. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1133 */ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1134 char_u * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1135 getfpermst(stat_T *st, char_u *perm) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1136 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1137 char_u flags[] = "rwx"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1138 int i; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1139 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1140 for (i = 0; i < 9; i++) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1141 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1142 if (st->st_mode & (1 << (8 - i))) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1143 perm[i] = flags[i % 3]; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1144 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1145 perm[i] = '-'; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1146 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1147 return perm; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1148 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1149 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1150 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 * "getfperm({fname})" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 f_getfperm(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 stat_T st; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 char_u *perm = NULL; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1159 char_u permbuf[] = "---------"; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
1161 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1162 return; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1163 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 fname = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 if (mch_stat((char *)fname, &st) >= 0) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1168 perm = vim_strsave(getfpermst(&st, permbuf)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 rettv->vval.v_string = perm; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 * "getfsize({fname})" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 f_getfsize(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 stat_T st; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
1181 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1182 return; |
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1183 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 fname = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 if (mch_stat((char *)fname, &st) >= 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 if (mch_isdir(fname)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 rettv->vval.v_number = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 rettv->vval.v_number = (varnumber_T)st.st_size; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1193 // non-perfect check for overflow |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 if ((off_T)rettv->vval.v_number != (off_T)st.st_size) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 rettv->vval.v_number = -2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 rettv->vval.v_number = -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 * "getftime({fname})" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 f_getftime(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 stat_T st; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
1211 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1212 return; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1213 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 fname = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 if (mch_stat((char *)fname, &st) >= 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 rettv->vval.v_number = (varnumber_T)st.st_mtime; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 rettv->vval.v_number = -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1219 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 /* |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1222 * Convert "st" to file type string. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1223 */ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1224 char_u * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1225 getftypest(stat_T *st) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1226 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1227 char *t; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1228 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1229 if (S_ISREG(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1230 t = "file"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1231 else if (S_ISDIR(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1232 t = "dir"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1233 else if (S_ISLNK(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1234 t = "link"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1235 else if (S_ISBLK(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1236 t = "bdev"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1237 else if (S_ISCHR(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1238 t = "cdev"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1239 else if (S_ISFIFO(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1240 t = "fifo"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1241 else if (S_ISSOCK(st->st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1242 t = "socket"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1243 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1244 t = "other"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1245 return (char_u*)t; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1246 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1247 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1248 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 * "getftype({fname})" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 f_getftype(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1253 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1254 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 stat_T st; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 char_u *type = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
1258 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
23142
5f08d4a42898
patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1259 return; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1260 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 fname = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 if (mch_lstat((char *)fname, &st) >= 0) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1265 type = vim_strsave(getftypest(&st)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 rettv->vval.v_string = type; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 * "glob()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 f_glob(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 int options = WILD_SILENT|WILD_USE_NL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 expand_T xpc; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 int error = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1279 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1280 && (check_for_string_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1281 || check_for_opt_bool_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1282 || (argvars[1].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1283 && (check_for_opt_bool_arg(argvars, 2) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1284 || (argvars[2].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1285 && check_for_opt_bool_arg(argvars, 3) == FAIL))))) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1286 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1287 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1288 // When the optional second argument is non-zero, don't remove matches |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1289 // for 'wildignore' and don't put matches for 'suffixes' at the end. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 if (argvars[1].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 { |
22049
2b04c5bf4dc3
patch 8.2.1574: Vim9: glob() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
21873
diff
changeset
|
1293 if (tv_get_bool_chk(&argvars[1], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 options |= WILD_KEEP_ALL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 if (argvars[2].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 { |
22049
2b04c5bf4dc3
patch 8.2.1574: Vim9: glob() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
21873
diff
changeset
|
1297 if (tv_get_bool_chk(&argvars[2], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 rettv_list_set(rettv, NULL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 if (argvars[3].v_type != VAR_UNKNOWN |
22049
2b04c5bf4dc3
patch 8.2.1574: Vim9: glob() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
21873
diff
changeset
|
1300 && tv_get_bool_chk(&argvars[3], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 options |= WILD_ALLLINKS; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1304 if (!error) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 ExpandInit(&xpc); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 xpc.xp_context = EXPAND_FILES; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 if (p_wic) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 options += WILD_ICASE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 if (rettv->v_type == VAR_STRING) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 rettv->vval.v_string = ExpandOne(&xpc, tv_get_string(&argvars[0]), |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 NULL, options, WILD_ALL); |
29239
da56650de132
patch 8.2.5138: various small issues
Bram Moolenaar <Bram@vim.org>
parents:
29113
diff
changeset
|
1313 else if (rettv_list_alloc(rettv) == OK) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 int i; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 ExpandOne(&xpc, tv_get_string(&argvars[0]), |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 NULL, options, WILD_ALL_KEEP); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 for (i = 0; i < xpc.xp_numfiles; i++) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 ExpandCleanup(&xpc); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 * "glob2regpat()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 f_glob2regpat(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 { |
24822
5f8dd7b3ae41
patch 8.2.2949: tests failing because no error for float to string conversion
Bram Moolenaar <Bram@vim.org>
parents:
24250
diff
changeset
|
1335 char_u buf[NUMBUFLEN]; |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1336 char_u *pat; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1337 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1338 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1339 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1340 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1341 pat = tv_get_string_buf_chk_strict(&argvars[0], buf, in_vim9script()); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 rettv->vval.v_string = (pat == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 ? NULL : file_pat_to_reg_pat(pat, NULL, NULL, FALSE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 * "globpath()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 f_globpath(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 int flags = WILD_IGNORE_COMPLETESLASH; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 char_u buf1[NUMBUFLEN]; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1355 char_u *file; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 int error = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 garray_T ga; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 int i; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1360 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1361 && (check_for_string_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1362 || check_for_string_arg(argvars, 1) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1363 || check_for_opt_bool_arg(argvars, 2) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1364 || (argvars[2].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1365 && (check_for_opt_bool_arg(argvars, 3) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1366 || (argvars[3].v_type != VAR_UNKNOWN |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1367 && check_for_opt_bool_arg(argvars, 4) == FAIL))))) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1368 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1369 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1370 file = tv_get_string_buf_chk(&argvars[1], buf1); |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1371 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 // When the optional second argument is non-zero, don't remove matches |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 // for 'wildignore' and don't put matches for 'suffixes' at the end. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 if (argvars[2].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 { |
22051
342bcb9f7d34
patch 8.2.1575: Vim9: globpath() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
22049
diff
changeset
|
1377 if (tv_get_bool_chk(&argvars[2], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 flags |= WILD_KEEP_ALL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 if (argvars[3].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 { |
22051
342bcb9f7d34
patch 8.2.1575: Vim9: globpath() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
22049
diff
changeset
|
1381 if (tv_get_bool_chk(&argvars[3], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 rettv_list_set(rettv, NULL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 if (argvars[4].v_type != VAR_UNKNOWN |
22051
342bcb9f7d34
patch 8.2.1575: Vim9: globpath() doesnot take "true" as argument
Bram Moolenaar <Bram@vim.org>
parents:
22049
diff
changeset
|
1384 && tv_get_bool_chk(&argvars[4], &error)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 flags |= WILD_ALLLINKS; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 if (file != NULL && !error) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 { |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
1390 ga_init2(&ga, sizeof(char_u *), 10); |
31798
5948cc887603
patch 9.0.1231: completion of :runtime does not handle {where} argument
Bram Moolenaar <Bram@vim.org>
parents:
31667
diff
changeset
|
1391 globpath(tv_get_string(&argvars[0]), file, &ga, flags, FALSE); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 if (rettv->v_type == VAR_STRING) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 rettv->vval.v_string = ga_concat_strings(&ga, "\n"); |
29239
da56650de132
patch 8.2.5138: various small issues
Bram Moolenaar <Bram@vim.org>
parents:
29113
diff
changeset
|
1394 else if (rettv_list_alloc(rettv) == OK) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 for (i = 0; i < ga.ga_len; ++i) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 list_append_string(rettv->vval.v_list, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 ((char_u **)(ga.ga_data))[i], -1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 ga_clear_strings(&ga); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 * "isdirectory()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 f_isdirectory(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1410 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1411 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1412 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 rettv->vval.v_number = mch_isdir(tv_get_string(&argvars[0])); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 /* |
28629
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1417 * "isabsolutepath()" function |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1418 */ |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1419 void |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1420 f_isabsolutepath(typval_T *argvars, typval_T *rettv) |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1421 { |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1422 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1423 return; |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1424 |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1425 rettv->vval.v_number = mch_isFullName(tv_get_string_strict(&argvars[0])); |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1426 } |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1427 |
5ef46b938c6e
patch 8.2.4838: checking for absolute path is not trivial
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
1428 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 * Create the directory in which "dir" is located, and higher levels when |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 * needed. |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1431 * Set "created" to the full name of the first created directory. It will be |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1432 * NULL until that happens. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 * Return OK or FAIL. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 static int |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1436 mkdir_recurse(char_u *dir, int prot, char_u **created) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 char_u *p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 char_u *updir; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 int r = FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1442 // Get end of directory name in "dir". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1443 // We're done when it's "/" or "c:/". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 p = gettail_sep(dir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 if (p <= get_past_head(dir)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 return OK; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1448 // If the directory exists we're done. Otherwise: create it. |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
1449 updir = vim_strnsave(dir, p - dir); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 if (updir == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 return FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 if (mch_isdir(updir)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 r = OK; |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1454 else if (mkdir_recurse(updir, prot, created) == OK) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1455 { |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 r = vim_mkdir_emsg(updir, prot); |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1457 if (r == OK && created != NULL && *created == NULL) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1458 *created = FullName_save(updir, FALSE); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1459 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 vim_free(updir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 return r; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 * "mkdir()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 f_mkdir(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 char_u *dir; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 char_u buf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 int prot = 0755; |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1473 int defer = FALSE; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1474 int defer_recurse = FALSE; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1475 char_u *created = NULL; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 rettv->vval.v_number = FAIL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 if (check_restricted() || check_secure()) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1481 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1482 && (check_for_nonempty_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1483 || check_for_opt_string_arg(argvars, 1) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1484 || (argvars[1].v_type != VAR_UNKNOWN |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1485 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1486 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
1487 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 dir = tv_get_string_buf(&argvars[0], buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 if (*dir == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 if (*gettail(dir) == NUL) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1493 // remove trailing slashes |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 *gettail_sep(dir) = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1495 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 if (argvars[1].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 { |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1498 char_u *arg2; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1499 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 if (argvars[2].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1501 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1502 prot = (int)tv_get_number_chk(&argvars[2], NULL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1503 if (prot == -1) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 } |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1506 arg2 = tv_get_string(&argvars[1]); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1507 defer = vim_strchr(arg2, 'D') != NULL; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1508 defer_recurse = vim_strchr(arg2, 'R') != NULL; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1509 if ((defer || defer_recurse) && !can_add_defer()) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1510 return; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1511 |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1512 if (vim_strchr(arg2, 'p') != NULL) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 if (mch_isdir(dir)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1516 // With the "p" flag it's OK if the dir already exists. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1517 rettv->vval.v_number = OK; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 } |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1520 mkdir_recurse(dir, prot, defer || defer_recurse ? &created : NULL); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 rettv->vval.v_number = vim_mkdir_emsg(dir, prot); |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1524 |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1525 // Handle "D" and "R": deferred deletion of the created directory. |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1526 if (rettv->vval.v_number == OK |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1527 && created == NULL && (defer || defer_recurse)) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1528 created = FullName_save(dir, FALSE); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1529 if (created != NULL) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1530 { |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1531 typval_T tv[2]; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1532 |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1533 tv[0].v_type = VAR_STRING; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1534 tv[0].v_lock = 0; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1535 tv[0].vval.v_string = created; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1536 tv[1].v_type = VAR_STRING; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1537 tv[1].v_lock = 0; |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1538 tv[1].vval.v_string = vim_strsave( |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1539 (char_u *)(defer_recurse ? "rf" : "d")); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1540 if (tv[0].vval.v_string == NULL || tv[1].vval.v_string == NULL |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1541 || add_defer((char_u *)"delete", 2, tv) == FAIL) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1542 { |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1543 vim_free(tv[0].vval.v_string); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1544 vim_free(tv[1].vval.v_string); |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1545 } |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
1546 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1547 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 /* |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1550 * "pathshorten()" function |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1551 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1552 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1553 f_pathshorten(typval_T *argvars, typval_T *rettv) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1554 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1555 char_u *p; |
22385
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1556 int trim_len = 1; |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1557 |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1558 if (in_vim9script() |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1559 && (check_for_string_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
1560 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1561 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1562 |
22385
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1563 if (argvars[1].v_type != VAR_UNKNOWN) |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1564 { |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1565 trim_len = (int)tv_get_number(&argvars[1]); |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1566 if (trim_len < 1) |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1567 trim_len = 1; |
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1568 } |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1569 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1570 rettv->v_type = VAR_STRING; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1571 p = tv_get_string_chk(&argvars[0]); |
22385
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1572 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1573 if (p == NULL) |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1574 rettv->vval.v_string = NULL; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1575 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1576 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1577 p = vim_strsave(p); |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1578 rettv->vval.v_string = p; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1579 if (p != NULL) |
22385
770fe121ca64
patch 8.2.1741: pathshorten() only supports using one character
Bram Moolenaar <Bram@vim.org>
parents:
22051
diff
changeset
|
1580 shorten_dir_len(p, trim_len); |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1581 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1582 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1583 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17978
diff
changeset
|
1584 /* |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1585 * Common code for readdir_checkitem() and readdirex_checkitem(). |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1586 * Either "name" or "dict" is NULL. |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1587 */ |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1588 static int |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1589 checkitem_common(void *context, char_u *name, dict_T *dict) |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1590 { |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1591 typval_T *expr = (typval_T *)context; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1592 typval_T save_val; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1593 typval_T rettv; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1594 typval_T argv[2]; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1595 int retval = 0; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1596 int error = FALSE; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1597 |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1598 prepare_vimvar(VV_VAL, &save_val); |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1599 if (name != NULL) |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1600 { |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1601 set_vim_var_string(VV_VAL, name, -1); |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1602 argv[0].v_type = VAR_STRING; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1603 argv[0].vval.v_string = name; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1604 } |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1605 else |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1606 { |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1607 set_vim_var_dict(VV_VAL, dict); |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1608 argv[0].v_type = VAR_DICT; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1609 argv[0].vval.v_dict = dict; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1610 } |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1611 |
30566
b3de17181c19
patch 9.0.0618: calling function for reduce() has too much overhead
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
1612 if (eval_expr_typval(expr, argv, 1, NULL, &rettv) == FAIL) |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1613 goto theend; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1614 |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1615 // We want to use -1, but also true/false should be allowed. |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1616 if (rettv.v_type == VAR_SPECIAL || rettv.v_type == VAR_BOOL) |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1617 { |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1618 rettv.v_type = VAR_NUMBER; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1619 rettv.vval.v_number = rettv.vval.v_number == VVAL_TRUE; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1620 } |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1621 retval = tv_get_number_chk(&rettv, &error); |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1622 if (error) |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1623 retval = -1; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1624 clear_tv(&rettv); |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1625 |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1626 theend: |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1627 if (name != NULL) |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1628 set_vim_var_string(VV_VAL, NULL, 0); |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1629 else |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1630 set_vim_var_dict(VV_VAL, NULL); |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1631 restore_vimvar(VV_VAL, &save_val); |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1632 return retval; |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1633 } |
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1634 |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1635 /* |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1636 * Evaluate "expr" (= "context") for readdir(). |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1637 */ |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1638 static int |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1639 readdir_checkitem(void *context, void *item) |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1640 { |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1641 char_u *name = (char_u *)item; |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1642 |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1643 return checkitem_common(context, name, NULL); |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1644 } |
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1645 |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1646 /* |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1647 * Process the keys in the Dict argument to the readdir() and readdirex() |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1648 * functions. Assumes the Dict argument is the 3rd argument. |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1649 */ |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1650 static int |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1651 readdirex_dict_arg(typval_T *argvars, int *cmp) |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1652 { |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1653 char_u *compare; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1654 |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1655 if (check_for_nonnull_dict_arg(argvars, 2) == FAIL) |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1656 return FAIL; |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1657 |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1658 if (dict_has_key(argvars[2].vval.v_dict, "sort")) |
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1659 compare = dict_get_string(argvars[2].vval.v_dict, "sort", FALSE); |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1660 else |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1661 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1662 semsg(_(e_dictionary_key_str_required), "sort"); |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1663 return FAIL; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1664 } |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1665 |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1666 if (STRCMP(compare, (char_u *) "none") == 0) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1667 *cmp = READDIR_SORT_NONE; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1668 else if (STRCMP(compare, (char_u *) "case") == 0) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1669 *cmp = READDIR_SORT_BYTE; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1670 else if (STRCMP(compare, (char_u *) "icase") == 0) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1671 *cmp = READDIR_SORT_IC; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1672 else if (STRCMP(compare, (char_u *) "collate") == 0) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1673 *cmp = READDIR_SORT_COLLATE; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1674 return OK; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1675 } |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1676 |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
19299
diff
changeset
|
1677 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 * "readdir()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 f_readdir(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 typval_T *expr; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 int ret; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 char_u *path; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 char_u *p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 garray_T ga; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 int i; |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28635
diff
changeset
|
1689 int sort = READDIR_SORT_BYTE; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 if (rettv_list_alloc(rettv) == FAIL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 return; |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1693 |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1694 if (in_vim9script() |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1695 && (check_for_string_arg(argvars, 0) == FAIL |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1696 || (argvars[1].v_type != VAR_UNKNOWN |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1697 && check_for_opt_dict_arg(argvars, 2) == FAIL))) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1698 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1699 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 path = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 expr = &argvars[1]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1703 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1704 readdirex_dict_arg(argvars, &sort) == FAIL) |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1705 return; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1706 |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1707 ret = readdir_core(&ga, path, FALSE, (void *)expr, |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1708 (expr->v_type == VAR_UNKNOWN) ? NULL : readdir_checkitem, sort); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1709 if (ret == OK) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1711 for (i = 0; i < ga.ga_len; i++) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 p = ((char_u **)ga.ga_data)[i]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 list_append_string(rettv->vval.v_list, p, -1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 ga_clear_strings(&ga); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 /* |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1721 * Evaluate "expr" (= "context") for readdirex(). |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1722 */ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1723 static int |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1724 readdirex_checkitem(void *context, void *item) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1725 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1726 dict_T *dict = (dict_T*)item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1727 |
21873
62e61424482f
patch 8.2.1486: Vim9: readdir() expression doesn't accept bool
Bram Moolenaar <Bram@vim.org>
parents:
21871
diff
changeset
|
1728 return checkitem_common(context, NULL, dict); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1729 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1730 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1731 /* |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1732 * "readdirex()" function |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1733 */ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1734 void |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1735 f_readdirex(typval_T *argvars, typval_T *rettv) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1736 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1737 typval_T *expr; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1738 int ret; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1739 char_u *path; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1740 garray_T ga; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1741 int i; |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28635
diff
changeset
|
1742 int sort = READDIR_SORT_BYTE; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1743 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1744 if (rettv_list_alloc(rettv) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1745 return; |
25356
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1746 |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1747 if (in_vim9script() |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1748 && (check_for_string_arg(argvars, 0) == FAIL |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1749 || (argvars[1].v_type != VAR_UNKNOWN |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1750 && check_for_opt_dict_arg(argvars, 2) == FAIL))) |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1751 return; |
1cde96e768e4
patch 8.2.3215: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
1752 |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1753 path = tv_get_string(&argvars[0]); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1754 expr = &argvars[1]; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1755 |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1756 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN && |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29898
diff
changeset
|
1757 readdirex_dict_arg(argvars, &sort) == FAIL) |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1758 return; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1759 |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1760 ret = readdir_core(&ga, path, TRUE, (void *)expr, |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1761 (expr->v_type == VAR_UNKNOWN) ? NULL : readdirex_checkitem, sort); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1762 if (ret == OK) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1763 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1764 for (i = 0; i < ga.ga_len; i++) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1765 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1766 dict_T *dict = ((dict_T**)ga.ga_data)[i]; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1767 list_append_dict(rettv->vval.v_list, dict); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1768 dict_unref(dict); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1769 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1770 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1771 ga_clear(&ga); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1772 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1773 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1774 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 * "readfile()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 */ |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
1777 static void |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
1778 read_file_or_blob(typval_T *argvars, typval_T *rettv, int always_blob) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 int binary = FALSE; |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
1781 int blob = always_blob; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 int failed = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 FILE *fd; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1785 char_u buf[(IOSIZE/256)*256]; // rounded to avoid odd + 1 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 int io_size = sizeof(buf); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1787 int readlen; // size of last fread() |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1788 char_u *prev = NULL; // previously read bytes, if any |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1789 long prevlen = 0; // length of data in prev |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1790 long prevsize = 0; // size of prev buffer |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 long maxline = MAXLNUM; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 long cnt = 0; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1793 char_u *p; // position in buf |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1794 char_u *start; // start of current line |
30922
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1795 off_T offset = 0; |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1796 off_T size = -1; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 if (argvars[1].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 { |
30922
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1800 if (always_blob) |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1801 { |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1802 offset = (off_T)tv_get_number(&argvars[1]); |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1803 if (argvars[2].v_type != VAR_UNKNOWN) |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1804 size = (off_T)tv_get_number(&argvars[2]); |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1805 } |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1806 else |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1807 { |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1808 if (STRCMP(tv_get_string(&argvars[1]), "b") == 0) |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1809 binary = TRUE; |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1810 if (STRCMP(tv_get_string(&argvars[1]), "B") == 0) |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1811 blob = TRUE; |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1812 |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1813 if (argvars[2].v_type != VAR_UNKNOWN) |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1814 maxline = (long)tv_get_number(&argvars[2]); |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1815 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 |
19930
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1818 if ((blob ? rettv_blob_alloc(rettv) : rettv_list_alloc(rettv)) == FAIL) |
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1819 return; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1821 // Always open the file in binary mode, library functions have a mind of |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1822 // their own about CR-LF conversion. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 fname = tv_get_string(&argvars[0]); |
19930
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1824 |
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1825 if (mch_isdir(fname)) |
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1826 { |
28255
48b9ffd40f38
patch 8.2.4653: "import autoload" does not check the file name
Bram Moolenaar <Bram@vim.org>
parents:
28021
diff
changeset
|
1827 semsg(_(e_str_is_directory), fname); |
19930
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1828 return; |
80e663e91e1b
patch 8.2.0521: crash when reading a blob fails
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1829 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 if (*fname == NUL || (fd = mch_fopen((char *)fname, READBIN)) == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 { |
30922
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1832 semsg(_(e_cant_open_file_str), |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1833 *fname == NUL ? (char_u *)_("<empty>") : fname); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1837 if (blob) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1838 { |
30922
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
1839 if (read_blob(fd, rettv, offset, size) == FAIL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
1840 semsg(_(e_cant_read_file_str), fname); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1841 fclose(fd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 while (cnt < maxline || maxline < 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 readlen = (int)fread(buf, 1, io_size, fd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1849 // This for loop processes what was read, but is also entered at end |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1850 // of file so that either: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1851 // - an incomplete line gets written |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1852 // - a "binary" file gets an empty line at the end if it ends in a |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1853 // newline. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 for (p = buf, start = buf; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 p < buf + readlen || (readlen <= 0 && (prevlen > 0 || binary)); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 ++p) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 { |
27082
360a6a1ca9dd
patch 8.2.4070: using uninitialized memory when reading empty file
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
1858 if (readlen <= 0 || *p == '\n') |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 listitem_T *li; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 char_u *s = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 long_u len = p - start; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1864 // Finished a line. Remove CRs before NL. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 if (readlen > 0 && !binary) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 while (len > 0 && start[len - 1] == '\r') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 --len; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1869 // removal may cross back to the "prev" string |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 if (len == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 while (prevlen > 0 && prev[prevlen - 1] == '\r') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 --prevlen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 if (prevlen == 0) |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
1875 s = vim_strnsave(start, len); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1878 // Change "prev" buffer to be the right size. This way |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1879 // the bytes are only copied once, and very long lines are |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1880 // allocated only once. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 if ((s = vim_realloc(prev, prevlen + len + 1)) != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 mch_memmove(s + prevlen, start, len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 s[prevlen + len] = NUL; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1885 prev = NULL; // the list will own the string |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 prevlen = prevsize = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 if (s == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 do_outofmem_msg((long_u) prevlen + len + 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 failed = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 if ((li = listitem_alloc()) == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 vim_free(s); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 failed = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 li->li_tv.v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 li->li_tv.v_lock = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 li->li_tv.vval.v_string = s; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 list_append(rettv->vval.v_list, li); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1907 start = p + 1; // step over newline |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 if ((++cnt >= maxline && maxline >= 0) || readlen <= 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 else if (*p == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 *p = '\n'; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1913 // Check for utf8 "bom"; U+FEFF is encoded as EF BB BF. Do this |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1914 // when finding the BF and check the previous two bytes. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 else if (*p == 0xbf && enc_utf8 && !binary) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1917 // Find the two bytes before the 0xbf. If p is at buf, or buf |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1918 // + 1, these may be in the "prev" string. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 char_u back1 = p >= buf + 1 ? p[-1] |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 : prevlen >= 1 ? prev[prevlen - 1] : NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 char_u back2 = p >= buf + 2 ? p[-2] |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 : p == buf + 1 && prevlen >= 1 ? prev[prevlen - 1] |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 : prevlen >= 2 ? prev[prevlen - 2] : NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 if (back2 == 0xef && back1 == 0xbb) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 char_u *dest = p - 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1929 // Usually a BOM is at the beginning of a file, and so at |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1930 // the beginning of a line; then we can just step over it. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (start == dest) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 start = p + 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1935 // have to shuffle buf to close gap |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 int adjust_prevlen = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 if (dest < buf) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 { |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
1940 // must be 1 or 2 |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
1941 adjust_prevlen = (int)(buf - dest); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 dest = buf; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 if (readlen > p - buf + 1) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 mch_memmove(dest, p + 1, readlen - (p - buf) - 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 readlen -= 3 - adjust_prevlen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 prevlen -= adjust_prevlen; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 p = dest - 1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1952 } // for |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 if (failed || (cnt >= maxline && maxline >= 0) || readlen <= 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 if (start < p) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1958 // There's part of a line in buf, store it in "prev". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 if (p - start + prevlen >= prevsize) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1961 // need bigger "prev" buffer |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 char_u *newprev; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1964 // A common use case is ordinary text files and "prev" gets a |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1965 // fragment of a line, so the first allocation is made |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1966 // small, to avoid repeatedly 'allocing' large and |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1967 // 'reallocing' small. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 if (prevsize == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 prevsize = (long)(p - start); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 long grow50pc = (prevsize * 3) / 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 long growmin = (long)((p - start) * 2 + prevlen); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 prevsize = grow50pc > growmin ? grow50pc : growmin; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 newprev = vim_realloc(prev, prevsize); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 if (newprev == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 do_outofmem_msg((long_u)prevsize); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 failed = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 prev = newprev; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1985 // Add the line part to end of "prev". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 mch_memmove(prev + prevlen, start, p - start); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 prevlen += (long)(p - start); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1989 } // while |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1990 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1991 // For a negative line count use only the lines at the end of the file, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
1992 // free the rest. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 if (!failed && maxline < 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 while (cnt > -maxline) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 listitem_remove(rettv->vval.v_list, rettv->vval.v_list->lv_first); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 --cnt; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 if (failed) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2002 // an empty list is returned on error |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 list_free(rettv->vval.v_list); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 rettv_list_alloc(rettv); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2007 vim_free(prev); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2008 fclose(fd); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 /* |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2012 * "readblob()" function |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2013 */ |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2014 void |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2015 f_readblob(typval_T *argvars, typval_T *rettv) |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2016 { |
30922
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
2017 if (in_vim9script() |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
2018 && (check_for_string_arg(argvars, 0) == FAIL |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
2019 || check_for_opt_number_arg(argvars, 1) == FAIL |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
2020 || (argvars[1].v_type != VAR_UNKNOWN |
ed6acfafa17e
patch 9.0.0795: readblob() always reads the whole file
Bram Moolenaar <Bram@vim.org>
parents:
30717
diff
changeset
|
2021 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2022 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2023 |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2024 read_file_or_blob(argvars, rettv, TRUE); |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2025 } |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2026 |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2027 /* |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2028 * "readfile()" function |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2029 */ |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2030 void |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2031 f_readfile(typval_T *argvars, typval_T *rettv) |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2032 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2033 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2034 && (check_for_nonempty_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2035 || check_for_opt_string_arg(argvars, 1) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2036 || (argvars[1].v_type != VAR_UNKNOWN |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2037 && check_for_opt_number_arg(argvars, 2) == FAIL))) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2038 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2039 |
23602
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2040 read_file_or_blob(argvars, rettv, FALSE); |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2041 } |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2042 |
7b3317e959e3
patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents:
23181
diff
changeset
|
2043 /* |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 * "resolve()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2045 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 f_resolve(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 char_u *p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 #ifdef HAVE_READLINK |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 char_u *buf = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2054 if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2055 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2056 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 p = tv_get_string(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 #ifdef FEAT_SHORTCUT |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2059 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2060 char_u *v = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2061 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2062 v = mch_resolve_path(p, TRUE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2063 if (v != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2064 rettv->vval.v_string = v; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2065 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2066 rettv->vval.v_string = vim_strsave(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2067 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2068 #else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2069 # ifdef HAVE_READLINK |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2070 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2071 char_u *cpy; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2072 int len; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2073 char_u *remain = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2074 char_u *q; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2075 int is_relative_to_current = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2076 int has_trailing_pathsep = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2077 int limit = 100; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2078 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2079 p = vim_strsave(p); |
18947
d6c7b2f9aa20
patch 8.2.0034: missing check for out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
2080 if (p == NULL) |
d6c7b2f9aa20
patch 8.2.0034: missing check for out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
2081 goto fail; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2082 if (p[0] == '.' && (vim_ispathsep(p[1]) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2083 || (p[1] == '.' && (vim_ispathsep(p[2]))))) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2084 is_relative_to_current = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2085 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 len = STRLEN(p); |
22512
aeeee593fe0f
patch 8.2.1804: resolve('/') returns an empty string
Bram Moolenaar <Bram@vim.org>
parents:
22389
diff
changeset
|
2087 if (len > 1 && after_pathsep(p, p + len)) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 has_trailing_pathsep = TRUE; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2090 p[len - 1] = NUL; // the trailing slash breaks readlink() |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2091 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2093 q = getnextcomp(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 if (*q != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2096 // Separate the first path component in "p", and keep the |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2097 // remainder (beginning with the path separator). |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 remain = vim_strsave(q - 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2099 q[-1] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2100 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2101 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2102 buf = alloc(MAXPATHL + 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2103 if (buf == NULL) |
18947
d6c7b2f9aa20
patch 8.2.0034: missing check for out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
2104 { |
d6c7b2f9aa20
patch 8.2.0034: missing check for out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
2105 vim_free(p); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2106 goto fail; |
18947
d6c7b2f9aa20
patch 8.2.0034: missing check for out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
2107 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2108 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 for (;;) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2110 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2111 for (;;) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2112 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2113 len = readlink((char *)p, (char *)buf, MAXPATHL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2114 if (len <= 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2115 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2116 buf[len] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 if (limit-- == 0) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2119 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2120 vim_free(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2121 vim_free(remain); |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26909
diff
changeset
|
2122 emsg(_(e_too_many_symbolic_links_cycle)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2123 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2124 goto fail; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2125 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2126 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2127 // Ensure that the result will have a trailing path separator |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2128 // if the argument has one. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2129 if (remain == NULL && has_trailing_pathsep) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2130 add_pathsep(buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2131 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2132 // Separate the first path component in the link value and |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2133 // concatenate the remainders. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 q = getnextcomp(vim_ispathsep(*buf) ? buf + 1 : buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2135 if (*q != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2136 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 if (remain == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 remain = vim_strsave(q - 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 cpy = concat_str(q - 1, remain); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2142 if (cpy != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 vim_free(remain); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 remain = cpy; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 q[-1] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2150 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2151 q = gettail(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 if (q > p && *q == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2154 // Ignore trailing path separator. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2155 q[-1] = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2156 q = gettail(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2158 if (q > p && !mch_isFullName(buf)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2160 // symlink is relative to directory of argument |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2161 cpy = alloc(STRLEN(p) + STRLEN(buf) + 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2162 if (cpy != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2163 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2164 STRCPY(cpy, p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2165 STRCPY(gettail(cpy), buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2166 vim_free(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2167 p = cpy; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2168 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2169 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2171 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2172 vim_free(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2173 p = vim_strsave(buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2174 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2175 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2176 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 if (remain == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2178 break; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2179 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2180 // Append the first path component of "remain" to "p". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2181 q = getnextcomp(remain + 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2182 len = q - remain - (*q != NUL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2183 cpy = vim_strnsave(p, STRLEN(p) + len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2184 if (cpy != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2185 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2186 STRNCAT(cpy, remain, len); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2187 vim_free(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2188 p = cpy; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2190 // Shorten "remain". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 if (*q != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 STRMOVE(remain, q - 1); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2193 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2194 VIM_CLEAR(remain); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2195 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2197 // If the result is a relative path name, make it explicitly relative to |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2198 // the current directory if and only if the argument had this form. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 if (!vim_ispathsep(*p)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2201 if (is_relative_to_current |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2202 && *p != NUL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2203 && !(p[0] == '.' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2204 && (p[1] == NUL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2205 || vim_ispathsep(p[1]) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2206 || (p[1] == '.' |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2207 && (p[2] == NUL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 || vim_ispathsep(p[2])))))) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2209 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2210 // Prepend "./". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2211 cpy = concat_str((char_u *)"./", p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2212 if (cpy != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2213 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2214 vim_free(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 p = cpy; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2216 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2218 else if (!is_relative_to_current) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2219 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2220 // Strip leading "./". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2221 q = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2222 while (q[0] == '.' && vim_ispathsep(q[1])) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2223 q += 2; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2224 if (q > p) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2225 STRMOVE(p, p + 2); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2226 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2227 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2228 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2229 // Ensure that the result will have no trailing path separator |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2230 // if the argument had none. But keep "/" or "//". |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2231 if (!has_trailing_pathsep) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2232 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2233 q = p + STRLEN(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2234 if (after_pathsep(p, q)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2235 *gettail_sep(p) = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2236 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2237 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2238 rettv->vval.v_string = p; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2239 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2240 # else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2241 rettv->vval.v_string = vim_strsave(p); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2242 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2243 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2244 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2245 simplify_filename(rettv->vval.v_string); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2246 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2247 #ifdef HAVE_READLINK |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2248 fail: |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 vim_free(buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2250 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2254 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2255 * "tempname()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2256 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2258 f_tempname(typval_T *argvars UNUSED, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2259 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2260 static int x = 'A'; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2261 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 rettv->vval.v_string = vim_tempname(x, FALSE); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2265 // Advance 'x' to use A-Z and 0-9, so that there are at least 34 different |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2266 // names. Skip 'I' and 'O', they are used for shell redirection. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2267 do |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2268 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2269 if (x == 'Z') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2270 x = '0'; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2271 else if (x == '9') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 x = 'A'; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 else |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27082
diff
changeset
|
2274 ++x; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2275 } while (x == 'I' || x == 'O'); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2277 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2278 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2279 * "writefile()" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2280 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 f_writefile(typval_T *argvars, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2283 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 int binary = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2285 int append = FALSE; |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2286 int defer = FALSE; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2287 #ifdef HAVE_FSYNC |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2288 int do_fsync = p_fs; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2289 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2290 char_u *fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2291 FILE *fd; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2292 int ret = 0; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2293 listitem_T *li; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2294 list_T *list = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2295 blob_T *blob = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2296 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2297 rettv->vval.v_number = -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2298 if (check_secure()) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2299 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2300 |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2301 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2302 && (check_for_list_or_blob_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2303 || check_for_string_arg(argvars, 1) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2304 || check_for_opt_string_arg(argvars, 2) == FAIL)) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2305 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2306 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 if (argvars[0].v_type == VAR_LIST) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 list = argvars[0].vval.v_list; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 if (list == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 return; |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
19938
diff
changeset
|
2312 CHECK_LIST_MATERIALIZE(list); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
2313 FOR_ALL_LIST_ITEMS(list, li) |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 if (tv_get_string_chk(&li->li_tv) == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2316 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 else if (argvars[0].v_type == VAR_BLOB) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 blob = argvars[0].vval.v_blob; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 if (blob == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26173
diff
changeset
|
2325 semsg(_(e_invalid_argument_str), |
19695
1697a25328fd
patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents:
19314
diff
changeset
|
2326 _("writefile() first argument must be a List or a Blob")); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2329 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2330 if (argvars[2].v_type != VAR_UNKNOWN) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2331 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 char_u *arg2 = tv_get_string_chk(&argvars[2]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2333 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 if (arg2 == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 if (vim_strchr(arg2, 'b') != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2337 binary = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 if (vim_strchr(arg2, 'a') != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2339 append = TRUE; |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2340 if (vim_strchr(arg2, 'D') != NULL) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2341 defer = TRUE; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2342 #ifdef HAVE_FSYNC |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2343 if (vim_strchr(arg2, 's') != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2344 do_fsync = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2345 else if (vim_strchr(arg2, 'S') != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 do_fsync = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2348 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2349 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2350 fname = tv_get_string_chk(&argvars[1]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2351 if (fname == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2352 return; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2353 |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
2354 if (defer && !can_add_defer()) |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2355 return; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2356 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2357 // Always open the file in binary mode, library functions have a mind of |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2358 // their own about CR-LF conversion. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 if (*fname == NUL || (fd = mch_fopen((char *)fname, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 append ? APPENDBIN : WRITEBIN)) == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2361 { |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2362 semsg(_(e_cant_create_file_str), |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2363 *fname == NUL ? (char_u *)_("<empty>") : fname); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2364 ret = -1; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2365 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2366 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2367 { |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2368 if (defer) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2369 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2370 typval_T tv; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2371 |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2372 tv.v_type = VAR_STRING; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2373 tv.v_lock = 0; |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
2374 tv.vval.v_string = FullName_save(fname, FALSE); |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2375 if (tv.vval.v_string == NULL |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2376 || add_defer((char_u *)"delete", 1, &tv) == FAIL) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2377 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2378 ret = -1; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2379 fclose(fd); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2380 (void)mch_remove(fname); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2381 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2382 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2383 |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2384 if (ret == 0) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2385 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2386 if (blob) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2387 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2388 if (write_blob(fd, blob) == FAIL) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2389 ret = -1; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2390 } |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2391 else |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2392 { |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2393 if (write_list(fd, list, binary) == FAIL) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2394 ret = -1; |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2395 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 #ifdef HAVE_FSYNC |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2397 if (ret == 0 && do_fsync) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2398 // Ignore the error, the user wouldn't know what to do about |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2399 // it. May happen for a device. |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2400 vim_ignored = vim_fsync(fileno(fd)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2401 #endif |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2402 fclose(fd); |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30049
diff
changeset
|
2403 } |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2404 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2405 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 rettv->vval.v_number = ret; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 #endif // FEAT_EVAL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 #if defined(FEAT_BROWSE) || defined(PROTO) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2412 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2413 * Generic browse function. Calls gui_mch_browse() when possible. |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2414 * Later this may pop-up a non-GUI file selector (external command?). |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2415 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2416 char_u * |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2417 do_browse( |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2418 int flags, // BROWSE_SAVE and BROWSE_DIR |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2419 char_u *title, // title for the window |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2420 char_u *dflt, // default file name (may include directory) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2421 char_u *ext, // extension added |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2422 char_u *initdir, // initial directory, NULL for current dir or |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2423 // when using path from "dflt" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2424 char_u *filter, // file name filter |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2425 buf_T *buf) // buffer to read/write for |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2426 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 char_u *fname; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2428 static char_u *last_dir = NULL; // last used directory |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2429 char_u *tofree = NULL; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22512
diff
changeset
|
2430 int save_cmod_flags = cmdmod.cmod_flags; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2432 // Must turn off browse to avoid that autocommands will get the |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2433 // flag too! |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22512
diff
changeset
|
2434 cmdmod.cmod_flags &= ~CMOD_BROWSE; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 if (title == NULL || *title == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2437 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 if (flags & BROWSE_DIR) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2439 title = (char_u *)_("Select Directory dialog"); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 else if (flags & BROWSE_SAVE) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2441 title = (char_u *)_("Save File dialog"); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2442 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2443 title = (char_u *)_("Open File dialog"); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2444 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2445 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2446 // When no directory specified, use default file name, default dir, buffer |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2447 // dir, last dir or current dir |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 if ((initdir == NULL || *initdir == NUL) && dflt != NULL && *dflt != NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2449 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2450 if (mch_isdir(dflt)) // default file name is a directory |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2451 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2452 initdir = dflt; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2453 dflt = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2454 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2455 else if (gettail(dflt) != dflt) // default file name includes a path |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2456 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2457 tofree = vim_strsave(dflt); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2458 if (tofree != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2459 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2460 initdir = tofree; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2461 *gettail(initdir) = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2462 dflt = gettail(dflt); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 if (initdir == NULL || *initdir == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2469 // When 'browsedir' is a directory, use it |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 if (STRCMP(p_bsdir, "last") != 0 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2471 && STRCMP(p_bsdir, "buffer") != 0 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2472 && STRCMP(p_bsdir, "current") != 0 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 && mch_isdir(p_bsdir)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 initdir = p_bsdir; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2475 // When saving or 'browsedir' is "buffer", use buffer fname |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2476 else if (((flags & BROWSE_SAVE) || *p_bsdir == 'b') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2477 && buf != NULL && buf->b_ffname != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2478 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2479 if (dflt == NULL || *dflt == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2480 dflt = gettail(curbuf->b_ffname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 tofree = vim_strsave(curbuf->b_ffname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2482 if (tofree != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2484 initdir = tofree; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2485 *gettail(initdir) = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2486 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2487 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2488 // When 'browsedir' is "last", use dir from last browse |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2489 else if (*p_bsdir == 'l') |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 initdir = last_dir; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2491 // When 'browsedir is "current", use current directory. This is the |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2492 // default already, leave initdir empty. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2493 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2494 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2495 # ifdef FEAT_GUI |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2496 if (gui.in_use) // when this changes, also adjust f_has()! |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2498 if (filter == NULL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 # ifdef FEAT_EVAL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 && (filter = get_var_value((char_u *)"b:browsefilter")) == NULL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 && (filter = get_var_value((char_u *)"g:browsefilter")) == NULL |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 ) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2504 filter = BROWSE_FILTER_DEFAULT; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2505 if (flags & BROWSE_DIR) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2506 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2507 # if defined(FEAT_GUI_GTK) || defined(MSWIN) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2508 // For systems that have a directory dialog. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2509 fname = gui_mch_browsedir(title, initdir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2510 # else |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2511 // Generic solution for selecting a directory: select a file and |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2512 // remove the file name. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2513 fname = gui_mch_browse(0, title, dflt, ext, initdir, (char_u *)""); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2514 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2515 # if !defined(FEAT_GUI_GTK) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2516 // Win32 adds a dummy file name, others return an arbitrary file |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2517 // name. GTK+ 2 returns only the directory, |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2518 if (fname != NULL && *fname != NUL && !mch_isdir(fname)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2519 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2520 // Remove the file name. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2521 char_u *tail = gettail_sep(fname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2522 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2523 if (tail == fname) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2524 *tail++ = '.'; // use current dir |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2525 *tail = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2526 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2527 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2528 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2529 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2530 fname = gui_mch_browse(flags & BROWSE_SAVE, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2531 title, dflt, ext, initdir, (char_u *)_(filter)); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2532 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2533 // We hang around in the dialog for a while, the user might do some |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2534 // things to our files. The Win32 dialog allows deleting or renaming |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2535 // a file, check timestamps. |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2536 need_check_timestamps = TRUE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2537 did_check_timestamps = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2538 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2539 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2540 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2541 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2542 // TODO: non-GUI file selector here |
26909
aa65d1808bd0
patch 8.2.3983: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2543 emsg(_(e_sorry_no_file_browser_in_console_mode)); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2544 fname = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2545 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2546 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2547 // keep the directory for next time |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2548 if (fname != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2549 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2550 vim_free(last_dir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2551 last_dir = vim_strsave(fname); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2552 if (last_dir != NULL && !(flags & BROWSE_DIR)) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2553 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2554 *gettail(last_dir) = NUL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2555 if (*last_dir == NUL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2556 { |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2557 // filename only returned, must be in current dir |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2558 vim_free(last_dir); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2559 last_dir = alloc(MAXPATHL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2560 if (last_dir != NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2561 mch_dirname(last_dir, MAXPATHL); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2562 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2563 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2564 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2565 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2566 vim_free(tofree); |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22512
diff
changeset
|
2567 cmdmod.cmod_flags = save_cmod_flags; |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2568 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2569 return fname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2570 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2571 #endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2572 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2573 #if defined(FEAT_EVAL) || defined(PROTO) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2574 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2575 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2576 * "browse(save, title, initdir, default)" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2577 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2578 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2579 f_browse(typval_T *argvars UNUSED, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2580 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2581 # ifdef FEAT_BROWSE |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2582 int save; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2583 char_u *title; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2584 char_u *initdir; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2585 char_u *defname; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2586 char_u buf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2587 char_u buf2[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2588 int error = FALSE; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2589 |
24210
083f07f99e20
patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents:
23873
diff
changeset
|
2590 if (in_vim9script() |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
2591 && (check_for_bool_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
2592 || check_for_string_arg(argvars, 1) == FAIL |
24246
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
2593 || check_for_string_arg(argvars, 2) == FAIL |
35603c7991d7
patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents:
24210
diff
changeset
|
2594 || check_for_string_arg(argvars, 3) == FAIL)) |
24210
083f07f99e20
patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents:
23873
diff
changeset
|
2595 return; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
2596 |
30717
aa0f7c66653c
patch 9.0.0693: browse() first argument cannot be a bool
Bram Moolenaar <Bram@vim.org>
parents:
30598
diff
changeset
|
2597 save = (int)tv_get_bool_chk(&argvars[0], &error); |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2598 title = tv_get_string_chk(&argvars[1]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2599 initdir = tv_get_string_buf_chk(&argvars[2], buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2600 defname = tv_get_string_buf_chk(&argvars[3], buf2); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2601 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2602 if (error || title == NULL || initdir == NULL || defname == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2603 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2604 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2605 rettv->vval.v_string = |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2606 do_browse(save ? BROWSE_SAVE : 0, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2607 title, defname, NULL, initdir, NULL, curbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2608 # else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2609 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2610 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2611 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2612 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2613 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2614 /* |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2615 * "browsedir(title, initdir)" function |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2616 */ |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2617 void |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2618 f_browsedir(typval_T *argvars UNUSED, typval_T *rettv) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2619 { |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2620 # ifdef FEAT_BROWSE |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2621 char_u *title; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2622 char_u *initdir; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2623 char_u buf[NUMBUFLEN]; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2624 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2625 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2626 && (check_for_string_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2627 || check_for_string_arg(argvars, 1) == FAIL)) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2628 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25356
diff
changeset
|
2629 |
17966
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2630 title = tv_get_string_chk(&argvars[0]); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2631 initdir = tv_get_string_buf_chk(&argvars[1], buf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2632 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2633 if (title == NULL || initdir == NULL) |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2634 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2635 else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2636 rettv->vval.v_string = do_browse(BROWSE_DIR, |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2637 title, NULL, NULL, initdir, NULL, curbuf); |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2638 # else |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2639 rettv->vval.v_string = NULL; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2640 # endif |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2641 rettv->v_type = VAR_STRING; |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2642 } |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2643 |
46f95606b9ec
patch 8.1.1979: code for handling file names is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2644 #endif // FEAT_EVAL |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2645 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2646 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2647 * Replace home directory by "~" in each space or comma separated file name in |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2648 * 'src'. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2649 * If anything fails (except when out of space) dst equals src. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2650 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2651 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2652 home_replace( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2653 buf_T *buf, // when not NULL, check for help files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2654 char_u *src, // input file name |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2655 char_u *dst, // where to put the result |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2656 int dstlen, // maximum length of the result |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2657 int one) // if TRUE, only replace one file name, include |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2658 // spaces and commas in the file name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2659 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2660 size_t dirlen = 0, envlen = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2661 size_t len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2662 char_u *homedir_env, *homedir_env_orig; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2663 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2664 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2665 if (src == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2666 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2667 *dst = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2668 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2669 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2670 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2671 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2672 * If the file is a help file, remove the path completely. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2673 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2674 if (buf != NULL && buf->b_help) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2675 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2676 vim_snprintf((char *)dst, dstlen, "%s", gettail(src)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2677 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2678 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2679 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2680 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2681 * We check both the value of the $HOME environment variable and the |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2682 * "real" home directory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2683 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2684 if (homedir != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2685 dirlen = STRLEN(homedir); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2686 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2687 #ifdef VMS |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2688 homedir_env_orig = homedir_env = mch_getenv((char_u *)"SYS$LOGIN"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2689 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2690 homedir_env_orig = homedir_env = mch_getenv((char_u *)"HOME"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2691 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2692 #ifdef MSWIN |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2693 if (homedir_env == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2694 homedir_env_orig = homedir_env = mch_getenv((char_u *)"USERPROFILE"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2695 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2696 // Empty is the same as not set. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2697 if (homedir_env != NULL && *homedir_env == NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2698 homedir_env = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2699 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2700 if (homedir_env != NULL && *homedir_env == '~') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2701 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2702 int usedlen = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2703 int flen; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2704 char_u *fbuf = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2705 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2706 flen = (int)STRLEN(homedir_env); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2707 (void)modify_fname((char_u *)":p", FALSE, &usedlen, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2708 &homedir_env, &fbuf, &flen); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2709 flen = (int)STRLEN(homedir_env); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2710 if (flen > 0 && vim_ispathsep(homedir_env[flen - 1])) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2711 // Remove the trailing / that is added to a directory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2712 homedir_env[flen - 1] = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2713 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2714 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2715 if (homedir_env != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2716 envlen = STRLEN(homedir_env); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2717 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2718 if (!one) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2719 src = skipwhite(src); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2720 while (*src && dstlen > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2721 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2722 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2723 * Here we are at the beginning of a file name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2724 * First, check to see if the beginning of the file name matches |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2725 * $HOME or the "real" home directory. Check that there is a '/' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2726 * after the match (so that if e.g. the file is "/home/pieter/bla", |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2727 * and the home directory is "/home/piet", the file does not end up |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2728 * as "~er/bla" (which would seem to indicate the file "bla" in user |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2729 * er's home directory)). |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2730 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2731 p = homedir; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2732 len = dirlen; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2733 for (;;) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2734 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2735 if ( len |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2736 && fnamencmp(src, p, len) == 0 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2737 && (vim_ispathsep(src[len]) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2738 || (!one && (src[len] == ',' || src[len] == ' ')) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2739 || src[len] == NUL)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2740 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2741 src += len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2742 if (--dstlen > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2743 *dst++ = '~'; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2744 |
20780
300fbeef8c82
patch 8.2.0942: expanding to local dir after homedir keeps "~/"
Bram Moolenaar <Bram@vim.org>
parents:
20711
diff
changeset
|
2745 // Do not add directory separator into dst, because dst is |
300fbeef8c82
patch 8.2.0942: expanding to local dir after homedir keeps "~/"
Bram Moolenaar <Bram@vim.org>
parents:
20711
diff
changeset
|
2746 // expected to just return the directory name without the |
300fbeef8c82
patch 8.2.0942: expanding to local dir after homedir keeps "~/"
Bram Moolenaar <Bram@vim.org>
parents:
20711
diff
changeset
|
2747 // directory separator '/'. |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2748 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2749 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2750 if (p == homedir_env) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2751 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2752 p = homedir_env; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2753 len = envlen; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2754 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2755 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2756 // if (!one) skip to separator: space or comma |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2757 while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2758 *dst++ = *src++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2759 // skip separator |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2760 while ((*src == ' ' || *src == ',') && --dstlen > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2761 *dst++ = *src++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2762 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2763 // if (dstlen == 0) out of space, what to do??? |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2764 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2765 *dst = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2766 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2767 if (homedir_env != homedir_env_orig) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2768 vim_free(homedir_env); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2769 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2770 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2771 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2772 * Like home_replace, store the replaced string in allocated memory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2773 * When something fails, NULL is returned. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2774 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2775 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2776 home_replace_save( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2777 buf_T *buf, // when not NULL, check for help files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2778 char_u *src) // input file name |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2779 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2780 char_u *dst; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2781 unsigned len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2782 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2783 len = 3; // space for "~/" and trailing NUL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2784 if (src != NULL) // just in case |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2785 len += (unsigned)STRLEN(src); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2786 dst = alloc(len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2787 if (dst != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2788 home_replace(buf, src, dst, len, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2789 return dst; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2790 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2791 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2792 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2793 * Compare two file names and return: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2794 * FPC_SAME if they both exist and are the same file. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2795 * FPC_SAMEX if they both don't exist and have the same file name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2796 * FPC_DIFF if they both exist and are different files. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2797 * FPC_NOTX if they both don't exist. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2798 * FPC_DIFFX if one of them doesn't exist. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2799 * For the first name environment variables are expanded if "expandenv" is |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2800 * TRUE. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2801 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2802 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2803 fullpathcmp( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2804 char_u *s1, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2805 char_u *s2, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2806 int checkname, // when both don't exist, check file names |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2807 int expandenv) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2808 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2809 #ifdef UNIX |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2810 char_u exp1[MAXPATHL]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2811 char_u full1[MAXPATHL]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2812 char_u full2[MAXPATHL]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2813 stat_T st1, st2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2814 int r1, r2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2815 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2816 if (expandenv) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2817 expand_env(s1, exp1, MAXPATHL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2818 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2819 vim_strncpy(exp1, s1, MAXPATHL - 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2820 r1 = mch_stat((char *)exp1, &st1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2821 r2 = mch_stat((char *)s2, &st2); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2822 if (r1 != 0 && r2 != 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2823 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18516
diff
changeset
|
2824 // if mch_stat() doesn't work, may compare the names |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2825 if (checkname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2826 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2827 if (fnamecmp(exp1, s2) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2828 return FPC_SAMEX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2829 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2830 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2831 if (r1 == OK && r2 == OK && fnamecmp(full1, full2) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2832 return FPC_SAMEX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2833 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2834 return FPC_NOTX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2835 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2836 if (r1 != 0 || r2 != 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2837 return FPC_DIFFX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2838 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2839 return FPC_SAME; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2840 return FPC_DIFF; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2841 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2842 char_u *exp1; // expanded s1 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2843 char_u *full1; // full path of s1 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2844 char_u *full2; // full path of s2 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2845 int retval = FPC_DIFF; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2846 int r1, r2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2847 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2848 // allocate one buffer to store three paths (alloc()/free() is slow!) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2849 if ((exp1 = alloc(MAXPATHL * 3)) != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2850 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2851 full1 = exp1 + MAXPATHL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2852 full2 = full1 + MAXPATHL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2853 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2854 if (expandenv) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2855 expand_env(s1, exp1, MAXPATHL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2856 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2857 vim_strncpy(exp1, s1, MAXPATHL - 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2858 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2859 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2860 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2861 // If vim_FullName() fails, the file probably doesn't exist. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2862 if (r1 != OK && r2 != OK) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2863 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2864 if (checkname && fnamecmp(exp1, s2) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2865 retval = FPC_SAMEX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2866 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2867 retval = FPC_NOTX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2868 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2869 else if (r1 != OK || r2 != OK) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2870 retval = FPC_DIFFX; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2871 else if (fnamecmp(full1, full2)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2872 retval = FPC_DIFF; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2873 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2874 retval = FPC_SAME; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2875 vim_free(exp1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2876 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2877 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2878 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2879 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2880 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2881 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2882 * Get the tail of a path: the file name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2883 * When the path ends in a path separator the tail is the NUL after it. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2884 * Fail safe: never returns NULL. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2885 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2886 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2887 gettail(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2888 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2889 char_u *p1, *p2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2890 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2891 if (fname == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2892 return (char_u *)""; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2893 for (p1 = p2 = get_past_head(fname); *p2; ) // find last part of path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2894 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2895 if (vim_ispathsep_nocolon(*p2)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2896 p1 = p2 + 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2897 MB_PTR_ADV(p2); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2898 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2899 return p1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2900 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2901 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2902 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2903 * Get pointer to tail of "fname", including path separators. Putting a NUL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2904 * here leaves the directory name. Takes care of "c:/" and "//". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2905 * Always returns a valid pointer. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2906 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2907 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2908 gettail_sep(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2909 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2910 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2911 char_u *t; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2912 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2913 p = get_past_head(fname); // don't remove the '/' from "c:/file" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2914 t = gettail(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2915 while (t > p && after_pathsep(fname, t)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2916 --t; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2917 #ifdef VMS |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2918 // path separator is part of the path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2919 ++t; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2920 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2921 return t; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2922 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2923 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2924 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2925 * get the next path component (just after the next path separator). |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2926 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2927 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2928 getnextcomp(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2929 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2930 while (*fname && !vim_ispathsep(*fname)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2931 MB_PTR_ADV(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2932 if (*fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2933 ++fname; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2934 return fname; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2935 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2936 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2937 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2938 * Get a pointer to one character past the head of a path name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2939 * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/"; Mac: no head. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2940 * If there is no head, path is returned. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2941 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2942 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2943 get_past_head(char_u *path) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2944 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2945 char_u *retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2946 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2947 #if defined(MSWIN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2948 // may skip "c:" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2949 if (isalpha(path[0]) && path[1] == ':') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2950 retval = path + 2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2951 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2952 retval = path; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2953 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2954 # if defined(AMIGA) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2955 // may skip "label:" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2956 retval = vim_strchr(path, ':'); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2957 if (retval == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2958 retval = path; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2959 # else // Unix |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2960 retval = path; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2961 # endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2962 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2963 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2964 while (vim_ispathsep(*retval)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2965 ++retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2966 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2967 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2968 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2969 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2970 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2971 * Return TRUE if 'c' is a path separator. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2972 * Note that for MS-Windows this includes the colon. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2973 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2974 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2975 vim_ispathsep(int c) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2976 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2977 #ifdef UNIX |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2978 return (c == '/'); // UNIX has ':' inside file names |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2979 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2980 # ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2981 return (c == ':' || c == '/' || c == '\\'); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2982 # else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2983 # ifdef VMS |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2984 // server"user passwd"::device:[full.path.name]fname.extension;version" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2985 return (c == ':' || c == '[' || c == ']' || c == '/' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2986 || c == '<' || c == '>' || c == '"' ); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2987 # else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2988 return (c == ':' || c == '/'); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2989 # endif // VMS |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2990 # endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2991 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2992 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2993 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2994 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2995 * Like vim_ispathsep(c), but exclude the colon for MS-Windows. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2996 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2997 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2998 vim_ispathsep_nocolon(int c) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
2999 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3000 return vim_ispathsep(c) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3001 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3002 && c != ':' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3003 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3004 ; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3005 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3006 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3007 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3008 * Return TRUE if the directory of "fname" exists, FALSE otherwise. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3009 * Also returns TRUE if there is no directory name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3010 * "fname" must be writable!. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3011 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3012 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3013 dir_of_file_exists(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3014 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3015 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3016 int c; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3017 int retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3018 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3019 p = gettail_sep(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3020 if (p == fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3021 return TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3022 c = *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3023 *p = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3024 retval = mch_isdir(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3025 *p = c; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3026 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3027 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3028 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3029 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3030 * Versions of fnamecmp() and fnamencmp() that handle '/' and '\' equally |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3031 * and deal with 'fileignorecase'. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3032 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3033 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3034 vim_fnamecmp(char_u *x, char_u *y) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3035 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3036 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3037 return vim_fnamencmp(x, y, MAXPATHL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3038 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3039 if (p_fic) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3040 return MB_STRICMP(x, y); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3041 return STRCMP(x, y); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3042 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3043 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3044 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3045 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3046 vim_fnamencmp(char_u *x, char_u *y, size_t len) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3047 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3048 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3049 char_u *px = x; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3050 char_u *py = y; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3051 int cx = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3052 int cy = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3053 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3054 while (len > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3055 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3056 cx = PTR2CHAR(px); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3057 cy = PTR2CHAR(py); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3058 if (cx == NUL || cy == NUL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3059 || ((p_fic ? MB_TOLOWER(cx) != MB_TOLOWER(cy) : cx != cy) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3060 && !(cx == '/' && cy == '\\') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3061 && !(cx == '\\' && cy == '/'))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3062 break; |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
3063 len -= mb_ptr2len(px); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
3064 px += mb_ptr2len(px); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
3065 py += mb_ptr2len(py); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3066 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3067 if (len == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3068 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3069 return (cx - cy); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3070 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3071 if (p_fic) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3072 return MB_STRNICMP(x, y, len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3073 return STRNCMP(x, y, len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3074 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3075 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3076 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3077 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3078 * Concatenate file names fname1 and fname2 into allocated memory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3079 * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3080 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3081 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3082 concat_fnames(char_u *fname1, char_u *fname2, int sep) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3083 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3084 char_u *dest; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3085 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3086 dest = alloc(STRLEN(fname1) + STRLEN(fname2) + 3); |
31667
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3087 if (dest == NULL) |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3088 return NULL; |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3089 |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3090 STRCPY(dest, fname1); |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3091 if (sep) |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3092 add_pathsep(dest); |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3093 STRCAT(dest, fname2); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3094 return dest; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3095 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3096 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3097 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3098 * Add a path separator to a file name, unless it already ends in a path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3099 * separator. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3100 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3101 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3102 add_pathsep(char_u *p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3103 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3104 if (*p != NUL && !after_pathsep(p, p + STRLEN(p))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3105 STRCAT(p, PATHSEPSTR); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3106 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3107 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3108 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3109 * FullName_save - Make an allocated copy of a full file name. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3110 * Returns NULL when out of memory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3111 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3112 char_u * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3113 FullName_save( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3114 char_u *fname, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3115 int force) // force expansion, even when it already looks |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3116 // like a full path name |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3117 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3118 char_u *buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3119 char_u *new_fname = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3120 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3121 if (fname == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3122 return NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3123 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3124 buf = alloc(MAXPATHL); |
31667
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3125 if (buf == NULL) |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3126 return NULL; |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3127 |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3128 if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3129 new_fname = vim_strsave(buf); |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3130 else |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3131 new_fname = vim_strsave(fname); |
b89cfd86e18e
patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents:
30922
diff
changeset
|
3132 vim_free(buf); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3133 return new_fname; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3134 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3135 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3136 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3137 * return TRUE if "fname" exists. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3138 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3139 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3140 vim_fexists(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3141 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3142 stat_T st; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3143 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3144 if (mch_stat((char *)fname, &st)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3145 return FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3146 return TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3147 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3148 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3149 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3150 * Invoke expand_wildcards() for one pattern. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3151 * Expand items like "%:h" before the expansion. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3152 * Returns OK or FAIL. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3153 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3154 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3155 expand_wildcards_eval( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3156 char_u **pat, // pointer to input pattern |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3157 int *num_file, // resulting number of files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3158 char_u ***file, // array of resulting files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3159 int flags) // EW_DIR, etc. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3160 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3161 int ret = FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3162 char_u *eval_pat = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3163 char_u *exp_pat = *pat; |
30049
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3164 char *ignored_msg; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3165 int usedlen; |
30049
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3166 int is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#'; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3167 int star_follows = FALSE; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3168 |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3169 if (is_cur_alt_file || *exp_pat == '<') |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3170 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3171 ++emsg_off; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3172 eval_pat = eval_vars(exp_pat, exp_pat, &usedlen, |
28635
dfe18756f2ad
patch 8.2.4841: empty string considered an error for expand()
Bram Moolenaar <Bram@vim.org>
parents:
28629
diff
changeset
|
3173 NULL, &ignored_msg, NULL, TRUE); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3174 --emsg_off; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3175 if (eval_pat != NULL) |
30049
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3176 { |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3177 star_follows = STRCMP(exp_pat + usedlen, "*") == 0; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3178 exp_pat = concat_str(eval_pat, exp_pat + usedlen); |
30049
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3179 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3180 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3181 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3182 if (exp_pat != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3183 ret = expand_wildcards(1, &exp_pat, num_file, file, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3184 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3185 if (eval_pat != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3186 { |
30049
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3187 if (*num_file == 0 && is_cur_alt_file && star_follows) |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3188 { |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3189 // Expanding "%" or "#" and the file does not exist: Add the |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3190 // pattern anyway (without the star) so that this works for remote |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3191 // files and non-file buffer names. |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3192 *file = ALLOC_ONE(char_u *); |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3193 if (*file != NULL) |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3194 { |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3195 **file = eval_pat; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3196 eval_pat = NULL; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3197 *num_file = 1; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3198 ret = OK; |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3199 } |
f005dea14c8b
patch 9.0.0362: expanding ":e %" does not work for remote files
Bram Moolenaar <Bram@vim.org>
parents:
30015
diff
changeset
|
3200 } |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3201 vim_free(exp_pat); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3202 vim_free(eval_pat); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3203 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3204 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3205 return ret; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3206 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3207 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3208 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3209 * Expand wildcards. Calls gen_expand_wildcards() and removes files matching |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3210 * 'wildignore'. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3211 * Returns OK or FAIL. When FAIL then "num_files" won't be set. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3212 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3213 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3214 expand_wildcards( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3215 int num_pat, // number of input patterns |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3216 char_u **pat, // array of input patterns |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3217 int *num_files, // resulting number of files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3218 char_u ***files, // array of resulting files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3219 int flags) // EW_DIR, etc. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3220 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3221 int retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3222 int i, j; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3223 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3224 int non_suf_match; // number without matching suffix |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3225 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3226 retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3227 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3228 // When keeping all matches, return here |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3229 if ((flags & EW_KEEPALL) || retval == FAIL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3230 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3231 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3232 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3233 * Remove names that match 'wildignore'. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3234 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3235 if (*p_wig) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3236 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3237 char_u *ffname; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3238 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3239 // check all files in (*files)[] |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3240 for (i = 0; i < *num_files; ++i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3241 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3242 ffname = FullName_save((*files)[i], FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3243 if (ffname == NULL) // out of memory |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3244 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3245 # ifdef VMS |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3246 vms_remove_version(ffname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3247 # endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3248 if (match_file_list(p_wig, (*files)[i], ffname)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3249 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3250 // remove this matching file from the list |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3251 vim_free((*files)[i]); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3252 for (j = i; j + 1 < *num_files; ++j) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3253 (*files)[j] = (*files)[j + 1]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3254 --*num_files; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3255 --i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3256 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3257 vim_free(ffname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3258 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3259 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3260 // If the number of matches is now zero, we fail. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3261 if (*num_files == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3262 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3263 VIM_CLEAR(*files); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3264 return FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3265 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3266 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3267 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3268 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3269 * Move the names where 'suffixes' match to the end. |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3270 * Skip when interrupted, the result probably won't be used. |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3271 */ |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3272 if (*num_files > 1 && !got_int) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3273 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3274 non_suf_match = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3275 for (i = 0; i < *num_files; ++i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3276 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3277 if (!match_suffix((*files)[i])) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3278 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3279 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3280 * Move the name without matching suffix to the front |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3281 * of the list. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3282 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3283 p = (*files)[i]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3284 for (j = i; j > non_suf_match; --j) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3285 (*files)[j] = (*files)[j - 1]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3286 (*files)[non_suf_match++] = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3287 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3288 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3289 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3290 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3291 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3292 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3293 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3294 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3295 * Return TRUE if "fname" matches with an entry in 'suffixes'. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3296 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3297 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3298 match_suffix(char_u *fname) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3299 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3300 int fnamelen, setsuflen; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3301 char_u *setsuf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3302 #define MAXSUFLEN 30 // maximum length of a file suffix |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3303 char_u suf_buf[MAXSUFLEN]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3304 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3305 fnamelen = (int)STRLEN(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3306 setsuflen = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3307 for (setsuf = p_su; *setsuf; ) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3308 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3309 setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3310 if (setsuflen == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3311 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3312 char_u *tail = gettail(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3313 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3314 // empty entry: match name without a '.' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3315 if (vim_strchr(tail, '.') == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3316 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3317 setsuflen = 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3318 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3319 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3320 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3321 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3322 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3323 if (fnamelen >= setsuflen |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3324 && fnamencmp(suf_buf, fname + fnamelen - setsuflen, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3325 (size_t)setsuflen) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3326 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3327 setsuflen = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3328 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3329 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3330 return (setsuflen != 0); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3331 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3332 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3333 #ifdef VIM_BACKTICK |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3334 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3335 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3336 * Return TRUE if we can expand this backtick thing here. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3337 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3338 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3339 vim_backtick(char_u *p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3340 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3341 return (*p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`'); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3342 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3343 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3344 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3345 * Expand an item in `backticks` by executing it as a command. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3346 * Currently only works when pat[] starts and ends with a `. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3347 * Returns number of file names found, -1 if an error is encountered. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3348 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3349 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3350 expand_backtick( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3351 garray_T *gap, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3352 char_u *pat, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3353 int flags) // EW_* flags |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3354 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3355 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3356 char_u *cmd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3357 char_u *buffer; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3358 int cnt = 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3359 int i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3360 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3361 // Create the command: lop off the backticks. |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20780
diff
changeset
|
3362 cmd = vim_strnsave(pat + 1, STRLEN(pat) - 2); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3363 if (cmd == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3364 return -1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3365 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3366 #ifdef FEAT_EVAL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3367 if (*cmd == '=') // `={expr}`: Expand expression |
30598
37aa9fd2ed72
patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents:
30566
diff
changeset
|
3368 buffer = eval_to_string(cmd + 1, TRUE, FALSE); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3369 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3370 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3371 buffer = get_cmd_output(cmd, NULL, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3372 (flags & EW_SILENT) ? SHELL_SILENT : 0, NULL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3373 vim_free(cmd); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3374 if (buffer == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3375 return -1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3376 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3377 cmd = buffer; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3378 while (*cmd != NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3379 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3380 cmd = skipwhite(cmd); // skip over white space |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3381 p = cmd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3382 while (*p != NUL && *p != '\r' && *p != '\n') // skip over entry |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3383 ++p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3384 // add an entry if it is not empty |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3385 if (p > cmd) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3386 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3387 i = *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3388 *p = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3389 addfile(gap, cmd, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3390 *p = i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3391 ++cnt; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3392 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3393 cmd = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3394 while (*cmd != NUL && (*cmd == '\r' || *cmd == '\n')) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3395 ++cmd; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3396 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3397 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3398 vim_free(buffer); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3399 return cnt; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3400 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3401 #endif // VIM_BACKTICK |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3402 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3403 #if defined(MSWIN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3404 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3405 * File name expansion code for MS-DOS, Win16 and Win32. It's here because |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3406 * it's shared between these systems. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3407 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3408 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3409 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3410 * comparison function for qsort in dos_expandpath() |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3411 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3412 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3413 pstrcmp(const void *a, const void *b) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3414 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3415 return (pathcmp(*(char **)a, *(char **)b, -1)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3416 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3417 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3418 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3419 * Recursively expand one path component into all matching files and/or |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3420 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3421 * Return the number of matches found. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3422 * "path" has backslashes before chars that are not to be expanded, starting |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3423 * at "path[wildoff]". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3424 * Return the number of matches found. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3425 * NOTE: much of this is identical to unix_expandpath(), keep in sync! |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3426 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3427 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3428 dos_expandpath( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3429 garray_T *gap, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3430 char_u *path, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3431 int wildoff, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3432 int flags, // EW_* flags |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3433 int didstar) // expanded "**" once already |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3434 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3435 char_u *buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3436 char_u *path_end; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3437 char_u *p, *s, *e; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3438 int start_len = gap->ga_len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3439 char_u *pat; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3440 regmatch_T regmatch; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3441 int starts_with_dot; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3442 int matches; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3443 int len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3444 int starstar = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3445 static int stardepth = 0; // depth for "**" expansion |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3446 HANDLE hFind = INVALID_HANDLE_VALUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3447 WIN32_FIND_DATAW wfb; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3448 WCHAR *wn = NULL; // UCS-2 name, NULL when not used. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3449 char_u *matchname; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3450 int ok; |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3451 char_u *p_alt; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3452 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3453 // Expanding "**" may take a long time, check for CTRL-C. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3454 if (stardepth > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3455 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3456 ui_breakcheck(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3457 if (got_int) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3458 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3459 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3460 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3461 // Make room for file name. When doing encoding conversion the actual |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3462 // length may be quite a bit longer, thus use the maximum possible length. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3463 buf = alloc(MAXPATHL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3464 if (buf == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3465 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3466 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3467 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3468 * Find the first part in the path name that contains a wildcard or a ~1. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3469 * Copy it into buf, including the preceding characters. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3470 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3471 p = buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3472 s = buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3473 e = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3474 path_end = path; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3475 while (*path_end != NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3476 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3477 // May ignore a wildcard that has a backslash before it; it will |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3478 // be removed by rem_backslash() or file_pat_to_reg_pat() below. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3479 if (path_end >= path + wildoff && rem_backslash(path_end)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3480 *p++ = *path_end++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3481 else if (*path_end == '\\' || *path_end == ':' || *path_end == '/') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3482 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3483 if (e != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3484 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3485 s = p + 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3486 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3487 else if (path_end >= path + wildoff |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3488 && vim_strchr((char_u *)"*?[~", *path_end) != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3489 e = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3490 if (has_mbyte) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3491 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3492 len = (*mb_ptr2len)(path_end); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3493 STRNCPY(p, path_end, len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3494 p += len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3495 path_end += len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3496 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3497 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3498 *p++ = *path_end++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3499 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3500 e = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3501 *e = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3502 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3503 // now we have one wildcard component between s and e |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3504 // Remove backslashes between "wildoff" and the start of the wildcard |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3505 // component. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3506 for (p = buf + wildoff; p < s; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3507 if (rem_backslash(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3508 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3509 STRMOVE(p, p + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3510 --e; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3511 --s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3512 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3513 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3514 // Check for "**" between "s" and "e". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3515 for (p = s; p < e; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3516 if (p[0] == '*' && p[1] == '*') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3517 starstar = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3518 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3519 starts_with_dot = *s == '.'; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3520 pat = file_pat_to_reg_pat(s, e, NULL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3521 if (pat == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3522 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3523 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3524 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3525 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3526 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3527 // compile the regexp into a program |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3528 if (flags & (EW_NOERROR | EW_NOTWILD)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3529 ++emsg_silent; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3530 regmatch.rm_ic = TRUE; // Always ignore case |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3531 regmatch.regprog = vim_regcomp(pat, RE_MAGIC); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3532 if (flags & (EW_NOERROR | EW_NOTWILD)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3533 --emsg_silent; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3534 vim_free(pat); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3535 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3536 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3537 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3538 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3539 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3540 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3541 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3542 // remember the pattern or file name being looked for |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3543 matchname = vim_strsave(s); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3544 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3545 // If "**" is by itself, this is the first time we encounter it and more |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3546 // is following then find matches without any directory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3547 if (!didstar && stardepth < 100 && starstar && e - s == 2 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3548 && *path_end == '/') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3549 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3550 STRCPY(s, path_end + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3551 ++stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3552 (void)dos_expandpath(gap, buf, (int)(s - buf), flags, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3553 --stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3554 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3555 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3556 // Scan all files in the directory with "dir/ *.*" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3557 STRCPY(s, "*.*"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3558 wn = enc_to_utf16(buf, NULL); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3559 if (wn != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3560 hFind = FindFirstFileW(wn, &wfb); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3561 ok = (hFind != INVALID_HANDLE_VALUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3562 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3563 while (ok) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3564 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3565 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3566 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3567 if (p == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3568 break; // out of memory |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3569 |
23873
7d3ee4d508b5
patch 8.2.2478: MS-Windows: backup files for plugins are loaded
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
3570 // Do not use the alternate filename when the file name ends in '~', |
7d3ee4d508b5
patch 8.2.2478: MS-Windows: backup files for plugins are loaded
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
3571 // because it picks up backup files: short name for "foo.vim~" is |
7d3ee4d508b5
patch 8.2.2478: MS-Windows: backup files for plugins are loaded
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
3572 // "foo~1.vim", which matches "*.vim". |
7d3ee4d508b5
patch 8.2.2478: MS-Windows: backup files for plugins are loaded
Bram Moolenaar <Bram@vim.org>
parents:
23602
diff
changeset
|
3573 if (*wfb.cAlternateFileName == NUL || p[STRLEN(p) - 1] == '~') |
19938
f33098f1aec0
patch 8.2.0525: Win32: typo in assignment and misplaced paren
Bram Moolenaar <Bram@vim.org>
parents:
19936
diff
changeset
|
3574 p_alt = NULL; |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3575 else |
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3576 p_alt = utf16_to_enc(wfb.cAlternateFileName, NULL); |
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3577 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3578 // Ignore entries starting with a dot, unless when asked for. Accept |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3579 // all entries found with "matchname". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3580 if ((p[0] != '.' || starts_with_dot |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3581 || ((flags & EW_DODOT) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3582 && p[1] != NUL && (p[1] != '.' || p[2] != NUL))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3583 && (matchname == NULL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3584 || (regmatch.regprog != NULL |
19938
f33098f1aec0
patch 8.2.0525: Win32: typo in assignment and misplaced paren
Bram Moolenaar <Bram@vim.org>
parents:
19936
diff
changeset
|
3585 && (vim_regexec(®match, p, (colnr_T)0) |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3586 || (p_alt != NULL |
19938
f33098f1aec0
patch 8.2.0525: Win32: typo in assignment and misplaced paren
Bram Moolenaar <Bram@vim.org>
parents:
19936
diff
changeset
|
3587 && vim_regexec(®match, p_alt, (colnr_T)0)))) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3588 || ((flags & EW_NOTWILD) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3589 && fnamencmp(path + (s - buf), p, e - s) == 0))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3590 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3591 STRCPY(s, p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3592 len = (int)STRLEN(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3593 |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3594 if (starstar && stardepth < 100 |
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3595 && (wfb.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3596 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3597 // For "**" in the pattern first go deeper in the tree to |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3598 // find matches. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3599 STRCPY(buf + len, "/**"); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3600 STRCPY(buf + len + 3, path_end); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3601 ++stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3602 (void)dos_expandpath(gap, buf, len + 1, flags, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3603 --stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3604 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3605 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3606 STRCPY(buf + len, path_end); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3607 if (mch_has_exp_wildcard(path_end)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3608 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3609 // need to expand another component of the path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3610 // remove backslashes for the remaining components only |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3611 (void)dos_expandpath(gap, buf, len + 1, flags, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3612 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3613 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3614 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3615 // no more wildcards, check if there is a match |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3616 // remove backslashes for the remaining components only |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3617 if (*path_end != 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3618 backslash_halve(buf + len + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3619 if (mch_getperm(buf) >= 0) // add existing file |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3620 addfile(gap, buf, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3621 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3622 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3623 |
19936
ce463840c826
patch 8.2.0524: Win32: searching for file matches is slow
Bram Moolenaar <Bram@vim.org>
parents:
19930
diff
changeset
|
3624 vim_free(p_alt); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3625 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3626 ok = FindNextFileW(hFind, &wfb); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3627 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3628 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3629 FindClose(hFind); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3630 vim_free(wn); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3631 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3632 vim_regfree(regmatch.regprog); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3633 vim_free(matchname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3634 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3635 matches = gap->ga_len - start_len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3636 if (matches > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3637 qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3638 sizeof(char_u *), pstrcmp); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3639 return matches; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3640 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3641 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3642 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3643 mch_expandpath( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3644 garray_T *gap, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3645 char_u *path, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3646 int flags) // EW_* flags |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3647 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3648 return dos_expandpath(gap, path, 0, flags, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3649 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3650 #endif // MSWIN |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3651 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3652 #if (defined(UNIX) && !defined(VMS)) || defined(USE_UNIXFILENAME) \ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3653 || defined(PROTO) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3654 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3655 * Unix style wildcard expansion code. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3656 * It's here because it's used both for Unix and Mac. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3657 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3658 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3659 pstrcmp(const void *a, const void *b) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3660 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3661 return (pathcmp(*(char **)a, *(char **)b, -1)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3662 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3663 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3664 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3665 * Recursively expand one path component into all matching files and/or |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3666 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3667 * "path" has backslashes before chars that are not to be expanded, starting |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3668 * at "path + wildoff". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3669 * Return the number of matches found. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3670 * NOTE: much of this is identical to dos_expandpath(), keep in sync! |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3671 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3672 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3673 unix_expandpath( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3674 garray_T *gap, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3675 char_u *path, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3676 int wildoff, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3677 int flags, // EW_* flags |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3678 int didstar) // expanded "**" once already |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3679 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3680 char_u *buf; |
28881
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3681 size_t buflen; |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3682 char_u *path_end; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3683 char_u *p, *s, *e; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3684 int start_len = gap->ga_len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3685 char_u *pat; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3686 regmatch_T regmatch; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3687 int starts_with_dot; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3688 int matches; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3689 int len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3690 int starstar = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3691 static int stardepth = 0; // depth for "**" expansion |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3692 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3693 DIR *dirp; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3694 struct dirent *dp; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3695 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3696 // Expanding "**" may take a long time, check for CTRL-C. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3697 if (stardepth > 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3698 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3699 ui_breakcheck(); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3700 if (got_int) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3701 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3702 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3703 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3704 // make room for file name |
28881
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3705 buflen = STRLEN(path) + BASENAMELEN + 5; |
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3706 buf = alloc(buflen); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3707 if (buf == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3708 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3709 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3710 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3711 * Find the first part in the path name that contains a wildcard. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3712 * When EW_ICASE is set every letter is considered to be a wildcard. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3713 * Copy it into "buf", including the preceding characters. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3714 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3715 p = buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3716 s = buf; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3717 e = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3718 path_end = path; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3719 while (*path_end != NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3720 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3721 // May ignore a wildcard that has a backslash before it; it will |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3722 // be removed by rem_backslash() or file_pat_to_reg_pat() below. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3723 if (path_end >= path + wildoff && rem_backslash(path_end)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3724 *p++ = *path_end++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3725 else if (*path_end == '/') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3726 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3727 if (e != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3728 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3729 s = p + 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3730 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3731 else if (path_end >= path + wildoff |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3732 && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3733 || (!p_fic && (flags & EW_ICASE) |
27784
bfce04a99561
patch 8.2.4418: crash when using special multi-byte character
Bram Moolenaar <Bram@vim.org>
parents:
27621
diff
changeset
|
3734 && vim_isalpha(PTR2CHAR(path_end))))) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3735 e = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3736 if (has_mbyte) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3737 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3738 len = (*mb_ptr2len)(path_end); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3739 STRNCPY(p, path_end, len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3740 p += len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3741 path_end += len; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3742 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3743 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3744 *p++ = *path_end++; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3745 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3746 e = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3747 *e = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3748 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3749 // Now we have one wildcard component between "s" and "e". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3750 // Remove backslashes between "wildoff" and the start of the wildcard |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3751 // component. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3752 for (p = buf + wildoff; p < s; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3753 if (rem_backslash(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3754 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3755 STRMOVE(p, p + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3756 --e; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3757 --s; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3758 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3759 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3760 // Check for "**" between "s" and "e". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3761 for (p = s; p < e; ++p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3762 if (p[0] == '*' && p[1] == '*') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3763 starstar = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3764 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3765 // convert the file pattern to a regexp pattern |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3766 starts_with_dot = *s == '.'; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3767 pat = file_pat_to_reg_pat(s, e, NULL, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3768 if (pat == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3769 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3770 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3771 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3772 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3773 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3774 // compile the regexp into a program |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3775 if (flags & EW_ICASE) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3776 regmatch.rm_ic = TRUE; // 'wildignorecase' set |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3777 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3778 regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3779 if (flags & (EW_NOERROR | EW_NOTWILD)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3780 ++emsg_silent; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3781 regmatch.regprog = vim_regcomp(pat, RE_MAGIC); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3782 if (flags & (EW_NOERROR | EW_NOTWILD)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3783 --emsg_silent; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3784 vim_free(pat); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3785 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3786 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3787 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3788 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3789 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3790 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3791 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3792 // If "**" is by itself, this is the first time we encounter it and more |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3793 // is following then find matches without any directory. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3794 if (!didstar && stardepth < 100 && starstar && e - s == 2 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3795 && *path_end == '/') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3796 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3797 STRCPY(s, path_end + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3798 ++stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3799 (void)unix_expandpath(gap, buf, (int)(s - buf), flags, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3800 --stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3801 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3802 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3803 // open the directory for scanning |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3804 *s = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3805 dirp = opendir(*buf == NUL ? "." : (char *)buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3806 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3807 // Find all matching entries |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3808 if (dirp != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3809 { |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3810 while (!got_int) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3811 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3812 dp = readdir(dirp); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3813 if (dp == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3814 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3815 if ((dp->d_name[0] != '.' || starts_with_dot |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3816 || ((flags & EW_DODOT) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3817 && dp->d_name[1] != NUL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3818 && (dp->d_name[1] != '.' || dp->d_name[2] != NUL))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3819 && ((regmatch.regprog != NULL && vim_regexec(®match, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3820 (char_u *)dp->d_name, (colnr_T)0)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3821 || ((flags & EW_NOTWILD) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3822 && fnamencmp(path + (s - buf), dp->d_name, e - s) == 0))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3823 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3824 STRCPY(s, dp->d_name); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3825 len = STRLEN(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3826 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3827 if (starstar && stardepth < 100) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3828 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3829 // For "**" in the pattern first go deeper in the tree to |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3830 // find matches. |
28881
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3831 vim_snprintf((char *)buf + len, buflen - len, |
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3832 "/**%s", path_end); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3833 ++stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3834 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3835 --stardepth; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3836 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3837 |
28881
3ddaf476a874
patch 8.2.4963: expanding path with "/**" may overrun end of buffer
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
3838 vim_snprintf((char *)buf + len, buflen - len, "%s", path_end); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3839 if (mch_has_exp_wildcard(path_end)) // handle more wildcards |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3840 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3841 // need to expand another component of the path |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3842 // remove backslashes for the remaining components only |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3843 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3844 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3845 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3846 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3847 stat_T sb; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3848 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3849 // no more wildcards, check if there is a match |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3850 // remove backslashes for the remaining components only |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3851 if (*path_end != NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3852 backslash_halve(buf + len + 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3853 // add existing file or symbolic link |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3854 if ((flags & EW_ALLLINKS) ? mch_lstat((char *)buf, &sb) >= 0 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3855 : mch_getperm(buf) >= 0) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3856 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3857 #ifdef MACOS_CONVERT |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3858 size_t precomp_len = STRLEN(buf)+1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3859 char_u *precomp_buf = |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3860 mac_precompose_path(buf, precomp_len, &precomp_len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3861 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3862 if (precomp_buf) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3863 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3864 mch_memmove(buf, precomp_buf, precomp_len); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3865 vim_free(precomp_buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3866 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3867 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3868 addfile(gap, buf, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3869 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3870 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3871 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3872 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3873 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3874 closedir(dirp); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3875 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3876 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3877 vim_free(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3878 vim_regfree(regmatch.regprog); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3879 |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3880 // When interrupted the matches probably won't be used and sorting can be |
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3881 // slow, thus skip it. |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3882 matches = gap->ga_len - start_len; |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3883 if (matches > 0 && !got_int) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3884 qsort(((char_u **)gap->ga_data) + start_len, matches, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3885 sizeof(char_u *), pstrcmp); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3886 return matches; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3887 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3888 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3889 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3890 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3891 * Return TRUE if "p" contains what looks like an environment variable. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3892 * Allowing for escaping. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3893 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3894 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3895 has_env_var(char_u *p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3896 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3897 for ( ; *p; MB_PTR_ADV(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3898 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3899 if (*p == '\\' && p[1] != NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3900 ++p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3901 else if (vim_strchr((char_u *) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3902 #if defined(MSWIN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3903 "$%" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3904 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3905 "$" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3906 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3907 , *p) != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3908 return TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3909 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3910 return FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3911 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3912 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3913 #ifdef SPECIAL_WILDCHAR |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3914 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3915 * Return TRUE if "p" contains a special wildcard character, one that Vim |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3916 * cannot expand, requires using a shell. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3917 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3918 static int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3919 has_special_wildchar(char_u *p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3920 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3921 for ( ; *p; MB_PTR_ADV(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3922 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3923 // Disallow line break characters. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3924 if (*p == '\r' || *p == '\n') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3925 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3926 // Allow for escaping. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3927 if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3928 ++p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3929 else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3930 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3931 // A { must be followed by a matching }. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3932 if (*p == '{' && vim_strchr(p, '}') == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3933 continue; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3934 // A quote and backtick must be followed by another one. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3935 if ((*p == '`' || *p == '\'') && vim_strchr(p, *p) == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3936 continue; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3937 return TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3938 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3939 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3940 return FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3941 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3942 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3943 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3944 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3945 * Generic wildcard expansion code. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3946 * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3947 * Characters in "pat" that should not be expanded must be preceded with a |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3948 * backslash. E.g., "/path\ with\ spaces/my\*star*" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3949 * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3950 * Return FAIL when no single file was found. In this case "num_file" is not |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3951 * set, and "file" may contain an error message. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3952 * Return OK when some files found. "num_file" is set to the number of |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3953 * matches, "file" to the array of matches. Call FreeWild() later. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3954 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3955 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3956 gen_expand_wildcards( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3957 int num_pat, // number of input patterns |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3958 char_u **pat, // array of input patterns |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3959 int *num_file, // resulting number of files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3960 char_u ***file, // array of resulting files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3961 int flags) // EW_* flags |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3962 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3963 int i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3964 garray_T ga; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3965 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3966 static int recursive = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3967 int add_pat; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3968 int retval = OK; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3969 int did_expand_in_path = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3970 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3971 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3972 * expand_env() is called to expand things like "~user". If this fails, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3973 * it calls ExpandOne(), which brings us back here. In this case, always |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3974 * call the machine specific expansion function, if possible. Otherwise, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3975 * return FAIL. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3976 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3977 if (recursive) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3978 #ifdef SPECIAL_WILDCHAR |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3979 return mch_expand_wildcards(num_pat, pat, num_file, file, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3980 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3981 return FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3982 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3983 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3984 #ifdef SPECIAL_WILDCHAR |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3985 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3986 * If there are any special wildcard characters which we cannot handle |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3987 * here, call machine specific function for all the expansion. This |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3988 * avoids starting the shell for each argument separately. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3989 * For `=expr` do use the internal function. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3990 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3991 for (i = 0; i < num_pat; i++) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3992 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3993 if (has_special_wildchar(pat[i]) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3994 # ifdef VIM_BACKTICK |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3995 && !(vim_backtick(pat[i]) && pat[i][1] == '=') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3996 # endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3997 ) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3998 return mch_expand_wildcards(num_pat, pat, num_file, file, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
3999 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4000 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4001 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4002 recursive = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4003 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4004 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4005 * The matching file names are stored in a growarray. Init it empty. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4006 */ |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
4007 ga_init2(&ga, sizeof(char_u *), 30); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4008 |
29784
86c203dbf12b
patch 9.0.0231: expanding "**" may loop forever with directory links
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
4009 for (i = 0; i < num_pat && !got_int; ++i) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4010 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4011 add_pat = -1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4012 p = pat[i]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4013 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4014 #ifdef VIM_BACKTICK |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4015 if (vim_backtick(p)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4016 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4017 add_pat = expand_backtick(&ga, p, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4018 if (add_pat == -1) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4019 retval = FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4020 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4021 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4022 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4023 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4024 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4025 * First expand environment variables, "~/" and "~user/". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4026 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4027 if ((has_env_var(p) && !(flags & EW_NOTENV)) || *p == '~') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4028 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4029 p = expand_env_save_opt(p, TRUE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4030 if (p == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4031 p = pat[i]; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4032 #ifdef UNIX |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4033 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4034 * On Unix, if expand_env() can't expand an environment |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4035 * variable, use the shell to do that. Discard previously |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4036 * found file names and start all over again. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4037 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4038 else if (has_env_var(p) || *p == '~') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4039 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4040 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4041 ga_clear_strings(&ga); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4042 i = mch_expand_wildcards(num_pat, pat, num_file, file, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4043 flags|EW_KEEPDOLLAR); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4044 recursive = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4045 return i; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4046 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4047 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4048 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4049 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4050 /* |
28291
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4051 * If there are wildcards or case-insensitive expansion is |
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4052 * required: Expand file names and add each match to the list. If |
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4053 * there is no match, and EW_NOTFOUND is given, add the pattern. |
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4054 * Otherwise: Add the file name if it exists or when EW_NOTFOUND is |
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4055 * given. |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4056 */ |
28291
1c97a31f8f22
patch 8.2.4671: 'wildignorecase' is sometimes not used for glob()
Bram Moolenaar <Bram@vim.org>
parents:
28255
diff
changeset
|
4057 if (mch_has_exp_wildcard(p) || (flags & EW_ICASE)) |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4058 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4059 if ((flags & EW_PATH) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4060 && !mch_isFullName(p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4061 && !(p[0] == '.' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4062 && (vim_ispathsep(p[1]) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4063 || (p[1] == '.' && vim_ispathsep(p[2])))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4064 ) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4065 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4066 // :find completion where 'path' is used. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4067 // Recursiveness is OK here. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4068 recursive = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4069 add_pat = expand_in_path(&ga, p, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4070 recursive = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4071 did_expand_in_path = TRUE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4072 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4073 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4074 add_pat = mch_expandpath(&ga, p, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4075 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4076 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4077 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4078 if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4079 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4080 char_u *t = backslash_halve_save(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4081 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4082 // When EW_NOTFOUND is used, always add files and dirs. Makes |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4083 // "vim c:/" work. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4084 if (flags & EW_NOTFOUND) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4085 addfile(&ga, t, flags | EW_DIR | EW_FILE); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4086 else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4087 addfile(&ga, t, flags); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4088 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4089 if (t != p) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4090 vim_free(t); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4091 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4092 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4093 if (did_expand_in_path && ga.ga_len > 0 && (flags & EW_PATH)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4094 uniquefy_paths(&ga, p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4095 if (p != pat[i]) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4096 vim_free(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4097 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4098 |
21072
42e2fb7ec6e1
patch 8.2.1087: possible memory leak when file expansion fails
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
4099 // When returning FAIL the array must be freed here. |
42e2fb7ec6e1
patch 8.2.1087: possible memory leak when file expansion fails
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
4100 if (retval == FAIL) |
28307
425700af491b
patch 8.2.4679: cannot have expandcmd() give an error message for mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28291
diff
changeset
|
4101 ga_clear_strings(&ga); |
21072
42e2fb7ec6e1
patch 8.2.1087: possible memory leak when file expansion fails
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
4102 |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4103 *num_file = ga.ga_len; |
21072
42e2fb7ec6e1
patch 8.2.1087: possible memory leak when file expansion fails
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
4104 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data |
42e2fb7ec6e1
patch 8.2.1087: possible memory leak when file expansion fails
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
4105 : (char_u **)_("no matches"); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4106 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4107 recursive = FALSE; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4108 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4109 return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? retval : FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4110 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4111 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4112 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4113 * Add a file to a file list. Accepted flags: |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4114 * EW_DIR add directories |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4115 * EW_FILE add files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4116 * EW_EXEC add executable files |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4117 * EW_NOTFOUND add even when it doesn't exist |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4118 * EW_ADDSLASH add slash after directory name |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4119 * EW_ALLLINKS add symlink also when the referred file does not exist |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4120 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4121 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4122 addfile( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4123 garray_T *gap, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18516
diff
changeset
|
4124 char_u *f, // filename |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4125 int flags) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4126 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4127 char_u *p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4128 int isdir; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4129 stat_T sb; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4130 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4131 // if the file/dir/link doesn't exist, may not add it |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4132 if (!(flags & EW_NOTFOUND) && ((flags & EW_ALLLINKS) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4133 ? mch_lstat((char *)f, &sb) < 0 : mch_getperm(f) < 0)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4134 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4135 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4136 #ifdef FNAME_ILLEGAL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4137 // if the file/dir contains illegal characters, don't add it |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4138 if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4139 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4140 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4141 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4142 isdir = mch_isdir(f); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4143 if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4144 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4145 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4146 // If the file isn't executable, may not add it. Do accept directories. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4147 // When invoked from expand_shellcmd() do not use $PATH. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4148 if (!isdir && (flags & EW_EXEC) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4149 && !mch_can_exe(f, NULL, !(flags & EW_SHELLCMD))) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4150 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4151 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4152 // Make room for another item in the file list. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4153 if (ga_grow(gap, 1) == FAIL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4154 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4155 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4156 p = alloc(STRLEN(f) + 1 + isdir); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4157 if (p == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4158 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4159 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4160 STRCPY(p, f); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4161 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4162 slash_adjust(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4163 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4164 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4165 * Append a slash or backslash after directory names if none is present. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4166 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4167 if (isdir && (flags & EW_ADDSLASH)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4168 add_pathsep(p); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4169 ((char_u **)gap->ga_data)[gap->ga_len++] = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4170 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4171 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4172 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4173 * Free the list of files returned by expand_wildcards() or other expansion |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4174 * functions. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4175 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4176 void |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4177 FreeWild(int count, char_u **files) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4178 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4179 if (count <= 0 || files == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4180 return; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4181 while (count--) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4182 vim_free(files[count]); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4183 vim_free(files); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4184 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4185 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4186 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4187 * Compare path "p[]" to "q[]". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4188 * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4189 * Return value like strcmp(p, q), but consider path separators. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4190 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4191 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4192 pathcmp(const char *p, const char *q, int maxlen) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4193 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4194 int i, j; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4195 int c1, c2; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4196 const char *s = NULL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4197 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4198 for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4199 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4200 c1 = PTR2CHAR((char_u *)p + i); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4201 c2 = PTR2CHAR((char_u *)q + j); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4202 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4203 // End of "p": check if "q" also ends or just has a slash. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4204 if (c1 == NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4205 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4206 if (c2 == NUL) // full match |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4207 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4208 s = q; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4209 i = j; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4210 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4211 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4212 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4213 // End of "q": check if "p" just has a slash. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4214 if (c2 == NUL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4215 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4216 s = p; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4217 break; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4218 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4219 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4220 if ((p_fic ? MB_TOUPPER(c1) != MB_TOUPPER(c2) : c1 != c2) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4221 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4222 // consider '/' and '\\' to be equal |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4223 && !((c1 == '/' && c2 == '\\') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4224 || (c1 == '\\' && c2 == '/')) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4225 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4226 ) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4227 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4228 if (vim_ispathsep(c1)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4229 return -1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4230 if (vim_ispathsep(c2)) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4231 return 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4232 return p_fic ? MB_TOUPPER(c1) - MB_TOUPPER(c2) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4233 : c1 - c2; // no match |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4234 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4235 |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
4236 i += mb_ptr2len((char_u *)p + i); |
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
4237 j += mb_ptr2len((char_u *)q + j); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4238 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4239 if (s == NULL) // "i" or "j" ran into "maxlen" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4240 return 0; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4241 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4242 c1 = PTR2CHAR((char_u *)s + i); |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
4243 c2 = PTR2CHAR((char_u *)s + i + mb_ptr2len((char_u *)s + i)); |
17978
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4244 // ignore a trailing slash, but not "//" or ":/" |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4245 if (c2 == NUL |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4246 && i > 0 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4247 && !after_pathsep((char_u *)s, (char_u *)s + i) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4248 #ifdef BACKSLASH_IN_FILENAME |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4249 && (c1 == '/' || c1 == '\\') |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4250 #else |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4251 && c1 == '/' |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4252 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4253 ) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4254 return 0; // match with trailing slash |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4255 if (s == q) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4256 return -1; // no match |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4257 return 1; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4258 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4259 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4260 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4261 * Return TRUE if "name" is a full (absolute) path name or URL. |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4262 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4263 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4264 vim_isAbsName(char_u *name) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4265 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4266 return (path_with_url(name) != 0 || mch_isFullName(name)); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4267 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4268 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4269 /* |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4270 * Get absolute file name into buffer "buf[len]". |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4271 * |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4272 * return FAIL for failure, OK otherwise |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4273 */ |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4274 int |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4275 vim_FullName( |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4276 char_u *fname, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4277 char_u *buf, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4278 int len, |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4279 int force) // force expansion even when already absolute |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4280 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4281 int retval = OK; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4282 int url; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4283 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4284 *buf = NUL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4285 if (fname == NULL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4286 return FAIL; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4287 |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4288 url = path_with_url(fname); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4289 if (!url) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4290 retval = mch_FullName(fname, buf, len, force); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4291 if (url || retval == FAIL) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4292 { |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4293 // something failed; use the file name (truncate when too long) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4294 vim_strncpy(buf, fname, len - 1); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4295 } |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4296 #if defined(MSWIN) |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4297 slash_adjust(buf); |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4298 #endif |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4299 return retval; |
8f4cc259ed7a
patch 8.1.1985: code for dealing with paths is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17966
diff
changeset
|
4300 } |