Mercurial > vim
annotate src/fileio.c @ 25750:06e0400d9d69
Added tag v8.2.3410 for changeset 24b80aa4dd2e4e88b119dc1c0cc34cb52e010e4a
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 07 Sep 2021 21:00:06 +0200 |
parents | c094a29722bb |
children | 15fe946b1a41 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * fileio.c: read from and write to a file | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
21329
bb3f60b0aca0
patch 8.2.1215: Atari MiNT support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
21154
diff
changeset
|
16 #if defined(__TANDEM) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
17 # include <limits.h> // for SSIZE_MAX |
7 | 18 #endif |
23503
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
19 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_EVAL) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
20 # include <pwd.h> |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
21 # include <grp.h> |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
22 #endif |
23503
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
23 #if defined(VMS) && defined(HAVE_XOS_R_H) |
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
24 # include <x11/xos_r.h> |
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
25 #endif |
7 | 26 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
27 // Is there any system that doesn't have access()? |
574 | 28 #define USE_MCH_ACCESS |
7 | 29 |
22041
f55cba26348f
patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
30 #if defined(__hpux) && !defined(HAVE_DIRFD) |
f55cba26348f
patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
31 # define dirfd(x) ((x)->__dd_fd) |
f55cba26348f
patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
32 # define HAVE_DIRFD |
f55cba26348f
patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
33 #endif |
f55cba26348f
patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents:
21745
diff
changeset
|
34 |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
35 static char_u *next_fenc(char_u **pp, int *alloced); |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
36 #ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
37 static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp); |
7 | 38 #endif |
39 #ifdef FEAT_CRYPT | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
40 static char_u *check_for_cryptkey(char_u *cryptkey, char_u *ptr, long *sizep, off_T *filesizep, int newfile, char_u *fname, int *did_ask); |
7 | 41 #endif |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
42 static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, char_u *endp); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
43 static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags); |
1834 | 44 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
45 |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
46 #ifdef FEAT_EVAL |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
47 static int readdirex_sort; |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
48 #endif |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
49 |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
50 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
51 filemess( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
52 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
53 char_u *name, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
54 char_u *s, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
55 int attr) |
7 | 56 { |
57 int msg_scroll_save; | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
58 int prev_msg_col = msg_col; |
7 | 59 |
60 if (msg_silent != 0) | |
61 return; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
62 msg_add_fname(buf, name); // put file name in IObuff with quotes |
21073
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
63 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
64 // If it's extremely long, truncate it. |
21073
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
65 if (STRLEN(IObuff) > IOSIZE - 100) |
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
66 IObuff[IOSIZE - 100] = NUL; |
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
67 |
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
68 // Avoid an over-long translation to cause trouble. |
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
69 STRNCAT(IObuff, s, 99); |
334a8a5a6267
patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents:
20873
diff
changeset
|
70 |
7 | 71 /* |
72 * For the first message may have to start a new line. | |
73 * For further ones overwrite the previous one, reset msg_scroll before | |
74 * calling filemess(). | |
75 */ | |
76 msg_scroll_save = msg_scroll; | |
77 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
78 msg_scroll = FALSE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
79 if (!msg_scroll) // wait a bit when overwriting an error msg |
7 | 80 check_for_delay(FALSE); |
81 msg_start(); | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
82 if (prev_msg_col != 0 && msg_col == 0) |
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
83 msg_putchar('\r'); // overwrite any previous message. |
7 | 84 msg_scroll = msg_scroll_save; |
85 msg_scrolled_ign = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
86 // may truncate the message to avoid a hit-return prompt |
7 | 87 msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr); |
88 msg_clr_eos(); | |
89 out_flush(); | |
90 msg_scrolled_ign = FALSE; | |
91 } | |
92 | |
93 /* | |
94 * Read lines from file "fname" into the buffer after line "from". | |
95 * | |
96 * 1. We allocate blocks with lalloc, as big as possible. | |
97 * 2. Each block is filled with characters from the file with a single read(). | |
98 * 3. The lines are inserted in the buffer with ml_append(). | |
99 * | |
100 * (caller must check that fname != NULL, unless READ_STDIN is used) | |
101 * | |
102 * "lines_to_skip" is the number of lines that must be skipped | |
103 * "lines_to_read" is the number of lines that are appended | |
104 * When not recovering lines_to_skip is 0 and lines_to_read MAXLNUM. | |
105 * | |
106 * flags: | |
107 * READ_NEW starting to edit a new buffer | |
108 * READ_FILTER reading filter output | |
109 * READ_STDIN read from stdin instead of a file | |
110 * READ_BUFFER read from curbuf instead of a file (converting after reading | |
111 * stdin) | |
112 * READ_DUMMY read into a dummy buffer (to check if file contents changed) | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
113 * READ_KEEP_UNDO don't clear undo info or read it from a file |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
114 * READ_FIFO read from fifo/socket instead of a file |
7 | 115 * |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
116 * return FAIL for failure, NOTDONE for directory (failure), or OK |
7 | 117 */ |
118 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
119 readfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
120 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
121 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
122 linenr_T from, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
123 linenr_T lines_to_skip, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
124 linenr_T lines_to_read, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
125 exarg_T *eap, // can be NULL! |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
126 int flags) |
7 | 127 { |
128 int fd = 0; | |
129 int newfile = (flags & READ_NEW); | |
130 int check_readonly; | |
131 int filtering = (flags & READ_FILTER); | |
132 int read_stdin = (flags & READ_STDIN); | |
133 int read_buffer = (flags & READ_BUFFER); | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
134 int read_fifo = (flags & READ_FIFO); |
1486 | 135 int set_options = newfile || read_buffer |
136 || (eap != NULL && eap->read_edit); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
137 linenr_T read_buf_lnum = 1; // next line to read from curbuf |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
138 colnr_T read_buf_col = 0; // next char to read from this line |
7 | 139 char_u c; |
140 linenr_T lnum = from; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
141 char_u *ptr = NULL; // pointer into read buffer |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
142 char_u *buffer = NULL; // read buffer |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
143 char_u *new_buffer = NULL; // init to shut up gcc |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
144 char_u *line_start = NULL; // init to shut up gcc |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
145 int wasempty; // buffer was empty before reading |
7 | 146 colnr_T len; |
147 long size = 0; | |
148 char_u *p; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
149 off_T filesize = 0; |
7 | 150 int skip_read = FALSE; |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
151 off_T filesize_disk = 0; // file size read from disk |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
152 off_T filesize_count = 0; // counter |
7 | 153 #ifdef FEAT_CRYPT |
154 char_u *cryptkey = NULL; | |
2204
c493d6bfde09
A few more changes for encryption. Add test that encrypted file can be read.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
155 int did_ask_for_key = FALSE; |
7 | 156 #endif |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
157 #ifdef FEAT_PERSISTENT_UNDO |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
158 context_sha256_T sha_ctx; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
159 int read_undo_file = FALSE; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
160 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
161 int split = 0; // number of split lines |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
162 #define UNKNOWN 0x0fffffff // file size is unknown |
7 | 163 linenr_T linecnt; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
164 int error = FALSE; // errors encountered |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
165 int ff_error = EOL_UNKNOWN; // file format with errors |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
166 long linerest = 0; // remaining chars in line |
7 | 167 #ifdef UNIX |
168 int perm = 0; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
169 int swap_mode = -1; // protection bits for swap file |
7 | 170 #else |
171 int perm; | |
172 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
173 int fileformat = 0; // end-of-line format |
7 | 174 int keep_fileformat = FALSE; |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
175 stat_T st; |
7 | 176 int file_readonly; |
177 linenr_T skip_count = 0; | |
178 linenr_T read_count = 0; | |
179 int msg_save = msg_scroll; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
180 linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
181 // last read was missing the eol |
10668
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
182 int try_mac; |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
183 int try_dos; |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
184 int try_unix; |
7 | 185 int file_rewind = FALSE; |
186 int can_retry; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
187 linenr_T conv_error = 0; // line nr with conversion error |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
188 linenr_T illegal_byte = 0; // line nr with illegal byte |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
189 int keep_dest_enc = FALSE; // don't retry when char doesn't fit |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
190 // in destination encoding |
595 | 191 int bad_char_behavior = BAD_REPLACE; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
192 // BAD_KEEP, BAD_DROP or character to |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
193 // replace with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
194 char_u *tmpname = NULL; // name of 'charconvert' output file |
7 | 195 int fio_flags = 0; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
196 char_u *fenc; // fileencoding to use |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
197 int fenc_alloced; // fenc_next is in allocated memory |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
198 char_u *fenc_next = NULL; // next item in 'fencs' or NULL |
7 | 199 int advance_fenc = FALSE; |
200 long real_size = 0; | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
201 #ifdef USE_ICONV |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
202 iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
203 # ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
204 int did_iconv = FALSE; // TRUE when iconv() failed and trying |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
205 // 'charconvert' next |
7 | 206 # endif |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
207 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
208 int converted = FALSE; // TRUE if conversion done |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
209 int notconverted = FALSE; // TRUE if conversion wanted but it |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
210 // wasn't possible |
7 | 211 char_u conv_rest[CONV_RESTLEN]; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
212 int conv_restlen = 0; // nr of bytes in conv_rest[] |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
213 pos_T orig_start; |
2563
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
214 buf_T *old_curbuf; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
215 char_u *old_b_ffname; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
216 char_u *old_b_fname; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
217 int using_b_ffname; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
218 int using_b_fname; |
22490
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
219 static char *msg_is_a_directory = N_("is a directory"); |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
220 int eof; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
221 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
222 au_did_filetype = FALSE; // reset before triggering any autocommands |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
223 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
224 curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read |
7 | 225 |
226 /* | |
227 * If there is no file name yet, use the one for the read file. | |
228 * BF_NOTEDITED is set to reflect this. | |
229 * Don't do this for a read from a filter. | |
230 * Only do this when 'cpoptions' contains the 'f' flag. | |
231 */ | |
232 if (curbuf->b_ffname == NULL | |
233 && !filtering | |
234 && fname != NULL | |
235 && vim_strchr(p_cpo, CPO_FNAMER) != NULL | |
236 && !(flags & READ_DUMMY)) | |
237 { | |
633 | 238 if (set_rw_fname(fname, sfname) == FAIL) |
239 return FAIL; | |
7 | 240 } |
241 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
242 // Remember the initial values of curbuf, curbuf->b_ffname and |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
243 // curbuf->b_fname to detect whether they are altered as a result of |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
244 // executing nasty autocommands. Also check if "fname" and "sfname" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
245 // point to one of these values. |
2563
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
246 old_curbuf = curbuf; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
247 old_b_ffname = curbuf->b_ffname; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
248 old_b_fname = curbuf->b_fname; |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
249 using_b_ffname = (fname == curbuf->b_ffname) |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
250 || (sfname == curbuf->b_ffname); |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
251 using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname); |
5769dc787ec5
Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents:
2523
diff
changeset
|
252 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
253 // After reading a file the cursor line changes but we don't want to |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
254 // display the line. |
167 | 255 ex_no_reprint = TRUE; |
256 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
257 // don't display the file info for another buffer now |
968 | 258 need_fileinfo = FALSE; |
259 | |
7 | 260 /* |
261 * For Unix: Use the short file name whenever possible. | |
262 * Avoids problems with networks and when directory names are changed. | |
263 * Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to | |
264 * another directory, which we don't detect. | |
265 */ | |
266 if (sfname == NULL) | |
267 sfname = fname; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
268 #if defined(UNIX) |
7 | 269 fname = sfname; |
270 #endif | |
271 | |
272 /* | |
273 * The BufReadCmd and FileReadCmd events intercept the reading process by | |
274 * executing the associated commands instead. | |
275 */ | |
276 if (!filtering && !read_stdin && !read_buffer) | |
277 { | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
278 orig_start = curbuf->b_op_start; |
7 | 279 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
280 // Set '[ mark to the line above where the lines go (line 1 if zero). |
7 | 281 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); |
282 curbuf->b_op_start.col = 0; | |
283 | |
284 if (newfile) | |
285 { | |
286 if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname, | |
287 FALSE, curbuf, eap)) | |
19836
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
288 { |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
289 int status = OK; |
7 | 290 #ifdef FEAT_EVAL |
19836
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
291 if (aborting()) |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
292 status = FAIL; |
7 | 293 #endif |
19836
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
294 // The BufReadCmd code usually uses ":read" to get the text and |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
295 // perhaps ":file" to change the buffer name. But we should |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
296 // consider this to work like ":edit", thus reset the |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
297 // BF_NOTEDITED flag. Then ":write" will work to overwrite the |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
298 // same file. |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
299 if (status == OK) |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
300 curbuf->b_flags &= ~BF_NOTEDITED; |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
301 return status; |
c32b295af9c5
patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
302 } |
7 | 303 } |
304 else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname, | |
305 FALSE, NULL, eap)) | |
306 #ifdef FEAT_EVAL | |
307 return aborting() ? FAIL : OK; | |
308 #else | |
309 return OK; | |
310 #endif | |
311 | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
312 curbuf->b_op_start = orig_start; |
7 | 313 } |
314 | |
315 if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
316 msg_scroll = FALSE; // overwrite previous file message |
7 | 317 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
318 msg_scroll = TRUE; // don't overwrite previous file message |
7 | 319 |
23 | 320 if (fname != NULL && *fname != NUL) |
321 { | |
22490
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
322 size_t namelen = STRLEN(fname); |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
323 |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
324 // If the name is too long we might crash further on, quit here. |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
325 if (namelen >= MAXPATHL) |
23 | 326 { |
327 filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0); | |
328 msg_end(); | |
329 msg_scroll = msg_save; | |
330 return FAIL; | |
331 } | |
22490
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
332 |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
333 // If the name ends in a path separator, we can't open it. Check here, |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
334 // because reading the file may actually work, but then creating the |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
335 // swap file may destroy it! Reported on MS-DOS and Win 95. |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
336 if (after_pathsep(fname, fname + namelen)) |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
337 { |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
338 filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
339 msg_end(); |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
340 msg_scroll = msg_save; |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
341 return FAIL; |
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
342 } |
7 | 343 } |
344 | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
345 if (!read_stdin && !read_buffer && !read_fifo) |
5322 | 346 { |
23503
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
347 #if defined(UNIX) || defined(VMS) |
5322 | 348 /* |
349 * On Unix it is possible to read a directory, so we have to | |
350 * check for it before the mch_open(). | |
351 */ | |
7 | 352 perm = mch_getperm(fname); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
353 if (perm >= 0 && !S_ISREG(perm) // not a regular file ... |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
354 && !S_ISFIFO(perm) // ... or fifo |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
355 && !S_ISSOCK(perm) // ... or socket |
1313 | 356 # ifdef OPEN_CHR_FILES |
357 && !(S_ISCHR(perm) && is_dev_fd_file(fname)) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
358 // ... or a character special file named /dev/fd/<n> |
1313 | 359 # endif |
7 | 360 ) |
361 { | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
362 int retval = FAIL; |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
363 |
7 | 364 if (S_ISDIR(perm)) |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
365 { |
22490
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
366 filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
367 retval = NOTDONE; |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
368 } |
7 | 369 else |
370 filemess(curbuf, fname, (char_u *)_("is not a file"), 0); | |
371 msg_end(); | |
372 msg_scroll = msg_save; | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
373 return retval; |
7 | 374 } |
5322 | 375 #endif |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
376 #if defined(MSWIN) |
1006 | 377 /* |
378 * MS-Windows allows opening a device, but we will probably get stuck | |
379 * trying to read it. | |
380 */ | |
381 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE) | |
382 { | |
1303 | 383 filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0); |
1006 | 384 msg_end(); |
385 msg_scroll = msg_save; | |
386 return FAIL; | |
387 } | |
5322 | 388 #endif |
389 } | |
1004 | 390 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
391 // Set default or forced 'fileformat' and 'binary'. |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
392 set_file_options(set_options, eap); |
7 | 393 |
394 /* | |
395 * When opening a new file we take the readonly flag from the file. | |
396 * Default is r/w, can be set to r/o below. | |
397 * Don't reset it when in readonly mode | |
398 * Only set/reset b_p_ro when BF_CHECK_RO is set. | |
399 */ | |
400 check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO)); | |
164 | 401 if (check_readonly && !readonlymode) |
7 | 402 curbuf->b_p_ro = FALSE; |
403 | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
404 if (newfile && !read_stdin && !read_buffer && !read_fifo) |
7 | 405 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
406 // Remember time of file. |
7 | 407 if (mch_stat((char *)fname, &st) >= 0) |
408 { | |
409 buf_store_time(curbuf, &st, fname); | |
410 curbuf->b_mtime_read = curbuf->b_mtime; | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
411 filesize_disk = st.st_size; |
7 | 412 #ifdef UNIX |
413 /* | |
414 * Use the protection bits of the original file for the swap file. | |
415 * This makes it possible for others to read the name of the | |
416 * edited file from the swapfile, but only if they can read the | |
417 * edited file. | |
418 * Remove the "write" and "execute" bits for group and others | |
419 * (they must not write the swapfile). | |
420 * Add the "read" and "write" bits for the user, otherwise we may | |
421 * not be able to write to the file ourselves. | |
422 * Setting the bits is done below, after creating the swap file. | |
423 */ | |
424 swap_mode = (st.st_mode & 0644) | 0600; | |
425 #endif | |
426 #ifdef VMS | |
427 curbuf->b_fab_rfm = st.st_fab_rfm; | |
22 | 428 curbuf->b_fab_rat = st.st_fab_rat; |
429 curbuf->b_fab_mrs = st.st_fab_mrs; | |
7 | 430 #endif |
431 } | |
432 else | |
433 { | |
434 curbuf->b_mtime = 0; | |
435 curbuf->b_mtime_read = 0; | |
436 curbuf->b_orig_size = 0; | |
437 curbuf->b_orig_mode = 0; | |
438 } | |
439 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
440 // Reset the "new file" flag. It will be set again below when the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
441 // file doesn't exist. |
7 | 442 curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); |
443 } | |
444 | |
445 /* | |
446 * for UNIX: check readonly with perm and mch_access() | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
447 * for Amiga: check readonly by trying to open the file for writing |
7 | 448 */ |
449 file_readonly = FALSE; | |
450 if (read_stdin) | |
451 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
452 #if defined(MSWIN) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
453 // Force binary I/O on stdin to avoid CR-LF -> LF conversion. |
7 | 454 setmode(0, O_BINARY); |
455 #endif | |
456 } | |
457 else if (!read_buffer) | |
458 { | |
459 #ifdef USE_MCH_ACCESS | |
460 if ( | |
461 # ifdef UNIX | |
462 !(perm & 0222) || | |
463 # endif | |
464 mch_access((char *)fname, W_OK)) | |
465 file_readonly = TRUE; | |
466 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); | |
467 #else | |
468 if (!newfile | |
469 || readonlymode | |
470 || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) | |
471 { | |
472 file_readonly = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
473 // try to open ro |
7 | 474 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); |
475 } | |
476 #endif | |
477 } | |
478 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
479 if (fd < 0) // cannot open at all |
7 | 480 { |
481 #ifndef UNIX | |
482 int isdir_f; | |
483 #endif | |
484 msg_scroll = msg_save; | |
485 #ifndef UNIX | |
486 /* | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
487 * On Amiga we can't open a directory, check here. |
7 | 488 */ |
489 isdir_f = (mch_isdir(fname)); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
490 perm = mch_getperm(fname); // check if the file exists |
7 | 491 if (isdir_f) |
492 { | |
22490
23a5977d7211
patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents:
22041
diff
changeset
|
493 filemess(curbuf, sfname, (char_u *)_(msg_is_a_directory), 0); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
494 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 495 } |
496 else | |
497 #endif | |
498 if (newfile) | |
499 { | |
2147
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
500 if (perm < 0 |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
501 #ifdef ENOENT |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
502 && errno == ENOENT |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
503 #endif |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
504 ) |
7 | 505 { |
506 /* | |
507 * Set the 'new-file' flag, so that when the file has | |
508 * been created by someone else, a ":w" will complain. | |
509 */ | |
510 curbuf->b_flags |= BF_NEW; | |
511 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
512 // Create a swap file now, so that other Vims are warned |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
513 // that we are editing this file. Don't do this for a |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
514 // "nofile" or "nowrite" buffer type. |
7 | 515 #ifdef FEAT_QUICKFIX |
516 if (!bt_dontwrite(curbuf)) | |
517 #endif | |
1834 | 518 { |
7 | 519 check_need_swap(newfile); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
520 // SwapExists autocommand may mess things up |
1834 | 521 if (curbuf != old_curbuf |
522 || (using_b_ffname | |
523 && (old_b_ffname != curbuf->b_ffname)) | |
524 || (using_b_fname | |
525 && (old_b_fname != curbuf->b_fname))) | |
526 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
527 emsg(_(e_auchangedbuf)); |
1834 | 528 return FAIL; |
529 } | |
530 } | |
592 | 531 if (dir_of_file_exists(fname)) |
20828
db18625d8134
patch 8.2.0966: 'shortmess' flag "n" not used in two places
Bram Moolenaar <Bram@vim.org>
parents:
20790
diff
changeset
|
532 filemess(curbuf, sfname, |
db18625d8134
patch 8.2.0966: 'shortmess' flag "n" not used in two places
Bram Moolenaar <Bram@vim.org>
parents:
20790
diff
changeset
|
533 (char_u *)new_file_message(), 0); |
592 | 534 else |
535 filemess(curbuf, sfname, | |
536 (char_u *)_("[New DIRECTORY]"), 0); | |
7 | 537 #ifdef FEAT_VIMINFO |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
538 // Even though this is a new file, it might have been |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
539 // edited before and deleted. Get the old marks. |
7 | 540 check_marks_read(); |
541 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
542 // Set forced 'fileencoding'. |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
543 if (eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
544 set_forced_fenc(eap); |
7 | 545 apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, |
546 FALSE, curbuf, eap); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
547 // remember the current fileformat |
7 | 548 save_file_ff(curbuf); |
549 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
550 #if defined(FEAT_EVAL) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
551 if (aborting()) // autocmds may abort script processing |
7 | 552 return FAIL; |
553 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
554 return OK; // a new file is not an error |
7 | 555 } |
556 else | |
557 { | |
550 | 558 filemess(curbuf, sfname, (char_u *)( |
559 # ifdef EFBIG | |
560 (errno == EFBIG) ? _("[File too big]") : | |
561 # endif | |
2147
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
562 # ifdef EOVERFLOW |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
563 (errno == EOVERFLOW) ? _("[File too big]") : |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
564 # endif |
550 | 565 _("[Permission Denied]")), 0); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
566 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 567 } |
568 } | |
569 | |
570 return FAIL; | |
571 } | |
572 | |
573 /* | |
574 * Only set the 'ro' flag for readonly files the first time they are | |
575 * loaded. Help files always get readonly mode | |
576 */ | |
577 if ((check_readonly && file_readonly) || curbuf->b_help) | |
578 curbuf->b_p_ro = TRUE; | |
579 | |
819 | 580 if (set_options) |
7 | 581 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
582 // Don't change 'eol' if reading from buffer as it will already be |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
583 // correctly set when reading stdin. |
1486 | 584 if (!read_buffer) |
585 { | |
586 curbuf->b_p_eol = TRUE; | |
587 curbuf->b_start_eol = TRUE; | |
588 } | |
7 | 589 curbuf->b_p_bomb = FALSE; |
1352 | 590 curbuf->b_start_bomb = FALSE; |
7 | 591 } |
592 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
593 // Create a swap file now, so that other Vims are warned that we are |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
594 // editing this file. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
595 // Don't do this for a "nofile" or "nowrite" buffer type. |
7 | 596 #ifdef FEAT_QUICKFIX |
597 if (!bt_dontwrite(curbuf)) | |
598 #endif | |
599 { | |
600 check_need_swap(newfile); | |
1834 | 601 if (!read_stdin && (curbuf != old_curbuf |
602 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) | |
603 || (using_b_fname && (old_b_fname != curbuf->b_fname)))) | |
604 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
605 emsg(_(e_auchangedbuf)); |
1834 | 606 if (!read_buffer) |
607 close(fd); | |
608 return FAIL; | |
609 } | |
7 | 610 #ifdef UNIX |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
611 // Set swap file protection bits after creating it. |
1918 | 612 if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL |
613 && curbuf->b_ml.ml_mfp->mf_fname != NULL) | |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
614 { |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
615 char_u *swap_fname = curbuf->b_ml.ml_mfp->mf_fname; |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
616 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
617 /* |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
618 * If the group-read bit is set but not the world-read bit, then |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
619 * the group must be equal to the group of the original file. If |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
620 * we can't make that happen then reset the group-read bit. This |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
621 * avoids making the swap file readable to more users when the |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
622 * primary group of the user is too permissive. |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
623 */ |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
624 if ((swap_mode & 044) == 040) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
625 { |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
626 stat_T swap_st; |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
627 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
628 if (mch_stat((char *)swap_fname, &swap_st) >= 0 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
629 && st.st_gid != swap_st.st_gid |
13730
7b818f7bb738
patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
630 # ifdef HAVE_FCHOWN |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
631 && fchown(curbuf->b_ml.ml_mfp->mf_fd, -1, st.st_gid) |
13988
68290d296dc9
patch 8.1.0012: misplaced #endif
Christian Brabandt <cb@256bit.org>
parents:
13819
diff
changeset
|
632 == -1 |
13730
7b818f7bb738
patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
633 # endif |
7b818f7bb738
patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
634 ) |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
635 swap_mode &= 0600; |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
636 } |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
637 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
638 (void)mch_setperm(swap_fname, (long)swap_mode); |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
639 } |
7 | 640 #endif |
641 } | |
642 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
643 // If "Quit" selected at ATTENTION dialog, don't load the file |
7 | 644 if (swap_exists_action == SEA_QUIT) |
645 { | |
646 if (!read_buffer && !read_stdin) | |
647 close(fd); | |
648 return FAIL; | |
649 } | |
650 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
651 ++no_wait_return; // don't wait for return yet |
7 | 652 |
653 /* | |
654 * Set '[ mark to the line above where the lines go (line 1 if zero). | |
655 */ | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
656 orig_start = curbuf->b_op_start; |
7 | 657 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); |
658 curbuf->b_op_start.col = 0; | |
659 | |
10668
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
660 try_mac = (vim_strchr(p_ffs, 'm') != NULL); |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
661 try_dos = (vim_strchr(p_ffs, 'd') != NULL); |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
662 try_unix = (vim_strchr(p_ffs, 'x') != NULL); |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
663 |
7 | 664 if (!read_buffer) |
665 { | |
666 int m = msg_scroll; | |
667 int n = msg_scrolled; | |
668 | |
669 /* | |
670 * The file must be closed again, the autocommands may want to change | |
671 * the file before reading it. | |
672 */ | |
673 if (!read_stdin) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
674 close(fd); // ignore errors |
7 | 675 |
676 /* | |
677 * The output from the autocommands should not overwrite anything and | |
678 * should not be overwritten: Set msg_scroll, restore its value if no | |
679 * output was done. | |
680 */ | |
681 msg_scroll = TRUE; | |
682 if (filtering) | |
683 apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname, | |
684 FALSE, curbuf, eap); | |
685 else if (read_stdin) | |
686 apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname, | |
687 FALSE, curbuf, eap); | |
688 else if (newfile) | |
689 apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname, | |
690 FALSE, curbuf, eap); | |
691 else | |
692 apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, | |
693 FALSE, NULL, eap); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
694 // autocommands may have changed it |
10668
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
695 try_mac = (vim_strchr(p_ffs, 'm') != NULL); |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
696 try_dos = (vim_strchr(p_ffs, 'd') != NULL); |
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
697 try_unix = (vim_strchr(p_ffs, 'x') != NULL); |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
698 curbuf->b_op_start = orig_start; |
10668
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
699 |
7 | 700 if (msg_scrolled == n) |
701 msg_scroll = m; | |
702 | |
703 #ifdef FEAT_EVAL | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
704 if (aborting()) // autocmds may abort script processing |
7 | 705 { |
706 --no_wait_return; | |
707 msg_scroll = msg_save; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
708 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 709 return FAIL; |
710 } | |
711 #endif | |
712 /* | |
713 * Don't allow the autocommands to change the current buffer. | |
714 * Try to re-open the file. | |
1834 | 715 * |
716 * Don't allow the autocommands to change the buffer name either | |
717 * (cd for example) if it invalidates fname or sfname. | |
7 | 718 */ |
719 if (!read_stdin && (curbuf != old_curbuf | |
1834 | 720 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) |
721 || (using_b_fname && (old_b_fname != curbuf->b_fname)) | |
7 | 722 || (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0)) |
723 { | |
724 --no_wait_return; | |
725 msg_scroll = msg_save; | |
726 if (fd < 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
727 emsg(_("E200: *ReadPre autocommands made the file unreadable")); |
7 | 728 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
729 emsg(_("E201: *ReadPre autocommands must not change current buffer")); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
730 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 731 return FAIL; |
732 } | |
733 } | |
734 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
735 // Autocommands may add lines to the file, need to check if it is empty |
7 | 736 wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
737 | |
738 if (!recoverymode && !filtering && !(flags & READ_DUMMY)) | |
739 { | |
740 /* | |
741 * Show the user that we are busy reading the input. Sometimes this | |
742 * may take a while. When reading from stdin another program may | |
743 * still be running, don't move the cursor to the last line, unless | |
744 * always using the GUI. | |
745 */ | |
746 if (read_stdin) | |
747 { | |
12863
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
748 if (!is_not_a_term()) |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
749 { |
7 | 750 #ifndef ALWAYS_USE_GUI |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
751 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
752 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
753 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
754 mch_msg(_("Vim: Reading from stdin...\n")); |
7 | 755 #endif |
756 #ifdef FEAT_GUI | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
757 // Also write a message in the GUI window, if there is one. |
12863
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
758 if (gui.in_use && !gui.dying && !gui.starting) |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
759 { |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
760 p = (char_u *)_("Reading from stdin..."); |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
761 gui_write(p, (int)STRLEN(p)); |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
762 } |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
763 #endif |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
764 } |
7 | 765 } |
766 else if (!read_buffer) | |
767 filemess(curbuf, sfname, (char_u *)"", 0); | |
768 } | |
769 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
770 msg_scroll = FALSE; // overwrite the file message |
7 | 771 |
772 /* | |
773 * Set linecnt now, before the "retry" caused by a wrong guess for | |
774 * fileformat, and after the autocommands, which may change them. | |
775 */ | |
776 linecnt = curbuf->b_ml.ml_line_count; | |
777 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
778 // "++bad=" argument. |
595 | 779 if (eap != NULL && eap->bad_char != 0) |
612 | 780 { |
595 | 781 bad_char_behavior = eap->bad_char; |
819 | 782 if (set_options) |
612 | 783 curbuf->b_bad_char = eap->bad_char; |
784 } | |
785 else | |
786 curbuf->b_bad_char = 0; | |
595 | 787 |
7 | 788 /* |
595 | 789 * Decide which 'encoding' to use or use first. |
7 | 790 */ |
791 if (eap != NULL && eap->force_enc != 0) | |
792 { | |
793 fenc = enc_canonize(eap->cmd + eap->force_enc); | |
794 fenc_alloced = TRUE; | |
595 | 795 keep_dest_enc = TRUE; |
7 | 796 } |
797 else if (curbuf->b_p_bin) | |
798 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
799 fenc = (char_u *)""; // binary: don't convert |
7 | 800 fenc_alloced = FALSE; |
801 } | |
802 else if (curbuf->b_help) | |
803 { | |
804 char_u firstline[80]; | |
301 | 805 int fc; |
7 | 806 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
807 // Help files are either utf-8 or latin1. Try utf-8 first, if this |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
808 // fails it must be latin1. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
809 // Always do this when 'encoding' is "utf-8". Otherwise only do |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
810 // this when needed to avoid [converted] remarks all the time. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
811 // It is needed when the first line contains non-ASCII characters. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
812 // That is only in *.??x files. |
7 | 813 fenc = (char_u *)"latin1"; |
814 c = enc_utf8; | |
301 | 815 if (!c && !read_stdin) |
816 { | |
817 fc = fname[STRLEN(fname) - 1]; | |
818 if (TOLOWER_ASC(fc) == 'x') | |
819 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
820 // Read the first line (and a bit more). Immediately rewind to |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
821 // the start of the file. If the read() fails "len" is -1. |
2664 | 822 len = read_eintr(fd, firstline, 80); |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
823 vim_lseek(fd, (off_T)0L, SEEK_SET); |
301 | 824 for (p = firstline; p < firstline + len; ++p) |
825 if (*p >= 0x80) | |
826 { | |
827 c = TRUE; | |
828 break; | |
829 } | |
830 } | |
7 | 831 } |
832 | |
833 if (c) | |
834 { | |
835 fenc_next = fenc; | |
836 fenc = (char_u *)"utf-8"; | |
837 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
838 // When the file is utf-8 but a character doesn't fit in |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
839 // 'encoding' don't retry. In help text editing utf-8 bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
840 // doesn't make sense. |
844 | 841 if (!enc_utf8) |
842 keep_dest_enc = TRUE; | |
7 | 843 } |
844 fenc_alloced = FALSE; | |
845 } | |
846 else if (*p_fencs == NUL) | |
847 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
848 fenc = curbuf->b_p_fenc; // use format from buffer |
7 | 849 fenc_alloced = FALSE; |
850 } | |
851 else | |
852 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
853 fenc_next = p_fencs; // try items in 'fileencodings' |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
854 fenc = next_fenc(&fenc_next, &fenc_alloced); |
7 | 855 } |
856 | |
857 /* | |
858 * Jump back here to retry reading the file in different ways. | |
859 * Reasons to retry: | |
860 * - encoding conversion failed: try another one from "fenc_next" | |
861 * - BOM detected and fenc was set, need to setup conversion | |
862 * - "fileformat" check failed: try another | |
863 * | |
864 * Variables set for special retry actions: | |
865 * "file_rewind" Rewind the file to start reading it again. | |
866 * "advance_fenc" Advance "fenc" using "fenc_next". | |
867 * "skip_read" Re-use already read bytes (BOM detected). | |
868 * "did_iconv" iconv() conversion failed, try 'charconvert'. | |
869 * "keep_fileformat" Don't reset "fileformat". | |
870 * | |
871 * Other status indicators: | |
872 * "tmpname" When != NULL did conversion with 'charconvert'. | |
873 * Output file has to be deleted afterwards. | |
874 * "iconv_fd" When != -1 did conversion with iconv(). | |
875 */ | |
876 retry: | |
877 | |
878 if (file_rewind) | |
879 { | |
880 if (read_buffer) | |
881 { | |
882 read_buf_lnum = 1; | |
883 read_buf_col = 0; | |
884 } | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
885 else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0) |
7 | 886 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
887 // Can't rewind the file, give up. |
7 | 888 error = TRUE; |
889 goto failed; | |
890 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
891 // Delete the previously read lines. |
7 | 892 while (lnum > from) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20311
diff
changeset
|
893 ml_delete(lnum--); |
7 | 894 file_rewind = FALSE; |
819 | 895 if (set_options) |
1352 | 896 { |
7 | 897 curbuf->b_p_bomb = FALSE; |
1352 | 898 curbuf->b_start_bomb = FALSE; |
899 } | |
595 | 900 conv_error = 0; |
7 | 901 } |
902 | |
903 /* | |
904 * When retrying with another "fenc" and the first time "fileformat" | |
905 * will be reset. | |
906 */ | |
907 if (keep_fileformat) | |
908 keep_fileformat = FALSE; | |
909 else | |
910 { | |
911 if (eap != NULL && eap->force_ff != 0) | |
1742 | 912 { |
7 | 913 fileformat = get_fileformat_force(curbuf, eap); |
1742 | 914 try_unix = try_dos = try_mac = FALSE; |
915 } | |
7 | 916 else if (curbuf->b_p_bin) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
917 fileformat = EOL_UNIX; // binary: use Unix format |
7 | 918 else if (*p_ffs == NUL) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
919 fileformat = get_fileformat(curbuf);// use format from buffer |
7 | 920 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
921 fileformat = EOL_UNKNOWN; // detect from file |
7 | 922 } |
923 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
924 #ifdef USE_ICONV |
7 | 925 if (iconv_fd != (iconv_t)-1) |
926 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
927 // aborted conversion with iconv(), close the descriptor |
7 | 928 iconv_close(iconv_fd); |
929 iconv_fd = (iconv_t)-1; | |
930 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
931 #endif |
7 | 932 |
933 if (advance_fenc) | |
934 { | |
935 /* | |
936 * Try the next entry in 'fileencodings'. | |
937 */ | |
938 advance_fenc = FALSE; | |
939 | |
940 if (eap != NULL && eap->force_enc != 0) | |
941 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
942 // Conversion given with "++cc=" wasn't possible, read |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
943 // without conversion. |
7 | 944 notconverted = TRUE; |
595 | 945 conv_error = 0; |
7 | 946 if (fenc_alloced) |
947 vim_free(fenc); | |
948 fenc = (char_u *)""; | |
949 fenc_alloced = FALSE; | |
950 } | |
951 else | |
952 { | |
953 if (fenc_alloced) | |
954 vim_free(fenc); | |
955 if (fenc_next != NULL) | |
956 { | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
957 fenc = next_fenc(&fenc_next, &fenc_alloced); |
7 | 958 } |
959 else | |
960 { | |
961 fenc = (char_u *)""; | |
962 fenc_alloced = FALSE; | |
963 } | |
964 } | |
965 if (tmpname != NULL) | |
966 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
967 mch_remove(tmpname); // delete converted file |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
968 VIM_CLEAR(tmpname); |
7 | 969 } |
970 } | |
971 | |
972 /* | |
1948 | 973 * Conversion may be required when the encoding of the file is different |
974 * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4. | |
7 | 975 */ |
976 fio_flags = 0; | |
1948 | 977 converted = need_conversion(fenc); |
978 if (converted) | |
7 | 979 { |
980 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
981 // "ucs-bom" means we need to check the first bytes of the file |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
982 // for a BOM. |
7 | 983 if (STRCMP(fenc, ENC_UCSBOM) == 0) |
984 fio_flags = FIO_UCSBOM; | |
985 | |
986 /* | |
987 * Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be | |
988 * done. This is handled below after read(). Prepare the | |
989 * fio_flags to avoid having to parse the string each time. | |
990 * Also check for Unicode to Latin1 conversion, because iconv() | |
991 * appears not to handle this correctly. This works just like | |
992 * conversion to UTF-8 except how the resulting character is put in | |
993 * the buffer. | |
994 */ | |
995 else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0) | |
996 fio_flags = get_fio_flags(fenc); | |
997 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
998 #ifdef MSWIN |
7 | 999 /* |
1000 * Conversion from an MS-Windows codepage to UTF-8 or another codepage | |
1001 * is handled with MultiByteToWideChar(). | |
1002 */ | |
1003 if (fio_flags == 0) | |
1004 fio_flags = get_win_fio_flags(fenc); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1005 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1006 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1007 #ifdef MACOS_CONVERT |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1008 // Conversion from Apple MacRoman to latin1 or UTF-8 |
7 | 1009 if (fio_flags == 0) |
1010 fio_flags = get_mac_fio_flags(fenc); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1011 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1012 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1013 #ifdef USE_ICONV |
7 | 1014 /* |
1015 * Try using iconv() if we can't convert internally. | |
1016 */ | |
1017 if (fio_flags == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1018 # ifdef FEAT_EVAL |
7 | 1019 && !did_iconv |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1020 # endif |
7 | 1021 ) |
1022 iconv_fd = (iconv_t)my_iconv_open( | |
1023 enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1024 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1025 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1026 #ifdef FEAT_EVAL |
7 | 1027 /* |
1028 * Use the 'charconvert' expression when conversion is required | |
1029 * and we can't do it internally or with iconv(). | |
1030 */ | |
1031 if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
1032 && !read_fifo |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1033 # ifdef USE_ICONV |
7 | 1034 && iconv_fd == (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1035 # endif |
7 | 1036 ) |
1037 { | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1038 # ifdef USE_ICONV |
7 | 1039 did_iconv = FALSE; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1040 # endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1041 // Skip conversion when it's already done (retry for wrong |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1042 // "fileformat"). |
7 | 1043 if (tmpname == NULL) |
1044 { | |
1045 tmpname = readfile_charconvert(fname, fenc, &fd); | |
1046 if (tmpname == NULL) | |
1047 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1048 // Conversion failed. Try another one. |
7 | 1049 advance_fenc = TRUE; |
1050 if (fd < 0) | |
1051 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1052 // Re-opening the original file failed! |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
1053 emsg(_("E202: Conversion made file unreadable!")); |
7 | 1054 error = TRUE; |
1055 goto failed; | |
1056 } | |
1057 goto retry; | |
1058 } | |
1059 } | |
1060 } | |
1061 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1062 #endif |
7 | 1063 { |
1064 if (fio_flags == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1065 #ifdef USE_ICONV |
7 | 1066 && iconv_fd == (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1067 #endif |
7 | 1068 ) |
1069 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1070 // Conversion wanted but we can't. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1071 // Try the next conversion in 'fileencodings' |
7 | 1072 advance_fenc = TRUE; |
1073 goto retry; | |
1074 } | |
1075 } | |
1076 } | |
1077 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1078 // Set "can_retry" when it's possible to rewind the file and try with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1079 // another "fenc" value. It's FALSE when no other "fenc" to try, reading |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1080 // stdin or fixed at a specific encoding. |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
1081 can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc); |
7 | 1082 |
1083 if (!skip_read) | |
1084 { | |
1085 linerest = 0; | |
1086 filesize = 0; | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1087 filesize_count = 0; |
7 | 1088 skip_count = lines_to_skip; |
1089 read_count = lines_to_read; | |
1090 conv_restlen = 0; | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1091 #ifdef FEAT_PERSISTENT_UNDO |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1092 read_undo_file = (newfile && (flags & READ_KEEP_UNDO) == 0 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1093 && curbuf->b_ffname != NULL |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1094 && curbuf->b_p_udf |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1095 && !filtering |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
1096 && !read_fifo |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1097 && !read_stdin |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1098 && !read_buffer); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1099 if (read_undo_file) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1100 sha256_start(&sha_ctx); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1101 #endif |
6122 | 1102 #ifdef FEAT_CRYPT |
1103 if (curbuf->b_cryptstate != NULL) | |
1104 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1105 // Need to free the state, but keep the key, don't want to ask for |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1106 // it again. |
6122 | 1107 crypt_free_state(curbuf->b_cryptstate); |
1108 curbuf->b_cryptstate = NULL; | |
1109 } | |
1110 #endif | |
7 | 1111 } |
1112 | |
1113 while (!error && !got_int) | |
1114 { | |
1115 /* | |
1116 * We allocate as much space for the file as we can get, plus | |
1117 * space for the old line plus room for one terminating NUL. | |
1118 * The amount is limited by the fact that read() only can read | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
1119 * up to max_unsigned characters (and other things). |
7 | 1120 */ |
13804
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1121 if (!skip_read) |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1122 { |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1123 #if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1124 size = SSIZE_MAX; // use max I/O size, 52K |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1125 #else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1126 // Use buffer >= 64K. Add linerest to double the size if the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1127 // line gets very long, to avoid a lot of copying. But don't |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1128 // read more than 1 Mbyte at a time, so we can be interrupted. |
13804
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1129 size = 0x10000L + linerest; |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1130 if (size > 0x100000L) |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1131 size = 0x100000L; |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1132 #endif |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1133 } |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1134 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1135 // Protect against the argument of lalloc() going negative. |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1136 if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL) |
7 | 1137 { |
1138 ++split; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1139 *ptr = NL; // split line by inserting a NL |
7 | 1140 size = 1; |
1141 } | |
1142 else | |
1143 { | |
1144 if (!skip_read) | |
1145 { | |
836 | 1146 for ( ; size >= 10; size = (long)((long_u)size >> 1)) |
7 | 1147 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16766
diff
changeset
|
1148 if ((new_buffer = lalloc(size + linerest + 1, |
7 | 1149 FALSE)) != NULL) |
1150 break; | |
1151 } | |
1152 if (new_buffer == NULL) | |
1153 { | |
1154 do_outofmem_msg((long_u)(size * 2 + linerest + 1)); | |
1155 error = TRUE; | |
1156 break; | |
1157 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1158 if (linerest) // copy characters from the previous buffer |
7 | 1159 mch_memmove(new_buffer, ptr - linerest, (size_t)linerest); |
1160 vim_free(buffer); | |
1161 buffer = new_buffer; | |
1162 ptr = buffer + linerest; | |
1163 line_start = buffer; | |
1164 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1165 // May need room to translate into. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1166 // For iconv() we don't really know the required space, use a |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1167 // factor ICONV_MULT. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1168 // latin1 to utf-8: 1 byte becomes up to 2 bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1169 // utf-16 to utf-8: 2 bytes become up to 3 bytes, 4 bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1170 // become up to 4 bytes, size must be multiple of 2 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1171 // ucs-2 to utf-8: 2 bytes become up to 3 bytes, size must be |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1172 // multiple of 2 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1173 // ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1174 // multiple of 4 |
835 | 1175 real_size = (int)size; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1176 #ifdef USE_ICONV |
7 | 1177 if (iconv_fd != (iconv_t)-1) |
1178 size = size / ICONV_MULT; | |
1179 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1180 #endif |
7 | 1181 if (fio_flags & FIO_LATIN1) |
1182 size = size / 2; | |
1183 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1184 size = (size * 2 / 3) & ~1; | |
1185 else if (fio_flags & FIO_UCS4) | |
1186 size = (size * 2 / 3) & ~3; | |
1187 else if (fio_flags == FIO_UCSBOM) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1188 size = size / ICONV_MULT; // worst case |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
1189 #ifdef MSWIN |
7 | 1190 else if (fio_flags & FIO_CODEPAGE) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1191 size = size / ICONV_MULT; // also worst case |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1192 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1193 #ifdef MACOS_CONVERT |
7 | 1194 else if (fio_flags & FIO_MACROMAN) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1195 size = size / ICONV_MULT; // also worst case |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1196 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1197 |
7 | 1198 if (conv_restlen > 0) |
1199 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1200 // Insert unconverted bytes from previous line. |
7 | 1201 mch_memmove(ptr, conv_rest, conv_restlen); |
1202 ptr += conv_restlen; | |
1203 size -= conv_restlen; | |
1204 } | |
1205 | |
1206 if (read_buffer) | |
1207 { | |
1208 /* | |
1209 * Read bytes from curbuf. Used for converting text read | |
1210 * from stdin. | |
1211 */ | |
24990
85d1e82ed134
patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents:
24970
diff
changeset
|
1212 eof = FALSE; |
7 | 1213 if (read_buf_lnum > from) |
1214 size = 0; | |
1215 else | |
1216 { | |
1217 int n, ni; | |
1218 long tlen; | |
1219 | |
1220 tlen = 0; | |
1221 for (;;) | |
1222 { | |
1223 p = ml_get(read_buf_lnum) + read_buf_col; | |
1224 n = (int)STRLEN(p); | |
1225 if ((int)tlen + n + 1 > size) | |
1226 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1227 // Filled up to "size", append partial line. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1228 // Change NL to NUL to reverse the effect done |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1229 // below. |
835 | 1230 n = (int)(size - tlen); |
7 | 1231 for (ni = 0; ni < n; ++ni) |
1232 { | |
1233 if (p[ni] == NL) | |
1234 ptr[tlen++] = NUL; | |
1235 else | |
1236 ptr[tlen++] = p[ni]; | |
1237 } | |
1238 read_buf_col += n; | |
1239 break; | |
1240 } | |
1241 else | |
1242 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1243 // Append whole line and new-line. Change NL |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1244 // to NUL to reverse the effect done below. |
7 | 1245 for (ni = 0; ni < n; ++ni) |
1246 { | |
1247 if (p[ni] == NL) | |
1248 ptr[tlen++] = NUL; | |
1249 else | |
1250 ptr[tlen++] = p[ni]; | |
1251 } | |
1252 ptr[tlen++] = NL; | |
1253 read_buf_col = 0; | |
1254 if (++read_buf_lnum > from) | |
1255 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1256 // When the last line didn't have an |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1257 // end-of-line don't add it now either. |
7 | 1258 if (!curbuf->b_p_eol) |
1259 --tlen; | |
1260 size = tlen; | |
24990
85d1e82ed134
patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents:
24970
diff
changeset
|
1261 eof = TRUE; |
7 | 1262 break; |
1263 } | |
1264 } | |
1265 } | |
1266 } | |
1267 } | |
1268 else | |
1269 { | |
1270 /* | |
1271 * Read bytes from the file. | |
1272 */ | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1273 # ifdef FEAT_SODIUM |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1274 // Let the crypt layer work with a buffer size of 8192 |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1275 if (filesize == 0) |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1276 // set size to 8K + Sodium Crypt Metadata |
24990
85d1e82ed134
patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents:
24970
diff
changeset
|
1277 size = WRITEBUFSIZE + crypt_get_max_header_len() |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1278 + crypto_secretstream_xchacha20poly1305_HEADERBYTES |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1279 + crypto_secretstream_xchacha20poly1305_ABYTES; |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1280 |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1281 else if (filesize > 0 && (curbuf->b_cryptstate != NULL && |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1282 curbuf->b_cryptstate->method_nr == CRYPT_M_SOD)) |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1283 size = WRITEBUFSIZE + crypto_secretstream_xchacha20poly1305_ABYTES; |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1284 # endif |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1285 eof = size; |
2664 | 1286 size = read_eintr(fd, ptr, size); |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1287 filesize_count += size; |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1288 // hit end of file |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1289 eof = (size < eof || filesize_count == filesize_disk); |
7 | 1290 } |
1291 | |
6122 | 1292 #ifdef FEAT_CRYPT |
1293 /* | |
1294 * At start of file: Check for magic number of encryption. | |
1295 */ | |
1296 if (filesize == 0 && size > 0) | |
25052
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1297 { |
6122 | 1298 cryptkey = check_for_cryptkey(cryptkey, ptr, &size, |
1299 &filesize, newfile, sfname, | |
1300 &did_ask_for_key); | |
25052
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1301 # ifdef CRYPT_NOT_INPLACE |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1302 if (curbuf->b_cryptstate != NULL |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1303 && !crypt_works_inplace(curbuf->b_cryptstate)) |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1304 // reading undo file requires crypt_decode_inplace() |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1305 read_undo_file = FALSE; |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1306 # endif |
965d97f8208b
patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents:
24990
diff
changeset
|
1307 } |
6122 | 1308 /* |
1309 * Decrypt the read bytes. This is done before checking for | |
1310 * EOF because the crypt layer may be buffering. | |
1311 */ | |
12216
e971ef6c0dee
patch 8.0.0988: warning from Covscan about using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
12064
diff
changeset
|
1312 if (cryptkey != NULL && curbuf->b_cryptstate != NULL |
e971ef6c0dee
patch 8.0.0988: warning from Covscan about using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
12064
diff
changeset
|
1313 && size > 0) |
6122 | 1314 { |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1315 # ifdef CRYPT_NOT_INPLACE |
6122 | 1316 if (crypt_works_inplace(curbuf->b_cryptstate)) |
1317 { | |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1318 # endif |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1319 crypt_decode_inplace(curbuf->b_cryptstate, ptr, |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1320 size, eof); |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1321 # ifdef CRYPT_NOT_INPLACE |
6122 | 1322 } |
1323 else | |
1324 { | |
1325 char_u *newptr = NULL; | |
1326 int decrypted_size; | |
1327 | |
1328 decrypted_size = crypt_decode_alloc( | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1329 curbuf->b_cryptstate, ptr, size, |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1330 &newptr, eof); |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1331 |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1332 if (decrypted_size < 0) |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1333 { |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1334 // error message already given |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1335 error = TRUE; |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1336 vim_free(newptr); |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1337 break; |
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1338 } |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1339 // If the crypt layer is buffering, not producing |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1340 // anything yet, need to read more. |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13752
diff
changeset
|
1341 if (decrypted_size == 0) |
6122 | 1342 continue; |
1343 | |
1344 if (linerest == 0) | |
1345 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1346 // Simple case: reuse returned buffer (may be |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1347 // NULL, checked later). |
6122 | 1348 new_buffer = newptr; |
1349 } | |
1350 else | |
1351 { | |
1352 long_u new_size; | |
1353 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1354 // Need new buffer to add bytes carried over. |
6122 | 1355 new_size = (long_u)(decrypted_size + linerest + 1); |
1356 new_buffer = lalloc(new_size, FALSE); | |
1357 if (new_buffer == NULL) | |
1358 { | |
1359 do_outofmem_msg(new_size); | |
1360 error = TRUE; | |
1361 break; | |
1362 } | |
1363 | |
1364 mch_memmove(new_buffer, buffer, linerest); | |
1365 if (newptr != NULL) | |
1366 mch_memmove(new_buffer + linerest, newptr, | |
1367 decrypted_size); | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1368 vim_free(newptr); |
6122 | 1369 } |
1370 | |
1371 if (new_buffer != NULL) | |
1372 { | |
1373 vim_free(buffer); | |
1374 buffer = new_buffer; | |
1375 new_buffer = NULL; | |
1376 line_start = buffer; | |
1377 ptr = buffer + linerest; | |
24970
7e9e53a0368f
patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1378 real_size = size; |
6122 | 1379 } |
1380 size = decrypted_size; | |
1381 } | |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1382 # endif |
6122 | 1383 } |
1384 #endif | |
1385 | |
7 | 1386 if (size <= 0) |
1387 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1388 if (size < 0) // read error |
7 | 1389 error = TRUE; |
1390 else if (conv_restlen > 0) | |
595 | 1391 { |
1597 | 1392 /* |
1393 * Reached end-of-file but some trailing bytes could | |
1394 * not be converted. Truncated file? | |
1395 */ | |
1396 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1397 // When we did a conversion report an error. |
1597 | 1398 if (fio_flags != 0 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1399 #ifdef USE_ICONV |
1597 | 1400 || iconv_fd != (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1401 #endif |
1597 | 1402 ) |
1403 { | |
4331 | 1404 if (can_retry) |
1405 goto rewind_retry; | |
1597 | 1406 if (conv_error == 0) |
1407 conv_error = curbuf->b_ml.ml_line_count | |
1408 - linecnt + 1; | |
1409 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1410 // Remember the first linenr with an illegal byte |
1597 | 1411 else if (illegal_byte == 0) |
1412 illegal_byte = curbuf->b_ml.ml_line_count | |
1413 - linecnt + 1; | |
1414 if (bad_char_behavior == BAD_DROP) | |
595 | 1415 { |
1597 | 1416 *(ptr - conv_restlen) = NUL; |
1417 conv_restlen = 0; | |
1418 } | |
1419 else | |
1420 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1421 // Replace the trailing bytes with the replacement |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1422 // character if we were converting; if we weren't, |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1423 // leave the UTF8 checking code to do it, as it |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1424 // works slightly differently. |
1597 | 1425 if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1426 #ifdef USE_ICONV |
1597 | 1427 || iconv_fd != (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1428 #endif |
1597 | 1429 )) |
1430 { | |
1431 while (conv_restlen > 0) | |
1432 { | |
1433 *(--ptr) = bad_char_behavior; | |
1434 --conv_restlen; | |
1435 } | |
1436 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1437 fio_flags = 0; // don't convert this |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1438 #ifdef USE_ICONV |
834 | 1439 if (iconv_fd != (iconv_t)-1) |
1440 { | |
1441 iconv_close(iconv_fd); | |
1442 iconv_fd = (iconv_t)-1; | |
1443 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1444 #endif |
595 | 1445 } |
1446 } | |
7 | 1447 } |
1448 } | |
1449 skip_read = FALSE; | |
1450 | |
1451 /* | |
1452 * At start of file (or after crypt magic number): Check for BOM. | |
1453 * Also check for a BOM for other Unicode encodings, but not after | |
1454 * converting with 'charconvert' or when a BOM has already been | |
1455 * found. | |
1456 */ | |
1457 if ((filesize == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1458 #ifdef FEAT_CRYPT |
6122 | 1459 || (cryptkey != NULL |
1460 && filesize == crypt_get_header_len( | |
1461 crypt_get_method_nr(curbuf))) | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1462 #endif |
7 | 1463 ) |
1464 && (fio_flags == FIO_UCSBOM | |
1465 || (!curbuf->b_p_bomb | |
1466 && tmpname == NULL | |
1467 && (*fenc == 'u' || (*fenc == NUL && enc_utf8))))) | |
1468 { | |
1469 char_u *ccname; | |
1470 int blen; | |
1471 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1472 // no BOM detection in a short file or in binary mode |
7 | 1473 if (size < 2 || curbuf->b_p_bin) |
1474 ccname = NULL; | |
1475 else | |
1476 ccname = check_for_bom(ptr, size, &blen, | |
1477 fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); | |
1478 if (ccname != NULL) | |
1479 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1480 // Remove BOM from the text |
7 | 1481 filesize += blen; |
1482 size -= blen; | |
1483 mch_memmove(ptr, ptr + blen, (size_t)size); | |
819 | 1484 if (set_options) |
1352 | 1485 { |
7 | 1486 curbuf->b_p_bomb = TRUE; |
1352 | 1487 curbuf->b_start_bomb = TRUE; |
1488 } | |
7 | 1489 } |
1490 | |
1491 if (fio_flags == FIO_UCSBOM) | |
1492 { | |
1493 if (ccname == NULL) | |
1494 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1495 // No BOM detected: retry with next encoding. |
7 | 1496 advance_fenc = TRUE; |
1497 } | |
1498 else | |
1499 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1500 // BOM detected: set "fenc" and jump back |
7 | 1501 if (fenc_alloced) |
1502 vim_free(fenc); | |
1503 fenc = ccname; | |
1504 fenc_alloced = FALSE; | |
1505 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1506 // retry reading without getting new bytes or rewinding |
7 | 1507 skip_read = TRUE; |
1508 goto retry; | |
1509 } | |
1510 } | |
1597 | 1511 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1512 // Include not converted bytes. |
1597 | 1513 ptr -= conv_restlen; |
1514 size += conv_restlen; | |
1515 conv_restlen = 0; | |
7 | 1516 /* |
1517 * Break here for a read error or end-of-file. | |
1518 */ | |
1519 if (size <= 0) | |
1520 break; | |
1521 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1522 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1523 #ifdef USE_ICONV |
7 | 1524 if (iconv_fd != (iconv_t)-1) |
1525 { | |
1526 /* | |
1527 * Attempt conversion of the read bytes to 'encoding' using | |
1528 * iconv(). | |
1529 */ | |
1530 const char *fromp; | |
1531 char *top; | |
1532 size_t from_size; | |
1533 size_t to_size; | |
1534 | |
1535 fromp = (char *)ptr; | |
1536 from_size = size; | |
1537 ptr += size; | |
1538 top = (char *)ptr; | |
1539 to_size = real_size - size; | |
1540 | |
1541 /* | |
1542 * If there is conversion error or not enough room try using | |
179 | 1543 * another conversion. Except for when there is no |
1544 * alternative (help files). | |
7 | 1545 */ |
177 | 1546 while ((iconv(iconv_fd, (void *)&fromp, &from_size, |
1547 &top, &to_size) | |
7 | 1548 == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) |
1549 || from_size > CONV_RESTLEN) | |
177 | 1550 { |
595 | 1551 if (can_retry) |
375 | 1552 goto rewind_retry; |
595 | 1553 if (conv_error == 0) |
1554 conv_error = readfile_linenr(linecnt, | |
1555 ptr, (char_u *)top); | |
1556 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1557 // Deal with a bad byte and continue with the next. |
177 | 1558 ++fromp; |
1559 --from_size; | |
595 | 1560 if (bad_char_behavior == BAD_KEEP) |
1561 { | |
1562 *top++ = *(fromp - 1); | |
1563 --to_size; | |
1564 } | |
1565 else if (bad_char_behavior != BAD_DROP) | |
1566 { | |
1567 *top++ = bad_char_behavior; | |
1568 --to_size; | |
1569 } | |
177 | 1570 } |
7 | 1571 |
1572 if (from_size > 0) | |
1573 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1574 // Some remaining characters, keep them for the next |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1575 // round. |
7 | 1576 mch_memmove(conv_rest, (char_u *)fromp, from_size); |
1577 conv_restlen = (int)from_size; | |
1578 } | |
1579 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1580 // move the linerest to before the converted characters |
7 | 1581 line_start = ptr - linerest; |
1582 mch_memmove(line_start, buffer, (size_t)linerest); | |
1583 size = (long)((char_u *)top - ptr); | |
1584 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1585 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1586 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
1587 #ifdef MSWIN |
7 | 1588 if (fio_flags & FIO_CODEPAGE) |
1589 { | |
595 | 1590 char_u *src, *dst; |
1591 WCHAR ucs2buf[3]; | |
1592 int ucs2len; | |
1593 int codepage = FIO_GET_CP(fio_flags); | |
1594 int bytelen; | |
1595 int found_bad; | |
1596 char replstr[2]; | |
1597 | |
7 | 1598 /* |
1599 * Conversion from an MS-Windows codepage or UTF-8 to UTF-8 or | |
595 | 1600 * a codepage, using standard MS-Windows functions. This |
1601 * requires two steps: | |
1602 * 1. convert from 'fileencoding' to ucs-2 | |
1603 * 2. convert from ucs-2 to 'encoding' | |
1604 * | |
1605 * Because there may be illegal bytes AND an incomplete byte | |
1606 * sequence at the end, we may have to do the conversion one | |
1607 * character at a time to get it right. | |
7 | 1608 */ |
595 | 1609 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1610 // Replacement string for WideCharToMultiByte(). |
595 | 1611 if (bad_char_behavior > 0) |
1612 replstr[0] = bad_char_behavior; | |
1613 else | |
1614 replstr[0] = '?'; | |
1615 replstr[1] = NUL; | |
1616 | |
1617 /* | |
1618 * Move the bytes to the end of the buffer, so that we have | |
1619 * room to put the result at the start. | |
1620 */ | |
1621 src = ptr + real_size - size; | |
1622 mch_memmove(src, ptr, size); | |
7 | 1623 |
1624 /* | |
595 | 1625 * Do the conversion. |
7 | 1626 */ |
595 | 1627 dst = ptr; |
1628 size = size; | |
1629 while (size > 0) | |
7 | 1630 { |
595 | 1631 found_bad = FALSE; |
7 | 1632 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1633 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 |
595 | 1634 if (codepage == CP_UTF8) |
7 | 1635 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1636 // Handle CP_UTF8 input ourselves to be able to handle |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1637 // trailing bytes properly. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1638 // Get one UTF-8 character from src. |
835 | 1639 bytelen = (int)utf_ptr2len_len(src, size); |
595 | 1640 if (bytelen > size) |
1641 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1642 // Only got some bytes of a character. Normally |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1643 // it's put in "conv_rest", but if it's too long |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1644 // deal with it as if they were illegal bytes. |
595 | 1645 if (bytelen <= CONV_RESTLEN) |
1646 break; | |
1647 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1648 // weird overlong byte sequence |
595 | 1649 bytelen = size; |
1650 found_bad = TRUE; | |
1651 } | |
1652 else | |
1653 { | |
799 | 1654 int u8c = utf_ptr2char(src); |
1655 | |
622 | 1656 if (u8c > 0xffff || (*src >= 0x80 && bytelen == 1)) |
595 | 1657 found_bad = TRUE; |
1658 ucs2buf[0] = u8c; | |
1659 ucs2len = 1; | |
1660 } | |
7 | 1661 } |
595 | 1662 else |
7 | 1663 # endif |
595 | 1664 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1665 // We don't know how long the byte sequence is, try |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1666 // from one to three bytes. |
595 | 1667 for (bytelen = 1; bytelen <= size && bytelen <= 3; |
1668 ++bytelen) | |
1669 { | |
1670 ucs2len = MultiByteToWideChar(codepage, | |
1671 MB_ERR_INVALID_CHARS, | |
1672 (LPCSTR)src, bytelen, | |
1673 ucs2buf, 3); | |
1674 if (ucs2len > 0) | |
1675 break; | |
1676 } | |
1677 if (ucs2len == 0) | |
1678 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1679 // If we have only one byte then it's probably an |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1680 // incomplete byte sequence. Otherwise discard |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1681 // one byte as a bad character. |
595 | 1682 if (size == 1) |
1683 break; | |
1684 found_bad = TRUE; | |
1685 bytelen = 1; | |
1686 } | |
1687 } | |
1688 | |
1689 if (!found_bad) | |
7 | 1690 { |
595 | 1691 int i; |
1692 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1693 // Convert "ucs2buf[ucs2len]" to 'enc' in "dst". |
595 | 1694 if (enc_utf8) |
1695 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1696 // From UCS-2 to UTF-8. Cannot fail. |
595 | 1697 for (i = 0; i < ucs2len; ++i) |
1698 dst += utf_char2bytes(ucs2buf[i], dst); | |
1699 } | |
1700 else | |
1701 { | |
1702 BOOL bad = FALSE; | |
1703 int dstlen; | |
1704 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1705 // From UCS-2 to "enc_codepage". If the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1706 // conversion uses the default character "?", |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1707 // the data doesn't fit in this encoding. |
595 | 1708 dstlen = WideCharToMultiByte(enc_codepage, 0, |
1709 (LPCWSTR)ucs2buf, ucs2len, | |
835 | 1710 (LPSTR)dst, (int)(src - dst), |
595 | 1711 replstr, &bad); |
1712 if (bad) | |
1713 found_bad = TRUE; | |
1714 else | |
1715 dst += dstlen; | |
1716 } | |
7 | 1717 } |
595 | 1718 |
1719 if (found_bad) | |
1720 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1721 // Deal with bytes we can't convert. |
595 | 1722 if (can_retry) |
1723 goto rewind_retry; | |
1724 if (conv_error == 0) | |
1725 conv_error = readfile_linenr(linecnt, ptr, dst); | |
1726 if (bad_char_behavior != BAD_DROP) | |
1727 { | |
1728 if (bad_char_behavior == BAD_KEEP) | |
1729 { | |
1730 mch_memmove(dst, src, bytelen); | |
1731 dst += bytelen; | |
1732 } | |
1733 else | |
1734 *dst++ = bad_char_behavior; | |
1735 } | |
1736 } | |
1737 | |
1738 src += bytelen; | |
1739 size -= bytelen; | |
7 | 1740 } |
595 | 1741 |
1742 if (size > 0) | |
7 | 1743 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1744 // An incomplete byte sequence remaining. |
595 | 1745 mch_memmove(conv_rest, src, size); |
1746 conv_restlen = size; | |
7 | 1747 } |
595 | 1748 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1749 // The new size is equal to how much "dst" was advanced. |
835 | 1750 size = (long)(dst - ptr); |
7 | 1751 } |
1752 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1753 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1754 #ifdef MACOS_CONVERT |
7 | 1755 if (fio_flags & FIO_MACROMAN) |
1756 { | |
1757 /* | |
1758 * Conversion from Apple MacRoman char encoding to UTF-8 or | |
18 | 1759 * latin1. This is in os_mac_conv.c. |
7 | 1760 */ |
18 | 1761 if (macroman2enc(ptr, &size, real_size) == FAIL) |
7 | 1762 goto rewind_retry; |
1763 } | |
1764 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1765 #endif |
7 | 1766 if (fio_flags != 0) |
1767 { | |
1768 int u8c; | |
1769 char_u *dest; | |
1770 char_u *tail = NULL; | |
1771 | |
1772 /* | |
1773 * "enc_utf8" set: Convert Unicode or Latin1 to UTF-8. | |
1774 * "enc_utf8" not set: Convert Unicode to Latin1. | |
1775 * Go from end to start through the buffer, because the number | |
1776 * of bytes may increase. | |
1777 * "dest" points to after where the UTF-8 bytes go, "p" points | |
1778 * to after the next character to convert. | |
1779 */ | |
1780 dest = ptr + real_size; | |
1781 if (fio_flags == FIO_LATIN1 || fio_flags == FIO_UTF8) | |
1782 { | |
1783 p = ptr + size; | |
1784 if (fio_flags == FIO_UTF8) | |
1785 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1786 // Check for a trailing incomplete UTF-8 sequence |
7 | 1787 tail = ptr + size - 1; |
1788 while (tail > ptr && (*tail & 0xc0) == 0x80) | |
1789 --tail; | |
1790 if (tail + utf_byte2len(*tail) <= ptr + size) | |
1791 tail = NULL; | |
1792 else | |
1793 p = tail; | |
1794 } | |
1795 } | |
1796 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1797 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1798 // Check for a trailing byte |
7 | 1799 p = ptr + (size & ~1); |
1800 if (size & 1) | |
1801 tail = p; | |
1802 if ((fio_flags & FIO_UTF16) && p > ptr) | |
1803 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1804 // Check for a trailing leading word |
7 | 1805 if (fio_flags & FIO_ENDIAN_L) |
1806 { | |
1807 u8c = (*--p << 8); | |
1808 u8c += *--p; | |
1809 } | |
1810 else | |
1811 { | |
1812 u8c = *--p; | |
1813 u8c += (*--p << 8); | |
1814 } | |
1815 if (u8c >= 0xd800 && u8c <= 0xdbff) | |
1816 tail = p; | |
1817 else | |
1818 p += 2; | |
1819 } | |
1820 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1821 else // FIO_UCS4 |
7 | 1822 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1823 // Check for trailing 1, 2 or 3 bytes |
7 | 1824 p = ptr + (size & ~3); |
1825 if (size & 3) | |
1826 tail = p; | |
1827 } | |
1828 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1829 // If there is a trailing incomplete sequence move it to |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1830 // conv_rest[]. |
7 | 1831 if (tail != NULL) |
1832 { | |
1833 conv_restlen = (int)((ptr + size) - tail); | |
1834 mch_memmove(conv_rest, (char_u *)tail, conv_restlen); | |
1835 size -= conv_restlen; | |
1836 } | |
1837 | |
1838 | |
1839 while (p > ptr) | |
1840 { | |
1841 if (fio_flags & FIO_LATIN1) | |
1842 u8c = *--p; | |
1843 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1844 { | |
1845 if (fio_flags & FIO_ENDIAN_L) | |
1846 { | |
1847 u8c = (*--p << 8); | |
1848 u8c += *--p; | |
1849 } | |
1850 else | |
1851 { | |
1852 u8c = *--p; | |
1853 u8c += (*--p << 8); | |
1854 } | |
1855 if ((fio_flags & FIO_UTF16) | |
1856 && u8c >= 0xdc00 && u8c <= 0xdfff) | |
1857 { | |
1858 int u16c; | |
1859 | |
1860 if (p == ptr) | |
1861 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1862 // Missing leading word. |
7 | 1863 if (can_retry) |
1864 goto rewind_retry; | |
595 | 1865 if (conv_error == 0) |
1866 conv_error = readfile_linenr(linecnt, | |
1867 ptr, p); | |
1868 if (bad_char_behavior == BAD_DROP) | |
1869 continue; | |
1870 if (bad_char_behavior != BAD_KEEP) | |
1871 u8c = bad_char_behavior; | |
7 | 1872 } |
1873 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1874 // found second word of double-word, get the first |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1875 // word and compute the resulting character |
7 | 1876 if (fio_flags & FIO_ENDIAN_L) |
1877 { | |
1878 u16c = (*--p << 8); | |
1879 u16c += *--p; | |
1880 } | |
1881 else | |
1882 { | |
1883 u16c = *--p; | |
1884 u16c += (*--p << 8); | |
1885 } | |
595 | 1886 u8c = 0x10000 + ((u16c & 0x3ff) << 10) |
1887 + (u8c & 0x3ff); | |
1888 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1889 // Check if the word is indeed a leading word. |
7 | 1890 if (u16c < 0xd800 || u16c > 0xdbff) |
1891 { | |
1892 if (can_retry) | |
1893 goto rewind_retry; | |
595 | 1894 if (conv_error == 0) |
1895 conv_error = readfile_linenr(linecnt, | |
1896 ptr, p); | |
1897 if (bad_char_behavior == BAD_DROP) | |
1898 continue; | |
1899 if (bad_char_behavior != BAD_KEEP) | |
1900 u8c = bad_char_behavior; | |
7 | 1901 } |
1902 } | |
1903 } | |
1904 else if (fio_flags & FIO_UCS4) | |
1905 { | |
1906 if (fio_flags & FIO_ENDIAN_L) | |
1907 { | |
12698
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1908 u8c = (unsigned)*--p << 24; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1909 u8c += (unsigned)*--p << 16; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1910 u8c += (unsigned)*--p << 8; |
7 | 1911 u8c += *--p; |
1912 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1913 else // big endian |
7 | 1914 { |
1915 u8c = *--p; | |
12698
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1916 u8c += (unsigned)*--p << 8; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1917 u8c += (unsigned)*--p << 16; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1918 u8c += (unsigned)*--p << 24; |
7 | 1919 } |
1920 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1921 else // UTF-8 |
7 | 1922 { |
1923 if (*--p < 0x80) | |
1924 u8c = *p; | |
1925 else | |
1926 { | |
1927 len = utf_head_off(ptr, p); | |
595 | 1928 p -= len; |
1929 u8c = utf_ptr2char(p); | |
7 | 1930 if (len == 0) |
1931 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1932 // Not a valid UTF-8 character, retry with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1933 // another fenc when possible, otherwise just |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1934 // report the error. |
7 | 1935 if (can_retry) |
1936 goto rewind_retry; | |
595 | 1937 if (conv_error == 0) |
1938 conv_error = readfile_linenr(linecnt, | |
1939 ptr, p); | |
1940 if (bad_char_behavior == BAD_DROP) | |
1941 continue; | |
1942 if (bad_char_behavior != BAD_KEEP) | |
1943 u8c = bad_char_behavior; | |
7 | 1944 } |
1945 } | |
1946 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1947 if (enc_utf8) // produce UTF-8 |
7 | 1948 { |
1949 dest -= utf_char2len(u8c); | |
1950 (void)utf_char2bytes(u8c, dest); | |
1951 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1952 else // produce Latin1 |
7 | 1953 { |
1954 --dest; | |
1955 if (u8c >= 0x100) | |
1956 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1957 // character doesn't fit in latin1, retry with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1958 // another fenc when possible, otherwise just |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1959 // report the error. |
595 | 1960 if (can_retry) |
7 | 1961 goto rewind_retry; |
595 | 1962 if (conv_error == 0) |
1963 conv_error = readfile_linenr(linecnt, ptr, p); | |
1964 if (bad_char_behavior == BAD_DROP) | |
1965 ++dest; | |
1966 else if (bad_char_behavior == BAD_KEEP) | |
1967 *dest = u8c; | |
1968 else if (eap != NULL && eap->bad_char != 0) | |
1969 *dest = bad_char_behavior; | |
1970 else | |
1971 *dest = 0xBF; | |
7 | 1972 } |
1973 else | |
1974 *dest = u8c; | |
1975 } | |
1976 } | |
1977 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1978 // move the linerest to before the converted characters |
7 | 1979 line_start = dest - linerest; |
1980 mch_memmove(line_start, buffer, (size_t)linerest); | |
1981 size = (long)((ptr + real_size) - dest); | |
1982 ptr = dest; | |
1983 } | |
1597 | 1984 else if (enc_utf8 && !curbuf->b_p_bin) |
1985 { | |
1986 int incomplete_tail = FALSE; | |
1987 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1988 // Reading UTF-8: Check if the bytes are valid UTF-8. |
1597 | 1989 for (p = ptr; ; ++p) |
7 | 1990 { |
835 | 1991 int todo = (int)((ptr + size) - p); |
595 | 1992 int l; |
1993 | |
1994 if (todo <= 0) | |
1995 break; | |
7 | 1996 if (*p >= 0x80) |
1997 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1998 // A length of 1 means it's an illegal byte. Accept |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1999 // an incomplete character at the end though, the next |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2000 // read() will get the next bytes, we'll check it |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2001 // then. |
595 | 2002 l = utf_ptr2len_len(p, todo); |
1597 | 2003 if (l > todo && !incomplete_tail) |
7 | 2004 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2005 // Avoid retrying with a different encoding when |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2006 // a truncated file is more likely, or attempting |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2007 // to read the rest of an incomplete sequence when |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2008 // we have already done so. |
1597 | 2009 if (p > ptr || filesize > 0) |
2010 incomplete_tail = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2011 // Incomplete byte sequence, move it to conv_rest[] |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2012 // and try to read the rest of it, unless we've |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2013 // already done so. |
1597 | 2014 if (p > ptr) |
2015 { | |
2016 conv_restlen = todo; | |
2017 mch_memmove(conv_rest, p, conv_restlen); | |
2018 size -= conv_restlen; | |
2019 break; | |
2020 } | |
7 | 2021 } |
1597 | 2022 if (l == 1 || l > todo) |
595 | 2023 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2024 // Illegal byte. If we can try another encoding |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2025 // do that, unless at EOF where a truncated |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2026 // file is more likely than a conversion error. |
1597 | 2027 if (can_retry && !incomplete_tail) |
595 | 2028 break; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2029 #ifdef USE_ICONV |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2030 // When we did a conversion report an error. |
595 | 2031 if (iconv_fd != (iconv_t)-1 && conv_error == 0) |
2032 conv_error = readfile_linenr(linecnt, ptr, p); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2033 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2034 // Remember the first linenr with an illegal byte |
1597 | 2035 if (conv_error == 0 && illegal_byte == 0) |
2036 illegal_byte = readfile_linenr(linecnt, ptr, p); | |
595 | 2037 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2038 // Drop, keep or replace the bad byte. |
595 | 2039 if (bad_char_behavior == BAD_DROP) |
2040 { | |
1597 | 2041 mch_memmove(p, p + 1, todo - 1); |
595 | 2042 --p; |
2043 --size; | |
2044 } | |
2045 else if (bad_char_behavior != BAD_KEEP) | |
2046 *p = bad_char_behavior; | |
2047 } | |
1597 | 2048 else |
2049 p += l - 1; | |
7 | 2050 } |
2051 } | |
1597 | 2052 if (p < ptr + size && !incomplete_tail) |
7 | 2053 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2054 // Detected a UTF-8 error. |
7 | 2055 rewind_retry: |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2056 // Retry reading with another conversion. |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2057 #if defined(FEAT_EVAL) && defined(USE_ICONV) |
595 | 2058 if (*p_ccv != NUL && iconv_fd != (iconv_t)-1) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2059 // iconv() failed, try 'charconvert' |
595 | 2060 did_iconv = TRUE; |
7 | 2061 else |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2062 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2063 // use next item from 'fileencodings' |
595 | 2064 advance_fenc = TRUE; |
2065 file_rewind = TRUE; | |
2066 goto retry; | |
7 | 2067 } |
2068 } | |
2069 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2070 // count the number of characters (after conversion!) |
7 | 2071 filesize += size; |
2072 | |
2073 /* | |
2074 * when reading the first part of a file: guess EOL type | |
2075 */ | |
2076 if (fileformat == EOL_UNKNOWN) | |
2077 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2078 // First try finding a NL, for Dos and Unix |
7 | 2079 if (try_dos || try_unix) |
2080 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2081 // Reset the carriage return counter. |
6635 | 2082 if (try_mac) |
2083 try_mac = 1; | |
2084 | |
7 | 2085 for (p = ptr; p < ptr + size; ++p) |
2086 { | |
2087 if (*p == NL) | |
2088 { | |
2089 if (!try_unix | |
2090 || (try_dos && p > ptr && p[-1] == CAR)) | |
2091 fileformat = EOL_DOS; | |
2092 else | |
2093 fileformat = EOL_UNIX; | |
2094 break; | |
2095 } | |
6618 | 2096 else if (*p == CAR && try_mac) |
2097 try_mac++; | |
7 | 2098 } |
2099 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2100 // Don't give in to EOL_UNIX if EOL_MAC is more likely |
7 | 2101 if (fileformat == EOL_UNIX && try_mac) |
2102 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2103 // Need to reset the counters when retrying fenc. |
7 | 2104 try_mac = 1; |
2105 try_unix = 1; | |
2106 for (; p >= ptr && *p != CAR; p--) | |
2107 ; | |
2108 if (p >= ptr) | |
2109 { | |
2110 for (p = ptr; p < ptr + size; ++p) | |
2111 { | |
2112 if (*p == NL) | |
2113 try_unix++; | |
2114 else if (*p == CAR) | |
2115 try_mac++; | |
2116 } | |
2117 if (try_mac > try_unix) | |
2118 fileformat = EOL_MAC; | |
2119 } | |
2120 } | |
6618 | 2121 else if (fileformat == EOL_UNKNOWN && try_mac == 1) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2122 // Looking for CR but found no end-of-line markers at |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2123 // all: use the default format. |
6618 | 2124 fileformat = default_fileformat(); |
7 | 2125 } |
2126 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2127 // No NL found: may use Mac format |
7 | 2128 if (fileformat == EOL_UNKNOWN && try_mac) |
2129 fileformat = EOL_MAC; | |
2130 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2131 // Still nothing found? Use first format in 'ffs' |
7 | 2132 if (fileformat == EOL_UNKNOWN) |
2133 fileformat = default_fileformat(); | |
2134 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2135 // if editing a new file: may set p_tx and p_ff |
819 | 2136 if (set_options) |
7 | 2137 set_fileformat(fileformat, OPT_LOCAL); |
2138 } | |
2139 } | |
2140 | |
2141 /* | |
2142 * This loop is executed once for every character read. | |
2143 * Keep it fast! | |
2144 */ | |
2145 if (fileformat == EOL_MAC) | |
2146 { | |
2147 --ptr; | |
2148 while (++ptr, --size >= 0) | |
2149 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2150 // catch most common case first |
7 | 2151 if ((c = *ptr) != NUL && c != CAR && c != NL) |
2152 continue; | |
2153 if (c == NUL) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2154 *ptr = NL; // NULs are replaced by newlines! |
7 | 2155 else if (c == NL) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2156 *ptr = CAR; // NLs are replaced by CRs! |
7 | 2157 else |
2158 { | |
2159 if (skip_count == 0) | |
2160 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2161 *ptr = NUL; // end of line |
7 | 2162 len = (colnr_T) (ptr - line_start + 1); |
2163 if (ml_append(lnum, line_start, len, newfile) == FAIL) | |
2164 { | |
2165 error = TRUE; | |
2166 break; | |
2167 } | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2168 #ifdef FEAT_PERSISTENT_UNDO |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2169 if (read_undo_file) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2170 sha256_update(&sha_ctx, line_start, len); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2171 #endif |
7 | 2172 ++lnum; |
2173 if (--read_count == 0) | |
2174 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2175 error = TRUE; // break loop |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2176 line_start = ptr; // nothing left to write |
7 | 2177 break; |
2178 } | |
2179 } | |
2180 else | |
2181 --skip_count; | |
2182 line_start = ptr + 1; | |
2183 } | |
2184 } | |
2185 } | |
2186 else | |
2187 { | |
2188 --ptr; | |
2189 while (++ptr, --size >= 0) | |
2190 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2191 if ((c = *ptr) != NUL && c != NL) // catch most common case |
7 | 2192 continue; |
2193 if (c == NUL) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2194 *ptr = NL; // NULs are replaced by newlines! |
7 | 2195 else |
2196 { | |
2197 if (skip_count == 0) | |
2198 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2199 *ptr = NUL; // end of line |
7 | 2200 len = (colnr_T)(ptr - line_start + 1); |
2201 if (fileformat == EOL_DOS) | |
2202 { | |
10674
d6857a8dc07e
patch 8.0.0227: crash with ff=dos when first line in file has no CR
Christian Brabandt <cb@256bit.org>
parents:
10668
diff
changeset
|
2203 if (ptr > line_start && ptr[-1] == CAR) |
7 | 2204 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2205 // remove CR before NL |
7 | 2206 ptr[-1] = NUL; |
2207 --len; | |
2208 } | |
2209 /* | |
2210 * Reading in Dos format, but no CR-LF found! | |
2211 * When 'fileformats' includes "unix", delete all | |
2212 * the lines read so far and start all over again. | |
2213 * Otherwise give an error message later. | |
2214 */ | |
2215 else if (ff_error != EOL_DOS) | |
2216 { | |
2217 if ( try_unix | |
2218 && !read_stdin | |
2219 && (read_buffer | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
2220 || vim_lseek(fd, (off_T)0L, SEEK_SET) |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
2221 == 0)) |
7 | 2222 { |
2223 fileformat = EOL_UNIX; | |
819 | 2224 if (set_options) |
7 | 2225 set_fileformat(EOL_UNIX, OPT_LOCAL); |
2226 file_rewind = TRUE; | |
2227 keep_fileformat = TRUE; | |
2228 goto retry; | |
2229 } | |
2230 ff_error = EOL_DOS; | |
2231 } | |
2232 } | |
2233 if (ml_append(lnum, line_start, len, newfile) == FAIL) | |
2234 { | |
2235 error = TRUE; | |
2236 break; | |
2237 } | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2238 #ifdef FEAT_PERSISTENT_UNDO |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2239 if (read_undo_file) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2240 sha256_update(&sha_ctx, line_start, len); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2241 #endif |
7 | 2242 ++lnum; |
2243 if (--read_count == 0) | |
2244 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2245 error = TRUE; // break loop |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2246 line_start = ptr; // nothing left to write |
7 | 2247 break; |
2248 } | |
2249 } | |
2250 else | |
2251 --skip_count; | |
2252 line_start = ptr + 1; | |
2253 } | |
2254 } | |
2255 } | |
2256 linerest = (long)(ptr - line_start); | |
2257 ui_breakcheck(); | |
2258 } | |
2259 | |
2260 failed: | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2261 // not an error, max. number of lines reached |
7 | 2262 if (error && read_count == 0) |
2263 error = FALSE; | |
2264 | |
2265 /* | |
2266 * If we get EOF in the middle of a line, note the fact and | |
2267 * complete the line ourselves. | |
2268 * In Dos format ignore a trailing CTRL-Z, unless 'binary' set. | |
2269 */ | |
2270 if (!error | |
2271 && !got_int | |
2272 && linerest != 0 | |
2273 && !(!curbuf->b_p_bin | |
2274 && fileformat == EOL_DOS | |
2275 && *line_start == Ctrl_Z | |
2276 && ptr == line_start + 1)) | |
2277 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2278 // remember for when writing |
819 | 2279 if (set_options) |
7 | 2280 curbuf->b_p_eol = FALSE; |
2281 *ptr = NUL; | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2282 len = (colnr_T)(ptr - line_start + 1); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2283 if (ml_append(lnum, line_start, len, newfile) == FAIL) |
7 | 2284 error = TRUE; |
2285 else | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2286 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2287 #ifdef FEAT_PERSISTENT_UNDO |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2288 if (read_undo_file) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2289 sha256_update(&sha_ctx, line_start, len); |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2290 #endif |
7 | 2291 read_no_eol_lnum = ++lnum; |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2292 } |
7 | 2293 } |
2294 | |
819 | 2295 if (set_options) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2296 save_file_ff(curbuf); // remember the current file format |
7 | 2297 |
2298 #ifdef FEAT_CRYPT | |
6122 | 2299 if (curbuf->b_cryptstate != NULL) |
2300 { | |
2301 crypt_free_state(curbuf->b_cryptstate); | |
2302 curbuf->b_cryptstate = NULL; | |
2303 } | |
2304 if (cryptkey != NULL && cryptkey != curbuf->b_p_key) | |
2305 crypt_free_key(cryptkey); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2306 // Don't set cryptkey to NULL, it's used below as a flag that |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2307 // encryption was used. |
7 | 2308 #endif |
2309 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2310 // If editing a new file: set 'fenc' for the current buffer. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2311 // Also for ":read ++edit file". |
819 | 2312 if (set_options) |
7 | 2313 set_string_option_direct((char_u *)"fenc", -1, fenc, |
694 | 2314 OPT_FREE|OPT_LOCAL, 0); |
7 | 2315 if (fenc_alloced) |
2316 vim_free(fenc); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2317 #ifdef USE_ICONV |
7 | 2318 if (iconv_fd != (iconv_t)-1) |
2319 iconv_close(iconv_fd); | |
2320 #endif | |
2321 | |
2322 if (!read_buffer && !read_stdin) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2323 close(fd); // errors are ignored |
2003 | 2324 #ifdef HAVE_FD_CLOEXEC |
2325 else | |
2326 { | |
2327 int fdflags = fcntl(fd, F_GETFD); | |
23467
826a6406ea7b
patch 8.2.2276: list of distributed files is outdated
Bram Moolenaar <Bram@vim.org>
parents:
23017
diff
changeset
|
2328 |
2003 | 2329 if (fdflags >= 0 && (fdflags & FD_CLOEXEC) == 0) |
7961
a7e58c6e4e9a
commit https://github.com/vim/vim/commit/fbc4b4db3a9690906a96e16724350a6241cf32a5
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
2330 (void)fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); |
2003 | 2331 } |
2332 #endif | |
7 | 2333 vim_free(buffer); |
2334 | |
2335 #ifdef HAVE_DUP | |
2336 if (read_stdin) | |
2337 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2338 // Use stderr for stdin, makes shell commands work. |
7 | 2339 close(0); |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
2340 vim_ignored = dup(2); |
7 | 2341 } |
2342 #endif | |
2343 | |
2344 if (tmpname != NULL) | |
2345 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2346 mch_remove(tmpname); // delete converted file |
7 | 2347 vim_free(tmpname); |
2348 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2349 --no_wait_return; // may wait for return now |
7 | 2350 |
2351 /* | |
2352 * In recovery mode everything but autocommands is skipped. | |
2353 */ | |
2354 if (!recoverymode) | |
2355 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2356 // need to delete the last line, which comes from the empty buffer |
7 | 2357 if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) |
2358 { | |
2359 #ifdef FEAT_NETBEANS_INTG | |
2360 netbeansFireChanges = 0; | |
2361 #endif | |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20311
diff
changeset
|
2362 ml_delete(curbuf->b_ml.ml_line_count); |
7 | 2363 #ifdef FEAT_NETBEANS_INTG |
2364 netbeansFireChanges = 1; | |
2365 #endif | |
2366 --linecnt; | |
2367 } | |
2368 linecnt = curbuf->b_ml.ml_line_count - linecnt; | |
2369 if (filesize == 0) | |
2370 linecnt = 0; | |
2371 if (newfile || read_buffer) | |
1201 | 2372 { |
7 | 2373 redraw_curbuf_later(NOT_VALID); |
1201 | 2374 #ifdef FEAT_DIFF |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2375 // After reading the text into the buffer the diff info needs to |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2376 // be updated. |
1201 | 2377 diff_invalidate(curbuf); |
2378 #endif | |
2379 #ifdef FEAT_FOLDING | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2380 // All folds in the window are invalid now. Mark them for update |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2381 // before triggering autocommands. |
1201 | 2382 foldUpdateAll(curwin); |
2383 #endif | |
2384 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2385 else if (linecnt) // appended at least one line |
7 | 2386 appended_lines_mark(from, linecnt); |
2387 | |
2388 #ifndef ALWAYS_USE_GUI | |
2389 /* | |
2390 * If we were reading from the same terminal as where messages go, | |
2391 * the screen will have been messed up. | |
2392 * Switch on raw mode now and clear the screen. | |
2393 */ | |
2394 if (read_stdin) | |
2395 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2396 settmode(TMODE_RAW); // set to raw mode |
7 | 2397 starttermcap(); |
2398 screenclear(); | |
2399 } | |
2400 #endif | |
2401 | |
2402 if (got_int) | |
2403 { | |
2404 if (!(flags & READ_DUMMY)) | |
2405 { | |
2406 filemess(curbuf, sfname, (char_u *)_(e_interr), 0); | |
2407 if (newfile) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2408 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 2409 } |
2410 msg_scroll = msg_save; | |
2411 #ifdef FEAT_VIMINFO | |
2412 check_marks_read(); | |
2413 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2414 return OK; // an interrupt isn't really an error |
7 | 2415 } |
2416 | |
2417 if (!filtering && !(flags & READ_DUMMY)) | |
2418 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2419 msg_add_fname(curbuf, sfname); // fname in IObuff with quotes |
7 | 2420 c = FALSE; |
2421 | |
2422 #ifdef UNIX | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2423 if (S_ISFIFO(perm)) // fifo |
7 | 2424 { |
2425 STRCAT(IObuff, _("[fifo]")); | |
2426 c = TRUE; | |
2427 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2428 if (S_ISSOCK(perm)) // or socket |
7 | 2429 { |
2430 STRCAT(IObuff, _("[socket]")); | |
2431 c = TRUE; | |
2432 } | |
1313 | 2433 # ifdef OPEN_CHR_FILES |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2434 if (S_ISCHR(perm)) // or character special |
1313 | 2435 { |
2436 STRCAT(IObuff, _("[character special]")); | |
2437 c = TRUE; | |
2438 } | |
2439 # endif | |
7 | 2440 #endif |
2441 if (curbuf->b_p_ro) | |
2442 { | |
2443 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]")); | |
2444 c = TRUE; | |
2445 } | |
2446 if (read_no_eol_lnum) | |
2447 { | |
2448 msg_add_eol(); | |
2449 c = TRUE; | |
2450 } | |
2451 if (ff_error == EOL_DOS) | |
2452 { | |
2453 STRCAT(IObuff, _("[CR missing]")); | |
2454 c = TRUE; | |
2455 } | |
2456 if (split) | |
2457 { | |
2458 STRCAT(IObuff, _("[long lines split]")); | |
2459 c = TRUE; | |
2460 } | |
2461 if (notconverted) | |
2462 { | |
2463 STRCAT(IObuff, _("[NOT converted]")); | |
2464 c = TRUE; | |
2465 } | |
2466 else if (converted) | |
2467 { | |
2468 STRCAT(IObuff, _("[converted]")); | |
2469 c = TRUE; | |
2470 } | |
2471 #ifdef FEAT_CRYPT | |
2472 if (cryptkey != NULL) | |
2473 { | |
6122 | 2474 crypt_append_msg(curbuf); |
7 | 2475 c = TRUE; |
2476 } | |
2477 #endif | |
595 | 2478 if (conv_error != 0) |
2479 { | |
2480 sprintf((char *)IObuff + STRLEN(IObuff), | |
2481 _("[CONVERSION ERROR in line %ld]"), (long)conv_error); | |
7 | 2482 c = TRUE; |
2483 } | |
2484 else if (illegal_byte > 0) | |
2485 { | |
2486 sprintf((char *)IObuff + STRLEN(IObuff), | |
2487 _("[ILLEGAL BYTE in line %ld]"), (long)illegal_byte); | |
2488 c = TRUE; | |
2489 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2490 else if (error) |
7 | 2491 { |
2492 STRCAT(IObuff, _("[READ ERRORS]")); | |
2493 c = TRUE; | |
2494 } | |
2495 if (msg_add_fileformat(fileformat)) | |
2496 c = TRUE; | |
2497 #ifdef FEAT_CRYPT | |
2498 if (cryptkey != NULL) | |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2499 msg_add_lines(c, (long)linecnt, filesize |
6122 | 2500 - crypt_get_header_len(crypt_get_method_nr(curbuf))); |
7 | 2501 else |
2502 #endif | |
2503 msg_add_lines(c, (long)linecnt, filesize); | |
2504 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
2505 VIM_CLEAR(keep_msg); |
7 | 2506 msg_scrolled_ign = TRUE; |
2507 #ifdef ALWAYS_USE_GUI | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2508 // Don't show the message when reading stdin, it would end up in a |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2509 // message box (which might be shown when exiting!) |
7 | 2510 if (read_stdin || read_buffer) |
2511 p = msg_may_trunc(FALSE, IObuff); | |
2512 else | |
2513 #endif | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2514 { |
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2515 if (msg_col > 0) |
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2516 msg_putchar('\r'); // overwrite previous message |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2517 p = (char_u *)msg_trunc_attr((char *)IObuff, FALSE, 0); |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2518 } |
7 | 2519 if (read_stdin || read_buffer || restart_edit != 0 |
540 | 2520 || (msg_scrolled != 0 && !need_wait_return)) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2521 // Need to repeat the message after redrawing when: |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2522 // - When reading from stdin (the screen will be cleared next). |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2523 // - When restart_edit is set (otherwise there will be a delay |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2524 // before redrawing). |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2525 // - When the screen was scrolled but there is no wait-return |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2526 // prompt. |
679 | 2527 set_keep_msg(p, 0); |
7 | 2528 msg_scrolled_ign = FALSE; |
2529 } | |
2530 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2531 // with errors writing the file requires ":w!" |
7 | 2532 if (newfile && (error |
595 | 2533 || conv_error != 0 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2534 || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP))) |
7 | 2535 curbuf->b_p_ro = TRUE; |
2536 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2537 u_clearline(); // cannot use "U" command after adding lines |
7 | 2538 |
2539 /* | |
2540 * In Ex mode: cursor at last new line. | |
2541 * Otherwise: cursor at first new line. | |
2542 */ | |
2543 if (exmode_active) | |
2544 curwin->w_cursor.lnum = from + linecnt; | |
2545 else | |
2546 curwin->w_cursor.lnum = from + 1; | |
2547 check_cursor_lnum(); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2548 beginline(BL_WHITE | BL_FIX); // on first non-blank |
7 | 2549 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22568
diff
changeset
|
2550 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2551 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2552 // Set '[ and '] marks to the newly read lines. |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2553 curbuf->b_op_start.lnum = from + 1; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2554 curbuf->b_op_start.col = 0; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2555 curbuf->b_op_end.lnum = from + linecnt; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2556 curbuf->b_op_end.col = 0; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2557 } |
696 | 2558 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2559 #ifdef MSWIN |
696 | 2560 /* |
2561 * Work around a weird problem: When a file has two links (only | |
2562 * possible on NTFS) and we write through one link, then stat() it | |
1651 | 2563 * through the other link, the timestamp information may be wrong. |
696 | 2564 * It's correct again after reading the file, thus reset the timestamp |
2565 * here. | |
2566 */ | |
2567 if (newfile && !read_stdin && !read_buffer | |
2568 && mch_stat((char *)fname, &st) >= 0) | |
2569 { | |
2570 buf_store_time(curbuf, &st, fname); | |
2571 curbuf->b_mtime_read = curbuf->b_mtime; | |
2572 } | |
2573 #endif | |
7 | 2574 } |
2575 msg_scroll = msg_save; | |
2576 | |
2577 #ifdef FEAT_VIMINFO | |
2578 /* | |
2579 * Get the marks before executing autocommands, so they can be used there. | |
2580 */ | |
2581 check_marks_read(); | |
2582 #endif | |
2583 | |
2584 /* | |
6933 | 2585 * We remember if the last line of the read didn't have |
2586 * an eol even when 'binary' is off, to support turning 'fixeol' off, | |
2587 * or writing the read again with 'binary' on. The latter is required | |
2588 * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. | |
7 | 2589 */ |
2707 | 2590 curbuf->b_no_eol_lnum = read_no_eol_lnum; |
7 | 2591 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2592 // When reloading a buffer put the cursor at the first line that is |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2593 // different. |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
2594 if (flags & READ_KEEP_UNDO) |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
2595 u_find_first_changed(); |
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
2596 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2597 #ifdef FEAT_PERSISTENT_UNDO |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2598 /* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2599 * When opening a new file locate undo info and read it. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2600 */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2601 if (read_undo_file) |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2602 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2603 char_u hash[UNDO_HASH_SIZE]; |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2604 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2605 sha256_finish(&sha_ctx, hash); |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2217
diff
changeset
|
2606 u_read_undo(NULL, hash, fname); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2607 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2608 #endif |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2609 |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
2610 if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL)) |
7 | 2611 { |
2612 int m = msg_scroll; | |
2613 int n = msg_scrolled; | |
2614 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2615 // Save the fileformat now, otherwise the buffer will be considered |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2616 // modified if the format/encoding was automatically detected. |
819 | 2617 if (set_options) |
7 | 2618 save_file_ff(curbuf); |
2619 | |
2620 /* | |
2621 * The output from the autocommands should not overwrite anything and | |
2622 * should not be overwritten: Set msg_scroll, restore its value if no | |
2623 * output was done. | |
2624 */ | |
2625 msg_scroll = TRUE; | |
2626 if (filtering) | |
2627 apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname, | |
2628 FALSE, curbuf, eap); | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
2629 else if (newfile || (read_buffer && sfname != NULL)) |
8937
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2630 { |
7 | 2631 apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname, |
2632 FALSE, curbuf, eap); | |
8937
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2633 if (!au_did_filetype && *curbuf->b_p_ft != NUL) |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2634 /* |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2635 * EVENT_FILETYPE was not triggered but the buffer already has a |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2636 * filetype. Trigger EVENT_FILETYPE using the existing filetype. |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2637 */ |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2638 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2639 TRUE, curbuf); |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2640 } |
7 | 2641 else |
2642 apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname, | |
2643 FALSE, NULL, eap); | |
2644 if (msg_scrolled == n) | |
2645 msg_scroll = m; | |
2707 | 2646 # ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2647 if (aborting()) // autocmds may abort script processing |
7 | 2648 return FAIL; |
2707 | 2649 # endif |
2650 } | |
2651 | |
7 | 2652 if (recoverymode && error) |
2653 return FAIL; | |
2654 return OK; | |
2655 } | |
2656 | |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9828
diff
changeset
|
2657 #if defined(OPEN_CHR_FILES) || defined(PROTO) |
1313 | 2658 /* |
2659 * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+", | |
2660 * which is the name of files used for process substitution output by | |
2661 * some shells on some operating systems, e.g., bash on SunOS. | |
2662 * Do not accept "/dev/fd/[012]", opening these may hang Vim. | |
2663 */ | |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9828
diff
changeset
|
2664 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2665 is_dev_fd_file(char_u *fname) |
1313 | 2666 { |
2667 return (STRNCMP(fname, "/dev/fd/", 8) == 0 | |
2668 && VIM_ISDIGIT(fname[8]) | |
2669 && *skipdigits(fname + 9) == NUL | |
2670 && (fname[9] != NUL | |
2671 || (fname[8] != '0' && fname[8] != '1' && fname[8] != '2'))); | |
2672 } | |
2673 #endif | |
2674 | |
595 | 2675 /* |
2676 * From the current line count and characters read after that, estimate the | |
2677 * line number where we are now. | |
2678 * Used for error messages that include a line number. | |
2679 */ | |
2680 static linenr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2681 readfile_linenr( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2682 linenr_T linecnt, // line count before reading more bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2683 char_u *p, // start of more bytes read |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2684 char_u *endp) // end of more bytes read |
595 | 2685 { |
2686 char_u *s; | |
2687 linenr_T lnum; | |
2688 | |
2689 lnum = curbuf->b_ml.ml_line_count - linecnt + 1; | |
2690 for (s = p; s < endp; ++s) | |
2691 if (*s == '\n') | |
2692 ++lnum; | |
2693 return lnum; | |
2694 } | |
2695 | |
7 | 2696 /* |
612 | 2697 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be |
2698 * equal to the buffer "buf". Used for calling readfile(). | |
7 | 2699 * Returns OK or FAIL. |
2700 */ | |
2701 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2702 prep_exarg(exarg_T *eap, buf_T *buf) |
7 | 2703 { |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2704 eap->cmd = alloc(15 + (unsigned)STRLEN(buf->b_p_fenc)); |
7 | 2705 if (eap->cmd == NULL) |
2706 return FAIL; | |
2707 | |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2708 sprintf((char *)eap->cmd, "e ++enc=%s", buf->b_p_fenc); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2709 eap->force_enc = 8; |
612 | 2710 eap->bad_char = buf->b_bad_char; |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2711 eap->force_ff = *buf->b_p_ff; |
612 | 2712 |
2713 eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN; | |
819 | 2714 eap->read_edit = FALSE; |
612 | 2715 eap->forceit = FALSE; |
7 | 2716 return OK; |
2717 } | |
2718 | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2719 /* |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2720 * Set default or forced 'fileformat' and 'binary'. |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2721 */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2722 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2723 set_file_options(int set_options, exarg_T *eap) |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2724 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2725 // set default 'fileformat' |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2726 if (set_options) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2727 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2728 if (eap != NULL && eap->force_ff != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2729 set_fileformat(get_fileformat_force(curbuf, eap), OPT_LOCAL); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2730 else if (*p_ffs != NUL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2731 set_fileformat(default_fileformat(), OPT_LOCAL); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2732 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2733 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2734 // set or reset 'binary' |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2735 if (eap != NULL && eap->force_bin != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2736 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2737 int oldval = curbuf->b_p_bin; |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2738 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2739 curbuf->b_p_bin = (eap->force_bin == FORCE_BIN); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2740 set_options_bin(oldval, curbuf->b_p_bin, OPT_LOCAL); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2741 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2742 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2743 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2744 /* |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2745 * Set forced 'fileencoding'. |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2746 */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2747 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2748 set_forced_fenc(exarg_T *eap) |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2749 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2750 if (eap->force_enc != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2751 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2752 char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2753 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2754 if (fenc != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2755 set_string_option_direct((char_u *)"fenc", -1, |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2756 fenc, OPT_FREE|OPT_LOCAL, 0); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2757 vim_free(fenc); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2758 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2759 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2760 |
7 | 2761 /* |
2762 * Find next fileencoding to use from 'fileencodings'. | |
2763 * "pp" points to fenc_next. It's advanced to the next item. | |
2764 * When there are no more items, an empty string is returned and *pp is set to | |
2765 * NULL. | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2766 * When *pp is not set to NULL, the result is in allocated memory and "alloced" |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2767 * is set to TRUE. |
7 | 2768 */ |
2769 static char_u * | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2770 next_fenc(char_u **pp, int *alloced) |
7 | 2771 { |
2772 char_u *p; | |
2773 char_u *r; | |
2774 | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2775 *alloced = FALSE; |
7 | 2776 if (**pp == NUL) |
2777 { | |
2778 *pp = NULL; | |
2779 return (char_u *)""; | |
2780 } | |
2781 p = vim_strchr(*pp, ','); | |
2782 if (p == NULL) | |
2783 { | |
2784 r = enc_canonize(*pp); | |
2785 *pp += STRLEN(*pp); | |
2786 } | |
2787 else | |
2788 { | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20828
diff
changeset
|
2789 r = vim_strnsave(*pp, p - *pp); |
7 | 2790 *pp = p + 1; |
2791 if (r != NULL) | |
2792 { | |
2793 p = enc_canonize(r); | |
2794 vim_free(r); | |
2795 r = p; | |
2796 } | |
2797 } | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2798 if (r != NULL) |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2799 *alloced = TRUE; |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2800 else |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2801 { |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2802 // out of memory |
7 | 2803 r = (char_u *)""; |
2804 *pp = NULL; | |
2805 } | |
2806 return r; | |
2807 } | |
2808 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2809 #ifdef FEAT_EVAL |
7 | 2810 /* |
2811 * Convert a file with the 'charconvert' expression. | |
2812 * This closes the file which is to be read, converts it and opens the | |
2813 * resulting file for reading. | |
2814 * Returns name of the resulting converted file (the caller should delete it | |
2815 * after reading it). | |
2816 * Returns NULL if the conversion failed ("*fdp" is not set) . | |
2817 */ | |
2818 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2819 readfile_charconvert( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2820 char_u *fname, // name of input file |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2821 char_u *fenc, // converted from |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2822 int *fdp) // in/out: file descriptor of file |
7 | 2823 { |
2824 char_u *tmpname; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2825 char *errmsg = NULL; |
7 | 2826 |
6721 | 2827 tmpname = vim_tempname('r', FALSE); |
7 | 2828 if (tmpname == NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2829 errmsg = _("Can't find temp file for conversion"); |
7 | 2830 else |
2831 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2832 close(*fdp); // close the input file, ignore errors |
7 | 2833 *fdp = -1; |
2834 if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc, | |
2835 fname, tmpname) == FAIL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2836 errmsg = _("Conversion with 'charconvert' failed"); |
7 | 2837 if (errmsg == NULL && (*fdp = mch_open((char *)tmpname, |
2838 O_RDONLY | O_EXTRA, 0)) < 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2839 errmsg = _("can't read output of 'charconvert'"); |
7 | 2840 } |
2841 | |
2842 if (errmsg != NULL) | |
2843 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2844 // Don't use emsg(), it breaks mappings, the retry with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2845 // another type of conversion might still work. |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2846 msg(errmsg); |
7 | 2847 if (tmpname != NULL) |
2848 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2849 mch_remove(tmpname); // delete converted file |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
2850 VIM_CLEAR(tmpname); |
7 | 2851 } |
2852 } | |
2853 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2854 // If the input file is closed, open it (caller should check for error). |
7 | 2855 if (*fdp < 0) |
2856 *fdp = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); | |
2857 | |
2858 return tmpname; | |
2859 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2860 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2861 |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
2862 #if defined(FEAT_CRYPT) || defined(PROTO) |
7 | 2863 /* |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2864 * Check for magic number used for encryption. Applies to the current buffer. |
7 | 2865 * If found, the magic number is removed from ptr[*sizep] and *sizep and |
2866 * *filesizep are updated. | |
2867 * Return the (new) encryption key, NULL for no encryption. | |
2868 */ | |
2869 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2870 check_for_cryptkey( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2871 char_u *cryptkey, // previous encryption key or NULL |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2872 char_u *ptr, // pointer to read bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2873 long *sizep, // length of read bytes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2874 off_T *filesizep, // nr of bytes used from file |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2875 int newfile, // editing a new buffer |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2876 char_u *fname, // file name to display |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2877 int *did_ask) // flag: whether already asked for key |
7 | 2878 { |
6122 | 2879 int method = crypt_method_nr_from_magic((char *)ptr, *sizep); |
5312 | 2880 int b_p_ro = curbuf->b_p_ro; |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2881 |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2882 if (method >= 0) |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2883 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2884 // Mark the buffer as read-only until the decryption has taken place. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2885 // Avoids accidentally overwriting the file with garbage. |
5312 | 2886 curbuf->b_p_ro = TRUE; |
2887 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2888 // Set the cryptmethod local to the buffer. |
6122 | 2889 crypt_set_cm_option(curbuf, method); |
2204
c493d6bfde09
A few more changes for encryption. Add test that encrypted file can be read.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
2890 if (cryptkey == NULL && !*did_ask) |
7 | 2891 { |
2892 if (*curbuf->b_p_key) | |
2893 cryptkey = curbuf->b_p_key; | |
2894 else | |
2895 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2896 // When newfile is TRUE, store the typed key in the 'key' |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2897 // option and don't free it. bf needs hash of the key saved. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2898 // Don't ask for the key again when first time Enter was hit. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2899 // Happens when retrying to detect encoding. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
2900 smsg(_(need_key_msg), fname); |
2267 | 2901 msg_scroll = TRUE; |
6353 | 2902 crypt_check_method(method); |
6122 | 2903 cryptkey = crypt_get_key(newfile, FALSE); |
2204
c493d6bfde09
A few more changes for encryption. Add test that encrypted file can be read.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
2904 *did_ask = TRUE; |
c493d6bfde09
A few more changes for encryption. Add test that encrypted file can be read.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
2905 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2906 // check if empty key entered |
7 | 2907 if (cryptkey != NULL && *cryptkey == NUL) |
2908 { | |
2909 if (cryptkey != curbuf->b_p_key) | |
2910 vim_free(cryptkey); | |
2911 cryptkey = NULL; | |
2912 } | |
2913 } | |
2914 } | |
2915 | |
2916 if (cryptkey != NULL) | |
2917 { | |
6122 | 2918 int header_len; |
2919 | |
2920 header_len = crypt_get_header_len(method); | |
10221
fb1fde4fcff7
commit https://github.com/vim/vim/commit/680e015bfe19be6772d3bd754486fbd45c1a9d3b
Christian Brabandt <cb@256bit.org>
parents:
10086
diff
changeset
|
2921 if (*sizep <= header_len) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2922 // invalid header, buffer can't be encrypted |
10221
fb1fde4fcff7
commit https://github.com/vim/vim/commit/680e015bfe19be6772d3bd754486fbd45c1a9d3b
Christian Brabandt <cb@256bit.org>
parents:
10086
diff
changeset
|
2923 return NULL; |
25421
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2924 |
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2925 curbuf->b_cryptstate = crypt_create_from_header( |
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2926 method, cryptkey, ptr); |
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2927 crypt_set_cm_option(curbuf, method); |
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2928 |
c094a29722bb
patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents:
25417
diff
changeset
|
2929 // Remove cryptmethod specific header from the text. |
6122 | 2930 *filesizep += header_len; |
2931 *sizep -= header_len; | |
2932 mch_memmove(ptr, ptr + header_len, (size_t)*sizep); | |
2933 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2934 // Restore the read-only flag. |
5312 | 2935 curbuf->b_p_ro = b_p_ro; |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2936 } |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2937 } |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2938 // When starting to edit a new file which does not have encryption, clear |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2939 // the 'key' option, except when starting up (called with -x argument) |
2410
8f6106dd3d12
Fix: editing a not encrypted file after a crypted file messed up reading the
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2940 else if (newfile && *curbuf->b_p_key != NUL && !starting) |
7 | 2941 set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); |
2942 | |
2943 return cryptkey; | |
2944 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2945 #endif // FEAT_CRYPT |
2265
b7cb69ab616d
Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents:
2261
diff
changeset
|
2946 |
7 | 2947 /* |
1303 | 2948 * Return TRUE if a file appears to be read-only from the file permissions. |
2949 */ | |
2950 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2951 check_file_readonly( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2952 char_u *fname, // full path to file |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2953 int perm UNUSED) // known permissions on file |
1303 | 2954 { |
2955 #ifndef USE_MCH_ACCESS | |
2956 int fd = 0; | |
2957 #endif | |
2958 | |
2959 return ( | |
2960 #ifdef USE_MCH_ACCESS | |
2961 # ifdef UNIX | |
2962 (perm & 0222) == 0 || | |
2963 # endif | |
2964 mch_access((char *)fname, W_OK) | |
2965 #else | |
2966 (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0 | |
2967 ? TRUE : (close(fd), FALSE) | |
2968 #endif | |
2969 ); | |
2970 } | |
2971 | |
15816
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2972 #if defined(HAVE_FSYNC) || defined(PROTO) |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2973 /* |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2974 * Call fsync() with Mac-specific exception. |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2975 * Return fsync() result: zero for success. |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2976 */ |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2977 int |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2978 vim_fsync(int fd) |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2979 { |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2980 int r; |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2981 |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2982 # ifdef MACOS_X |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2983 r = fcntl(fd, F_FULLFSYNC); |
15910
da4d1f69374e
patch 8.1.0961: Mac: fsync may fail sometimes
Bram Moolenaar <Bram@vim.org>
parents:
15902
diff
changeset
|
2984 if (r != 0) // F_FULLFSYNC not working or not supported |
15816
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2985 # endif |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2986 r = fsync(fd); |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2987 return r; |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2988 } |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2989 #endif |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2990 |
7 | 2991 /* |
633 | 2992 * Set the name of the current buffer. Use when the buffer doesn't have a |
2993 * name and a ":r" or ":w" command with a file name is used. | |
2994 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2995 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2996 set_rw_fname(char_u *fname, char_u *sfname) |
633 | 2997 { |
1905 | 2998 buf_T *buf = curbuf; |
2999 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3000 // It's like the unnamed buffer is deleted.... |
633 | 3001 if (curbuf->b_p_bl) |
3002 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
3003 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3004 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3005 if (aborting()) // autocmds may abort script processing |
633 | 3006 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3007 #endif |
1905 | 3008 if (curbuf != buf) |
3009 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3010 // We are in another buffer now, don't do the renaming. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3011 emsg(_(e_auchangedbuf)); |
1905 | 3012 return FAIL; |
3013 } | |
633 | 3014 |
3015 if (setfname(curbuf, fname, sfname, FALSE) == OK) | |
3016 curbuf->b_flags |= BF_NOTEDITED; | |
3017 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3018 // ....and a new named one is created |
633 | 3019 apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); |
3020 if (curbuf->b_p_bl) | |
3021 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3022 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3023 if (aborting()) // autocmds may abort script processing |
633 | 3024 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3025 #endif |
633 | 3026 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3027 // Do filetype detection now if 'filetype' is empty. |
633 | 3028 if (*curbuf->b_p_ft == NUL) |
3029 { | |
819 | 3030 if (au_has_group((char_u *)"filetypedetect")) |
9260
ac8180818504
commit https://github.com/vim/vim/commit/1610d052413e0ed664498853a47acc2d677a22d1
Christian Brabandt <cb@256bit.org>
parents:
9211
diff
changeset
|
3031 (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE, NULL); |
717 | 3032 do_modelines(0); |
633 | 3033 } |
3034 | |
3035 return OK; | |
3036 } | |
3037 | |
3038 /* | |
7 | 3039 * Put file name into IObuff with quotes. |
3040 */ | |
33 | 3041 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3042 msg_add_fname(buf_T *buf, char_u *fname) |
7 | 3043 { |
3044 if (fname == NULL) | |
3045 fname = (char_u *)"-stdin-"; | |
3046 home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE); | |
3047 IObuff[0] = '"'; | |
3048 STRCAT(IObuff, "\" "); | |
3049 } | |
3050 | |
3051 /* | |
3052 * Append message for text mode to IObuff. | |
3053 * Return TRUE if something appended. | |
3054 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3055 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3056 msg_add_fileformat(int eol_type) |
7 | 3057 { |
3058 #ifndef USE_CRNL | |
3059 if (eol_type == EOL_DOS) | |
3060 { | |
3061 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); | |
3062 return TRUE; | |
3063 } | |
3064 #endif | |
3065 if (eol_type == EOL_MAC) | |
3066 { | |
3067 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]")); | |
3068 return TRUE; | |
3069 } | |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15816
diff
changeset
|
3070 #ifdef USE_CRNL |
7 | 3071 if (eol_type == EOL_UNIX) |
3072 { | |
3073 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]")); | |
3074 return TRUE; | |
3075 } | |
3076 #endif | |
3077 return FALSE; | |
3078 } | |
3079 | |
3080 /* | |
3081 * Append line and character count to IObuff. | |
3082 */ | |
33 | 3083 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3084 msg_add_lines( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3085 int insert_space, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3086 long lnum, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3087 off_T nchars) |
7 | 3088 { |
3089 char_u *p; | |
3090 | |
3091 p = IObuff + STRLEN(IObuff); | |
3092 | |
3093 if (insert_space) | |
3094 *p++ = ' '; | |
3095 if (shortmess(SHM_LINES)) | |
9391
4c40631238e4
commit https://github.com/vim/vim/commit/bde9810d6103ffe3a22a9330021cb21db1ed1792
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3096 vim_snprintf((char *)p, IOSIZE - (p - IObuff), |
21154
9f9c26b3ddc5
patch 8.2.1128: the write message mentions characters, but it's bytes
Bram Moolenaar <Bram@vim.org>
parents:
21073
diff
changeset
|
3097 "%ldL, %lldB", lnum, (varnumber_T)nchars); |
7 | 3098 else |
3099 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3100 sprintf((char *)p, NGETTEXT("%ld line, ", "%ld lines, ", lnum), lnum); |
7 | 3101 p += STRLEN(p); |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3102 vim_snprintf((char *)p, IOSIZE - (p - IObuff), |
21154
9f9c26b3ddc5
patch 8.2.1128: the write message mentions characters, but it's bytes
Bram Moolenaar <Bram@vim.org>
parents:
21073
diff
changeset
|
3103 NGETTEXT("%lld byte", "%lld bytes", nchars), |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19301
diff
changeset
|
3104 (varnumber_T)nchars); |
7 | 3105 } |
3106 } | |
3107 | |
3108 /* | |
3109 * Append message for missing line separator to IObuff. | |
3110 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3111 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3112 msg_add_eol(void) |
7 | 3113 { |
3114 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]")); | |
3115 } | |
3116 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3117 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3118 time_differs(long t1, long t2) |
7 | 3119 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3120 #if defined(__linux__) || defined(MSWIN) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3121 // On a FAT filesystem, esp. under Linux, there are only 5 bits to store |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3122 // the seconds. Since the roundoff is done when flushing the inode, the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3123 // time may change unexpectedly by one second!!! |
7 | 3124 return (t1 - t2 > 1 || t2 - t1 > 1); |
3125 #else | |
3126 return (t1 != t2); | |
3127 #endif | |
3128 } | |
3129 | |
3130 /* | |
1948 | 3131 * Return TRUE if file encoding "fenc" requires conversion from or to |
3132 * 'encoding'. | |
7 | 3133 */ |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3134 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3135 need_conversion(char_u *fenc) |
7 | 3136 { |
1948 | 3137 int same_encoding; |
3138 int enc_flags; | |
3139 int fenc_flags; | |
3140 | |
3141 if (*fenc == NUL || STRCMP(p_enc, fenc) == 0) | |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3142 { |
1948 | 3143 same_encoding = TRUE; |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3144 fenc_flags = 0; |
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3145 } |
1948 | 3146 else |
3147 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3148 // Ignore difference between "ansi" and "latin1", "ucs-4" and |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3149 // "ucs-4be", etc. |
1948 | 3150 enc_flags = get_fio_flags(p_enc); |
3151 fenc_flags = get_fio_flags(fenc); | |
3152 same_encoding = (enc_flags != 0 && fenc_flags == enc_flags); | |
3153 } | |
3154 if (same_encoding) | |
3155 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3156 // Specified encoding matches with 'encoding'. This requires |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3157 // conversion when 'encoding' is Unicode but not UTF-8. |
1948 | 3158 return enc_unicode != 0; |
3159 } | |
3160 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3161 // Encodings differ. However, conversion is not needed when 'enc' is any |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3162 // Unicode encoding and the file is UTF-8. |
1948 | 3163 return !(enc_utf8 && fenc_flags == FIO_UTF8); |
7 | 3164 } |
3165 | |
3166 /* | |
3167 * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the | |
3168 * internal conversion. | |
3169 * if "ptr" is an empty string, use 'encoding'. | |
3170 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3171 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3172 get_fio_flags(char_u *ptr) |
7 | 3173 { |
3174 int prop; | |
3175 | |
3176 if (*ptr == NUL) | |
3177 ptr = p_enc; | |
3178 | |
3179 prop = enc_canon_props(ptr); | |
3180 if (prop & ENC_UNICODE) | |
3181 { | |
3182 if (prop & ENC_2BYTE) | |
3183 { | |
3184 if (prop & ENC_ENDIAN_L) | |
3185 return FIO_UCS2 | FIO_ENDIAN_L; | |
3186 return FIO_UCS2; | |
3187 } | |
3188 if (prop & ENC_4BYTE) | |
3189 { | |
3190 if (prop & ENC_ENDIAN_L) | |
3191 return FIO_UCS4 | FIO_ENDIAN_L; | |
3192 return FIO_UCS4; | |
3193 } | |
3194 if (prop & ENC_2WORD) | |
3195 { | |
3196 if (prop & ENC_ENDIAN_L) | |
3197 return FIO_UTF16 | FIO_ENDIAN_L; | |
3198 return FIO_UTF16; | |
3199 } | |
3200 return FIO_UTF8; | |
3201 } | |
3202 if (prop & ENC_LATIN1) | |
3203 return FIO_LATIN1; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3204 // must be ENC_DBCS, requires iconv() |
7 | 3205 return 0; |
3206 } | |
3207 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3208 #if defined(MSWIN) || defined(PROTO) |
7 | 3209 /* |
3210 * Check "ptr" for a MS-Windows codepage name and return the FIO_ flags needed | |
3211 * for the conversion MS-Windows can do for us. Also accept "utf-8". | |
3212 * Used for conversion between 'encoding' and 'fileencoding'. | |
3213 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3214 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3215 get_win_fio_flags(char_u *ptr) |
7 | 3216 { |
3217 int cp; | |
3218 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3219 // Cannot do this when 'encoding' is not utf-8 and not a codepage. |
7 | 3220 if (!enc_utf8 && enc_codepage <= 0) |
3221 return 0; | |
3222 | |
3223 cp = encname2codepage(ptr); | |
3224 if (cp == 0) | |
3225 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3226 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 |
7 | 3227 if (STRCMP(ptr, "utf-8") == 0) |
3228 cp = CP_UTF8; | |
3229 else | |
3230 # endif | |
3231 return 0; | |
3232 } | |
3233 return FIO_PUT_CP(cp) | FIO_CODEPAGE; | |
3234 } | |
3235 #endif | |
3236 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3237 #if defined(MACOS_CONVERT) || defined(PROTO) |
7 | 3238 /* |
3239 * Check "ptr" for a Carbon supported encoding and return the FIO_ flags | |
3240 * needed for the internal conversion to/from utf-8 or latin1. | |
3241 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3242 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3243 get_mac_fio_flags(char_u *ptr) |
7 | 3244 { |
3245 if ((enc_utf8 || STRCMP(p_enc, "latin1") == 0) | |
3246 && (enc_canon_props(ptr) & ENC_MACROMAN)) | |
3247 return FIO_MACROMAN; | |
3248 return 0; | |
3249 } | |
3250 #endif | |
3251 | |
3252 /* | |
3253 * Check for a Unicode BOM (Byte Order Mark) at the start of p[size]. | |
3254 * "size" must be at least 2. | |
3255 * Return the name of the encoding and set "*lenp" to the length. | |
3256 * Returns NULL when no BOM found. | |
3257 */ | |
3258 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3259 check_for_bom( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3260 char_u *p, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3261 long size, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3262 int *lenp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3263 int flags) |
7 | 3264 { |
3265 char *name = NULL; | |
3266 int len = 2; | |
3267 | |
3268 if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf | |
1688 | 3269 && (flags == FIO_ALL || flags == FIO_UTF8 || flags == 0)) |
7 | 3270 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3271 name = "utf-8"; // EF BB BF |
7 | 3272 len = 3; |
3273 } | |
3274 else if (p[0] == 0xff && p[1] == 0xfe) | |
3275 { | |
3276 if (size >= 4 && p[2] == 0 && p[3] == 0 | |
3277 && (flags == FIO_ALL || flags == (FIO_UCS4 | FIO_ENDIAN_L))) | |
3278 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3279 name = "ucs-4le"; // FF FE 00 00 |
7 | 3280 len = 4; |
3281 } | |
1735 | 3282 else if (flags == (FIO_UCS2 | FIO_ENDIAN_L)) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3283 name = "ucs-2le"; // FF FE |
1735 | 3284 else if (flags == FIO_ALL || flags == (FIO_UTF16 | FIO_ENDIAN_L)) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3285 // utf-16le is preferred, it also works for ucs-2le text |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3286 name = "utf-16le"; // FF FE |
7 | 3287 } |
3288 else if (p[0] == 0xfe && p[1] == 0xff | |
3289 && (flags == FIO_ALL || flags == FIO_UCS2 || flags == FIO_UTF16)) | |
3290 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3291 // Default to utf-16, it works also for ucs-2 text. |
1547 | 3292 if (flags == FIO_UCS2) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3293 name = "ucs-2"; // FE FF |
1547 | 3294 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3295 name = "utf-16"; // FE FF |
7 | 3296 } |
3297 else if (size >= 4 && p[0] == 0 && p[1] == 0 && p[2] == 0xfe | |
3298 && p[3] == 0xff && (flags == FIO_ALL || flags == FIO_UCS4)) | |
3299 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3300 name = "ucs-4"; // 00 00 FE FF |
7 | 3301 len = 4; |
3302 } | |
3303 | |
3304 *lenp = len; | |
3305 return (char_u *)name; | |
3306 } | |
3307 | |
3308 /* | |
3309 * Try to find a shortname by comparing the fullname with the current | |
3310 * directory. | |
1411 | 3311 * Returns "full_path" or pointer into "full_path" if shortened. |
3312 */ | |
3313 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3314 shorten_fname1(char_u *full_path) |
1411 | 3315 { |
2770 | 3316 char_u *dirname; |
1411 | 3317 char_u *p = full_path; |
3318 | |
2770 | 3319 dirname = alloc(MAXPATHL); |
3320 if (dirname == NULL) | |
3321 return full_path; | |
1411 | 3322 if (mch_dirname(dirname, MAXPATHL) == OK) |
3323 { | |
3324 p = shorten_fname(full_path, dirname); | |
3325 if (p == NULL || *p == NUL) | |
3326 p = full_path; | |
3327 } | |
2770 | 3328 vim_free(dirname); |
1411 | 3329 return p; |
3330 } | |
3331 | |
3332 /* | |
3333 * Try to find a shortname by comparing the fullname with the current | |
3334 * directory. | |
7 | 3335 * Returns NULL if not shorter name possible, pointer into "full_path" |
3336 * otherwise. | |
3337 */ | |
3338 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3339 shorten_fname(char_u *full_path, char_u *dir_name) |
7 | 3340 { |
3341 int len; | |
3342 char_u *p; | |
3343 | |
3344 if (full_path == NULL) | |
3345 return NULL; | |
3346 len = (int)STRLEN(dir_name); | |
3347 if (fnamencmp(dir_name, full_path, len) == 0) | |
3348 { | |
3349 p = full_path + len; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3350 #if defined(MSWIN) |
7 | 3351 /* |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3352 * MS-Windows: when a file is in the root directory, dir_name will end |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3353 * in a slash, since C: by itself does not define a specific dir. In |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3354 * this case p may already be correct. <negri> |
7 | 3355 */ |
3356 if (!((len > 2) && (*(p - 2) == ':'))) | |
3357 #endif | |
3358 { | |
3359 if (vim_ispathsep(*p)) | |
3360 ++p; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3361 #ifndef VMS // the path separator is always part of the path |
7 | 3362 else |
3363 p = NULL; | |
3364 #endif | |
3365 } | |
3366 } | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3367 #if defined(MSWIN) |
7 | 3368 /* |
3369 * When using a file in the current drive, remove the drive name: | |
3370 * "A:\dir\file" -> "\dir\file". This helps when moving a session file on | |
3371 * a floppy from "A:\dir" to "B:\dir". | |
3372 */ | |
3373 else if (len > 3 | |
3374 && TOUPPER_LOC(full_path[0]) == TOUPPER_LOC(dir_name[0]) | |
3375 && full_path[1] == ':' | |
3376 && vim_ispathsep(full_path[2])) | |
3377 p = full_path + 2; | |
3378 #endif | |
3379 else | |
3380 p = NULL; | |
3381 return p; | |
3382 } | |
3383 | |
3384 /* | |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3385 * Shorten filename of a buffer. |
7 | 3386 * When "force" is TRUE: Use full path from now on for files currently being |
3387 * edited, both for file name and swap file name. Try to shorten the file | |
3388 * names a bit, if safe to do so. | |
3389 * When "force" is FALSE: Only try to shorten absolute file names. | |
3390 * For buffers that have buftype "nofile" or "scratch": never change the file | |
3391 * name. | |
3392 */ | |
3393 void | |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3394 shorten_buf_fname(buf_T *buf, char_u *dirname, int force) |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3395 { |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3396 char_u *p; |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3397 |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3398 if (buf->b_fname != NULL |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3399 #ifdef FEAT_QUICKFIX |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
3400 && !bt_nofilename(buf) |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3401 #endif |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3402 && !path_with_url(buf->b_fname) |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3403 && (force |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3404 || buf->b_sfname == NULL |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3405 || mch_isFullName(buf->b_sfname))) |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3406 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3407 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3408 VIM_CLEAR(buf->b_sfname); |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3409 p = shorten_fname(buf->b_ffname, dirname); |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3410 if (p != NULL) |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3411 { |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3412 buf->b_sfname = vim_strsave(p); |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3413 buf->b_fname = buf->b_sfname; |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3414 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3415 if (p == NULL || buf->b_fname == NULL) |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3416 buf->b_fname = buf->b_ffname; |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3417 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3418 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3419 |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3420 /* |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3421 * Shorten filenames for all buffers. |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3422 */ |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3423 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3424 shorten_fnames(int force) |
7 | 3425 { |
3426 char_u dirname[MAXPATHL]; | |
3427 buf_T *buf; | |
3428 | |
3429 mch_dirname(dirname, MAXPATHL); | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
3430 FOR_ALL_BUFFERS(buf) |
7 | 3431 { |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3432 shorten_buf_fname(buf, dirname, force); |
9 | 3433 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3434 // Always make the swap file name a full path, a "nofile" buffer may |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3435 // also have a swap file. |
9 | 3436 mf_fullname(buf->b_ml.ml_mfp); |
7 | 3437 } |
3438 status_redraw_all(); | |
672 | 3439 redraw_tabline = TRUE; |
18767
068337e86133
patch 8.1.2373: cannot build with +popupwin but without +quickfix
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3440 #if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX) |
17584
65a8099fc0e8
patch 8.1.1789: cannot see file name of preview popup window
Bram Moolenaar <Bram@vim.org>
parents:
17565
diff
changeset
|
3441 popup_update_preview_title(); |
65a8099fc0e8
patch 8.1.1789: cannot see file name of preview popup window
Bram Moolenaar <Bram@vim.org>
parents:
17565
diff
changeset
|
3442 #endif |
7 | 3443 } |
3444 | |
3445 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ | |
3446 || defined(FEAT_GUI_MSWIN) \ | |
19526
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
3447 || defined(FEAT_GUI_HAIKU) \ |
7 | 3448 || defined(PROTO) |
3449 /* | |
3450 * Shorten all filenames in "fnames[count]" by current directory. | |
3451 */ | |
3452 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3453 shorten_filenames(char_u **fnames, int count) |
7 | 3454 { |
3455 int i; | |
3456 char_u dirname[MAXPATHL]; | |
3457 char_u *p; | |
3458 | |
3459 if (fnames == NULL || count < 1) | |
3460 return; | |
3461 mch_dirname(dirname, sizeof(dirname)); | |
3462 for (i = 0; i < count; ++i) | |
3463 { | |
3464 if ((p = shorten_fname(fnames[i], dirname)) != NULL) | |
3465 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3466 // shorten_fname() returns pointer in given "fnames[i]". If free |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3467 // "fnames[i]" first, "p" becomes invalid. So we need to copy |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3468 // "p" first then free fnames[i]. |
7 | 3469 p = vim_strsave(p); |
3470 vim_free(fnames[i]); | |
3471 fnames[i] = p; | |
3472 } | |
3473 } | |
3474 } | |
3475 #endif | |
3476 | |
3477 /* | |
14475
dddba3937532
patch 8.1.0251: using full path is not supported for 'backupdir'
Christian Brabandt <cb@256bit.org>
parents:
14433
diff
changeset
|
3478 * Add extension to file name - change path/fo.o.h to path/fo.o.h.ext or |
7 | 3479 * fo_o_h.ext for MSDOS or when shortname option set. |
3480 * | |
3481 * Assumed that fname is a valid name found in the filesystem we assure that | |
3482 * the return value is a different name and ends in 'ext'. | |
3483 * "ext" MUST be at most 4 characters long if it starts with a dot, 3 | |
3484 * characters otherwise. | |
3485 * Space for the returned name is allocated, must be freed later. | |
3486 * Returns NULL when out of memory. | |
3487 */ | |
3488 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3489 modname( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3490 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3491 char_u *ext, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3492 int prepend_dot) // may prepend a '.' to file name |
7 | 3493 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3494 return buf_modname((curbuf->b_p_sn || curbuf->b_shortname), |
7 | 3495 fname, ext, prepend_dot); |
3496 } | |
3497 | |
3498 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3499 buf_modname( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3500 int shortname, // use 8.3 file name |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3501 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3502 char_u *ext, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3503 int prepend_dot) // may prepend a '.' to file name |
7 | 3504 { |
3505 char_u *retval; | |
3506 char_u *s; | |
3507 char_u *e; | |
3508 char_u *ptr; | |
3509 int fnamelen, extlen; | |
3510 | |
3511 extlen = (int)STRLEN(ext); | |
3512 | |
3513 /* | |
3514 * If there is no file name we must get the name of the current directory | |
3515 * (we need the full path in case :cd is used). | |
3516 */ | |
3517 if (fname == NULL || *fname == NUL) | |
3518 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16754
diff
changeset
|
3519 retval = alloc(MAXPATHL + extlen + 3); |
7 | 3520 if (retval == NULL) |
3521 return NULL; | |
3522 if (mch_dirname(retval, MAXPATHL) == FAIL || | |
3523 (fnamelen = (int)STRLEN(retval)) == 0) | |
3524 { | |
3525 vim_free(retval); | |
3526 return NULL; | |
3527 } | |
39 | 3528 if (!after_pathsep(retval, retval + fnamelen)) |
7 | 3529 { |
3530 retval[fnamelen++] = PATHSEP; | |
3531 retval[fnamelen] = NUL; | |
3532 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3533 prepend_dot = FALSE; // nothing to prepend a dot to |
7 | 3534 } |
3535 else | |
3536 { | |
3537 fnamelen = (int)STRLEN(fname); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16754
diff
changeset
|
3538 retval = alloc(fnamelen + extlen + 3); |
7 | 3539 if (retval == NULL) |
3540 return NULL; | |
3541 STRCPY(retval, fname); | |
3542 #ifdef VMS | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3543 vms_remove_version(retval); // we do not need versions here |
7 | 3544 #endif |
3545 } | |
3546 | |
3547 /* | |
3548 * search backwards until we hit a '/', '\' or ':' replacing all '.' | |
3549 * by '_' for MSDOS or when shortname option set and ext starts with a dot. | |
3550 * Then truncate what is after the '/', '\' or ':' to 8 characters for | |
3551 * MSDOS and 26 characters for AMIGA, a lot more for UNIX. | |
3552 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3553 for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr)) |
7 | 3554 { |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15776
diff
changeset
|
3555 if (*ext == '.' && shortname) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3556 if (*ptr == '.') // replace '.' by '_' |
7 | 3557 *ptr = '_'; |
3558 if (vim_ispathsep(*ptr)) | |
391 | 3559 { |
3560 ++ptr; | |
7 | 3561 break; |
391 | 3562 } |
3563 } | |
7 | 3564 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3565 // the file name has at most BASENAMELEN characters. |
7 | 3566 if (STRLEN(ptr) > (unsigned)BASENAMELEN) |
3567 ptr[BASENAMELEN] = '\0'; | |
3568 | |
3569 s = ptr + STRLEN(ptr); | |
3570 | |
3571 /* | |
3572 * For 8.3 file names we may have to reduce the length. | |
3573 */ | |
3574 if (shortname) | |
3575 { | |
3576 /* | |
3577 * If there is no file name, or the file name ends in '/', and the | |
3578 * extension starts with '.', put a '_' before the dot, because just | |
3579 * ".ext" is invalid. | |
3580 */ | |
3581 if (fname == NULL || *fname == NUL | |
3582 || vim_ispathsep(fname[STRLEN(fname) - 1])) | |
3583 { | |
3584 if (*ext == '.') | |
3585 *s++ = '_'; | |
3586 } | |
3587 /* | |
3588 * If the extension starts with '.', truncate the base name at 8 | |
3589 * characters | |
3590 */ | |
3591 else if (*ext == '.') | |
3592 { | |
1877 | 3593 if ((size_t)(s - ptr) > (size_t)8) |
7 | 3594 { |
3595 s = ptr + 8; | |
3596 *s = '\0'; | |
3597 } | |
3598 } | |
3599 /* | |
3600 * If the extension doesn't start with '.', and the file name | |
3601 * doesn't have an extension yet, append a '.' | |
3602 */ | |
3603 else if ((e = vim_strchr(ptr, '.')) == NULL) | |
3604 *s++ = '.'; | |
3605 /* | |
3606 * If the extension doesn't start with '.', and there already is an | |
1201 | 3607 * extension, it may need to be truncated |
7 | 3608 */ |
3609 else if ((int)STRLEN(e) + extlen > 4) | |
3610 s = e + 4 - extlen; | |
3611 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3612 #ifdef MSWIN |
7 | 3613 /* |
3614 * If there is no file name, and the extension starts with '.', put a | |
3615 * '_' before the dot, because just ".ext" may be invalid if it's on a | |
3616 * FAT partition, and on HPFS it doesn't matter. | |
3617 */ | |
3618 else if ((fname == NULL || *fname == NUL) && *ext == '.') | |
3619 *s++ = '_'; | |
3620 #endif | |
3621 | |
3622 /* | |
1651 | 3623 * Append the extension. |
7 | 3624 * ext can start with '.' and cannot exceed 3 more characters. |
3625 */ | |
3626 STRCPY(s, ext); | |
3627 | |
3628 /* | |
3629 * Prepend the dot. | |
3630 */ | |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15776
diff
changeset
|
3631 if (prepend_dot && !shortname && *(e = gettail(retval)) != '.') |
7 | 3632 { |
1620 | 3633 STRMOVE(e + 1, e); |
7 | 3634 *e = '.'; |
3635 } | |
3636 | |
3637 /* | |
3638 * Check that, after appending the extension, the file name is really | |
3639 * different. | |
3640 */ | |
3641 if (fname != NULL && STRCMP(fname, retval) == 0) | |
3642 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3643 // we search for a character that can be replaced by '_' |
7 | 3644 while (--s >= ptr) |
3645 { | |
3646 if (*s != '_') | |
3647 { | |
3648 *s = '_'; | |
3649 break; | |
3650 } | |
3651 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3652 if (s < ptr) // fname was "________.<ext>", how tricky! |
7 | 3653 *ptr = 'v'; |
3654 } | |
3655 return retval; | |
3656 } | |
3657 | |
3658 /* | |
3659 * Like fgets(), but if the file line is too long, it is truncated and the | |
3660 * rest of the line is thrown away. Returns TRUE for end-of-file. | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12863
diff
changeset
|
3661 * If the line is truncated then buf[size - 2] will not be NUL. |
7 | 3662 */ |
3663 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3664 vim_fgets(char_u *buf, int size, FILE *fp) |
7 | 3665 { |
3666 char *eof; | |
3667 #define FGETS_SIZE 200 | |
3668 char tbuf[FGETS_SIZE]; | |
3669 | |
3670 buf[size - 2] = NUL; | |
3671 eof = fgets((char *)buf, size, fp); | |
3672 if (buf[size - 2] != NUL && buf[size - 2] != '\n') | |
3673 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3674 buf[size - 1] = NUL; // Truncate the line |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3675 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3676 // Now throw away the rest of the line: |
7 | 3677 do |
3678 { | |
3679 tbuf[FGETS_SIZE - 2] = NUL; | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
3680 vim_ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp); |
7 | 3681 } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); |
3682 } | |
3683 return (eof == NULL); | |
3684 } | |
3685 | |
3686 /* | |
3687 * rename() only works if both files are on the same file system, this | |
3688 * function will (attempts to?) copy the file across if rename fails -- webb | |
3689 * Return -1 for failure, 0 for success. | |
3690 */ | |
3691 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3692 vim_rename(char_u *from, char_u *to) |
7 | 3693 { |
3694 int fd_in; | |
3695 int fd_out; | |
3696 int n; | |
3697 char *errmsg = NULL; | |
3698 char *buffer; | |
3699 #ifdef AMIGA | |
3700 BPTR flock; | |
3701 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3702 stat_T st; |
194 | 3703 long perm; |
199 | 3704 #ifdef HAVE_ACL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3705 vim_acl_T acl; // ACL from original file |
199 | 3706 #endif |
1779 | 3707 int use_tmp_file = FALSE; |
7 | 3708 |
3709 /* | |
1779 | 3710 * When the names are identical, there is nothing to do. When they refer |
3711 * to the same file (ignoring case and slash/backslash differences) but | |
3712 * the file name differs we need to go through a temp file. | |
7 | 3713 */ |
3714 if (fnamecmp(from, to) == 0) | |
1779 | 3715 { |
4242 | 3716 if (p_fic && STRCMP(gettail(from), gettail(to)) != 0) |
1779 | 3717 use_tmp_file = TRUE; |
3718 else | |
3719 return 0; | |
3720 } | |
7 | 3721 |
3722 /* | |
3723 * Fail if the "from" file doesn't exist. Avoids that "to" is deleted. | |
3724 */ | |
3725 if (mch_stat((char *)from, &st) < 0) | |
3726 return -1; | |
3727 | |
1778 | 3728 #ifdef UNIX |
3729 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3730 stat_T st_to; |
1778 | 3731 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3732 // It's possible for the source and destination to be the same file. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3733 // This happens when "from" and "to" differ in case and are on a FAT32 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3734 // filesystem. In that case go through a temp file name. |
1778 | 3735 if (mch_stat((char *)to, &st_to) >= 0 |
3736 && st.st_dev == st_to.st_dev | |
3737 && st.st_ino == st_to.st_ino) | |
1779 | 3738 use_tmp_file = TRUE; |
3739 } | |
3740 #endif | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3741 #ifdef MSWIN |
2793 | 3742 { |
3743 BY_HANDLE_FILE_INFORMATION info1, info2; | |
3744 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3745 // It's possible for the source and destination to be the same file. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3746 // In that case go through a temp file name. This makes rename("foo", |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3747 // "./foo") a no-op (in a complicated way). |
2793 | 3748 if (win32_fileinfo(from, &info1) == FILEINFO_OK |
3749 && win32_fileinfo(to, &info2) == FILEINFO_OK | |
3750 && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber | |
3751 && info1.nFileIndexHigh == info2.nFileIndexHigh | |
3752 && info1.nFileIndexLow == info2.nFileIndexLow) | |
3753 use_tmp_file = TRUE; | |
3754 } | |
3755 #endif | |
1779 | 3756 |
3757 if (use_tmp_file) | |
3758 { | |
3759 char tempname[MAXPATHL + 1]; | |
3760 | |
3761 /* | |
3762 * Find a name that doesn't exist and is in the same directory. | |
3763 * Rename "from" to "tempname" and then rename "tempname" to "to". | |
3764 */ | |
3765 if (STRLEN(from) >= MAXPATHL - 5) | |
3766 return -1; | |
3767 STRCPY(tempname, from); | |
3768 for (n = 123; n < 99999; ++n) | |
3769 { | |
3770 sprintf((char *)gettail((char_u *)tempname), "%d", n); | |
3771 if (mch_stat(tempname, &st) < 0) | |
3772 { | |
3773 if (mch_rename((char *)from, tempname) == 0) | |
1778 | 3774 { |
1779 | 3775 if (mch_rename(tempname, (char *)to) == 0) |
3776 return 0; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3777 // Strange, the second step failed. Try moving the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3778 // file back and return failure. |
24578
096f2b8d9cf4
patch 8.2.2828: Coverity complains about not checking rename() return value
Bram Moolenaar <Bram@vim.org>
parents:
23503
diff
changeset
|
3779 (void)mch_rename(tempname, (char *)from); |
1778 | 3780 return -1; |
3781 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3782 // If it fails for one temp name it will most likely fail |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3783 // for any temp name, give up. |
1779 | 3784 return -1; |
3785 } | |
3786 } | |
3787 return -1; | |
1778 | 3788 } |
3789 | |
7 | 3790 /* |
3791 * Delete the "to" file, this is required on some systems to make the | |
3792 * mch_rename() work, on other systems it makes sure that we don't have | |
3793 * two files when the mch_rename() fails. | |
3794 */ | |
3795 | |
3796 #ifdef AMIGA | |
3797 /* | |
3798 * With MSDOS-compatible filesystems (crossdos, messydos) it is possible | |
3799 * that the name of the "to" file is the same as the "from" file, even | |
1201 | 3800 * though the names are different. To avoid the chance of accidentally |
7 | 3801 * deleting the "from" file (horror!) we lock it during the remove. |
3802 * | |
3803 * When used for making a backup before writing the file: This should not | |
3804 * happen with ":w", because startscript() should detect this problem and | |
3805 * set buf->b_shortname, causing modname() to return a correct ".bak" file | |
3806 * name. This problem does exist with ":w filename", but then the | |
3807 * original file will be somewhere else so the backup isn't really | |
3808 * important. If autoscripting is off the rename may fail. | |
3809 */ | |
3810 flock = Lock((UBYTE *)from, (long)ACCESS_READ); | |
3811 #endif | |
3812 mch_remove(to); | |
3813 #ifdef AMIGA | |
3814 if (flock) | |
3815 UnLock(flock); | |
3816 #endif | |
3817 | |
3818 /* | |
3819 * First try a normal rename, return if it works. | |
3820 */ | |
3821 if (mch_rename((char *)from, (char *)to) == 0) | |
3822 return 0; | |
3823 | |
3824 /* | |
3825 * Rename() failed, try copying the file. | |
3826 */ | |
194 | 3827 perm = mch_getperm(from); |
199 | 3828 #ifdef HAVE_ACL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3829 // For systems that support ACL: get the ACL from the original file. |
199 | 3830 acl = mch_get_acl(from); |
3831 #endif | |
7 | 3832 fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); |
3833 if (fd_in == -1) | |
1651 | 3834 { |
3835 #ifdef HAVE_ACL | |
3836 mch_free_acl(acl); | |
3837 #endif | |
7 | 3838 return -1; |
1651 | 3839 } |
194 | 3840 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3841 // Create the new file with same permissions as the original. |
557 | 3842 fd_out = mch_open((char *)to, |
3843 O_CREAT|O_EXCL|O_WRONLY|O_EXTRA|O_NOFOLLOW, (int)perm); | |
7 | 3844 if (fd_out == -1) |
3845 { | |
3846 close(fd_in); | |
1651 | 3847 #ifdef HAVE_ACL |
3848 mch_free_acl(acl); | |
3849 #endif | |
7 | 3850 return -1; |
3851 } | |
3852 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3853 buffer = alloc(WRITEBUFSIZE); |
7 | 3854 if (buffer == NULL) |
3855 { | |
1651 | 3856 close(fd_out); |
7 | 3857 close(fd_in); |
1651 | 3858 #ifdef HAVE_ACL |
3859 mch_free_acl(acl); | |
3860 #endif | |
7 | 3861 return -1; |
3862 } | |
3863 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3864 while ((n = read_eintr(fd_in, buffer, WRITEBUFSIZE)) > 0) |
2664 | 3865 if (write_eintr(fd_out, buffer, n) != n) |
7 | 3866 { |
3867 errmsg = _("E208: Error writing to \"%s\""); | |
3868 break; | |
3869 } | |
3870 | |
3871 vim_free(buffer); | |
3872 close(fd_in); | |
3873 if (close(fd_out) < 0) | |
3874 errmsg = _("E209: Error closing \"%s\""); | |
3875 if (n < 0) | |
3876 { | |
3877 errmsg = _("E210: Error reading \"%s\""); | |
3878 to = from; | |
3879 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3880 #ifndef UNIX // for Unix mch_open() already set the permission |
194 | 3881 mch_setperm(to, perm); |
570 | 3882 #endif |
199 | 3883 #ifdef HAVE_ACL |
3884 mch_set_acl(to, acl); | |
1651 | 3885 mch_free_acl(acl); |
199 | 3886 #endif |
5788 | 3887 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) |
5483 | 3888 mch_copy_sec(from, to); |
5479 | 3889 #endif |
7 | 3890 if (errmsg != NULL) |
3891 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3892 semsg(errmsg, to); |
7 | 3893 return -1; |
3894 } | |
3895 mch_remove(from); | |
3896 return 0; | |
3897 } | |
3898 | |
3899 static int already_warned = FALSE; | |
3900 | |
3901 /* | |
3902 * Check if any not hidden buffer has been changed. | |
3903 * Postpone the check if there are characters in the stuff buffer, a global | |
3904 * command is being executed, a mapping is being executed or an autocommand is | |
3905 * busy. | |
3906 * Returns TRUE if some message was written (screen should be redrawn and | |
3907 * cursor positioned). | |
3908 */ | |
3909 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3910 check_timestamps( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3911 int focus) // called for GUI focus event |
7 | 3912 { |
3913 buf_T *buf; | |
3914 int didit = 0; | |
3915 int n; | |
3916 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3917 // Don't check timestamps while system() or another low-level function may |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3918 // cause us to lose and gain focus. |
7 | 3919 if (no_check_timestamps > 0) |
3920 return FALSE; | |
3921 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3922 // Avoid doing a check twice. The OK/Reload dialog can cause a focus |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3923 // event and we would keep on checking if the file is steadily growing. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3924 // Do check again after typing something. |
7 | 3925 if (focus && did_check_timestamps) |
3926 { | |
3927 need_check_timestamps = TRUE; | |
3928 return FALSE; | |
3929 } | |
3930 | |
3931 if (!stuff_empty() || global_busy || !typebuf_typed() | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3932 || autocmd_busy || curbuf_lock > 0 || allbuf_lock > 0) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3933 need_check_timestamps = TRUE; // check later |
7 | 3934 else |
3935 { | |
3936 ++no_wait_return; | |
3937 did_check_timestamps = TRUE; | |
3938 already_warned = FALSE; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
3939 FOR_ALL_BUFFERS(buf) |
7 | 3940 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3941 // Only check buffers in a window. |
7 | 3942 if (buf->b_nwindows > 0) |
3943 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3944 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3945 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3946 set_bufref(&bufref, buf); |
7 | 3947 n = buf_check_timestamp(buf, focus); |
3948 if (didit < n) | |
3949 didit = n; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3950 if (n > 0 && !bufref_valid(&bufref)) |
7 | 3951 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3952 // Autocommands have removed the buffer, start at the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3953 // first one again. |
7 | 3954 buf = firstbuf; |
3955 continue; | |
3956 } | |
3957 } | |
3958 } | |
3959 --no_wait_return; | |
3960 need_check_timestamps = FALSE; | |
3961 if (need_wait_return && didit == 2) | |
3962 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3963 // make sure msg isn't overwritten |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
3964 msg_puts("\n"); |
7 | 3965 out_flush(); |
3966 } | |
3967 } | |
3968 return didit; | |
3969 } | |
3970 | |
3971 /* | |
3972 * Move all the lines from buffer "frombuf" to buffer "tobuf". | |
3973 * Return OK or FAIL. When FAIL "tobuf" is incomplete and/or "frombuf" is not | |
3974 * empty. | |
3975 */ | |
3976 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3977 move_lines(buf_T *frombuf, buf_T *tobuf) |
7 | 3978 { |
3979 buf_T *tbuf = curbuf; | |
3980 int retval = OK; | |
3981 linenr_T lnum; | |
3982 char_u *p; | |
3983 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3984 // Copy the lines in "frombuf" to "tobuf". |
7 | 3985 curbuf = tobuf; |
3986 for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) | |
3987 { | |
3988 p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); | |
3989 if (p == NULL || ml_append(lnum - 1, p, 0, FALSE) == FAIL) | |
3990 { | |
3991 vim_free(p); | |
3992 retval = FAIL; | |
3993 break; | |
3994 } | |
3995 vim_free(p); | |
3996 } | |
3997 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3998 // Delete all the lines in "frombuf". |
7 | 3999 if (retval != FAIL) |
4000 { | |
4001 curbuf = frombuf; | |
1055 | 4002 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20311
diff
changeset
|
4003 if (ml_delete(lnum) == FAIL) |
7 | 4004 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4005 // Oops! We could try putting back the saved lines, but that |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4006 // might fail again... |
7 | 4007 retval = FAIL; |
4008 break; | |
4009 } | |
4010 } | |
4011 | |
4012 curbuf = tbuf; | |
4013 return retval; | |
4014 } | |
4015 | |
4016 /* | |
4017 * Check if buffer "buf" has been changed. | |
4018 * Also check if the file for a new buffer unexpectedly appeared. | |
4019 * return 1 if a changed buffer was found. | |
4020 * return 2 if a message has been displayed. | |
4021 * return 0 otherwise. | |
4022 */ | |
4023 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4024 buf_check_timestamp( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4025 buf_T *buf, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4026 int focus UNUSED) // called for GUI focus event |
7 | 4027 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
4028 stat_T st; |
7 | 4029 int stat_res; |
4030 int retval = 0; | |
4031 char_u *path; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4032 char *tbuf; |
7 | 4033 char *mesg = NULL; |
188 | 4034 char *mesg2 = ""; |
7 | 4035 int helpmesg = FALSE; |
4036 int reload = FALSE; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4037 char *reason; |
7 | 4038 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) |
4039 int can_reload = FALSE; | |
4040 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
4041 off_T orig_size = buf->b_orig_size; |
7 | 4042 int orig_mode = buf->b_orig_mode; |
4043 #ifdef FEAT_GUI | |
4044 int save_mouse_correct = need_mouse_correct; | |
4045 #endif | |
4046 static int busy = FALSE; | |
179 | 4047 int n; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4048 #ifdef FEAT_EVAL |
179 | 4049 char_u *s; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4050 #endif |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4051 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4052 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4053 set_bufref(&bufref, buf); |
7 | 4054 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4055 // If there is no file name, the buffer is not loaded, 'buftype' is |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4056 // set, we are in the middle of a save or being called recursively: ignore |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4057 // this buffer. |
7 | 4058 if (buf->b_ffname == NULL |
4059 || buf->b_ml.ml_mfp == NULL | |
14433
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14290
diff
changeset
|
4060 || !bt_normal(buf) |
7 | 4061 || buf->b_saving |
4062 || busy | |
33 | 4063 #ifdef FEAT_NETBEANS_INTG |
4064 || isNetbeansBuffer(buf) | |
4065 #endif | |
12064
407a475c67fd
patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
4066 #ifdef FEAT_TERMINAL |
407a475c67fd
patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
4067 || buf->b_term != NULL |
407a475c67fd
patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
4068 #endif |
7 | 4069 ) |
4070 return 0; | |
4071 | |
4072 if ( !(buf->b_flags & BF_NOTEDITED) | |
4073 && buf->b_mtime != 0 | |
4074 && ((stat_res = mch_stat((char *)buf->b_ffname, &st)) < 0 | |
4075 || time_differs((long)st.st_mtime, buf->b_mtime) | |
5863 | 4076 || st.st_size != buf->b_orig_size |
7 | 4077 #ifdef HAVE_ST_MODE |
4078 || (int)st.st_mode != buf->b_orig_mode | |
4079 #else | |
4080 || mch_getperm(buf->b_ffname) != buf->b_orig_mode | |
4081 #endif | |
4082 )) | |
4083 { | |
17565
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4084 long prev_b_mtime = buf->b_mtime; |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4085 |
7 | 4086 retval = 1; |
4087 | |
14290
977cab3d5474
patch 8.1.0161: buffer not updated with 'autoread' set if file was deleted
Christian Brabandt <cb@256bit.org>
parents:
14157
diff
changeset
|
4088 // set b_mtime to stop further warnings (e.g., when executing |
977cab3d5474
patch 8.1.0161: buffer not updated with 'autoread' set if file was deleted
Christian Brabandt <cb@256bit.org>
parents:
14157
diff
changeset
|
4089 // FileChangedShell autocmd) |
7 | 4090 if (stat_res < 0) |
4091 { | |
16754
8b92f3fea477
patch 8.1.1379: filechanged test hangs
Bram Moolenaar <Bram@vim.org>
parents:
16752
diff
changeset
|
4092 // Check the file again later to see if it re-appears. |
8b92f3fea477
patch 8.1.1379: filechanged test hangs
Bram Moolenaar <Bram@vim.org>
parents:
16752
diff
changeset
|
4093 buf->b_mtime = -1; |
7 | 4094 buf->b_orig_size = 0; |
4095 buf->b_orig_mode = 0; | |
4096 } | |
4097 else | |
4098 buf_store_time(buf, &st, buf->b_ffname); | |
4099 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4100 // Don't do anything for a directory. Might contain the file |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4101 // explorer. |
7 | 4102 if (mch_isdir(buf->b_fname)) |
4103 ; | |
4104 | |
4105 /* | |
4106 * If 'autoread' is set, the buffer has no changes and the file still | |
4107 * exists, reload the buffer. Use the buffer-local option value if it | |
4108 * was set, the global option value otherwise. | |
4109 */ | |
4110 else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) | |
4111 && !bufIsChanged(buf) && stat_res >= 0) | |
4112 reload = TRUE; | |
4113 else | |
4114 { | |
179 | 4115 if (stat_res < 0) |
4116 reason = "deleted"; | |
4117 else if (bufIsChanged(buf)) | |
4118 reason = "conflict"; | |
15634
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4119 /* |
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4120 * Check if the file contents really changed to avoid giving a |
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4121 * warning when only the timestamp was set (e.g., checked out of |
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4122 * CVS). Always warn when the buffer was changed. |
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4123 */ |
179 | 4124 else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) |
4125 reason = "changed"; | |
4126 else if (orig_mode != buf->b_orig_mode) | |
4127 reason = "mode"; | |
4128 else | |
4129 reason = "time"; | |
4130 | |
7 | 4131 /* |
4132 * Only give the warning if there are no FileChangedShell | |
4133 * autocommands. | |
4134 * Avoid being called recursively by setting "busy". | |
4135 */ | |
4136 busy = TRUE; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4137 #ifdef FEAT_EVAL |
179 | 4138 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1); |
4139 set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4140 #endif |
1834 | 4141 ++allbuf_lock; |
7 | 4142 n = apply_autocmds(EVENT_FILECHANGEDSHELL, |
4143 buf->b_fname, buf->b_fname, FALSE, buf); | |
1834 | 4144 --allbuf_lock; |
7 | 4145 busy = FALSE; |
4146 if (n) | |
4147 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4148 if (!bufref_valid(&bufref)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4149 emsg(_("E246: FileChangedShell autocommand deleted buffer")); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4150 #ifdef FEAT_EVAL |
179 | 4151 s = get_vim_var_str(VV_FCS_CHOICE); |
4152 if (STRCMP(s, "reload") == 0 && *reason != 'd') | |
4153 reload = TRUE; | |
4154 else if (STRCMP(s, "ask") == 0) | |
4155 n = FALSE; | |
4156 else | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4157 #endif |
179 | 4158 return 2; |
7 | 4159 } |
179 | 4160 if (!n) |
7 | 4161 { |
179 | 4162 if (*reason == 'd') |
17565
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4163 { |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4164 // Only give the message once. |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4165 if (prev_b_mtime != -1) |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4166 mesg = _("E211: File \"%s\" no longer available"); |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4167 } |
7 | 4168 else |
4169 { | |
4170 helpmesg = TRUE; | |
4171 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
4172 can_reload = TRUE; | |
4173 #endif | |
179 | 4174 if (reason[2] == 'n') |
4175 { | |
7 | 4176 mesg = _("W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well"); |
179 | 4177 mesg2 = _("See \":help W12\" for more info."); |
4178 } | |
4179 else if (reason[1] == 'h') | |
4180 { | |
7 | 4181 mesg = _("W11: Warning: File \"%s\" has changed since editing started"); |
179 | 4182 mesg2 = _("See \":help W11\" for more info."); |
4183 } | |
4184 else if (*reason == 'm') | |
4185 { | |
7 | 4186 mesg = _("W16: Warning: Mode of file \"%s\" has changed since editing started"); |
179 | 4187 mesg2 = _("See \":help W16\" for more info."); |
4188 } | |
1913 | 4189 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4190 // Only timestamp changed, store it to avoid a warning |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4191 // in check_mtime() later. |
1913 | 4192 buf->b_mtime_read = buf->b_mtime; |
7 | 4193 } |
4194 } | |
4195 } | |
4196 | |
4197 } | |
4198 else if ((buf->b_flags & BF_NEW) && !(buf->b_flags & BF_NEW_W) | |
4199 && vim_fexists(buf->b_ffname)) | |
4200 { | |
4201 retval = 1; | |
4202 mesg = _("W13: Warning: File \"%s\" has been created after editing started"); | |
4203 buf->b_flags |= BF_NEW_W; | |
4204 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
4205 can_reload = TRUE; | |
4206 #endif | |
4207 } | |
4208 | |
4209 if (mesg != NULL) | |
4210 { | |
4211 path = home_replace_save(buf, buf->b_fname); | |
4212 if (path != NULL) | |
4213 { | |
179 | 4214 if (!helpmesg) |
7 | 4215 mesg2 = ""; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4216 tbuf = alloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4217 sprintf(tbuf, mesg, path); |
1848 | 4218 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4219 // Set warningmsg here, before the unimportant and output-specific |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4220 // mesg2 has been appended. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4221 set_vim_var_string(VV_WARNINGMSG, (char_u *)tbuf, -1); |
1848 | 4222 #endif |
7 | 4223 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) |
4224 if (can_reload) | |
4225 { | |
4226 if (*mesg2 != NUL) | |
4227 { | |
4228 STRCAT(tbuf, "\n"); | |
4229 STRCAT(tbuf, mesg2); | |
4230 } | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4231 if (do_dialog(VIM_WARNING, (char_u *)_("Warning"), |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4232 (char_u *)tbuf, |
2684 | 4233 (char_u *)_("&OK\n&Load File"), 1, NULL, TRUE) == 2) |
7 | 4234 reload = TRUE; |
4235 } | |
4236 else | |
4237 #endif | |
4238 if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) | |
4239 { | |
4240 if (*mesg2 != NUL) | |
4241 { | |
4242 STRCAT(tbuf, "; "); | |
4243 STRCAT(tbuf, mesg2); | |
4244 } | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4245 emsg(tbuf); |
7 | 4246 retval = 2; |
4247 } | |
4248 else | |
4249 { | |
4250 if (!autocmd_busy) | |
4251 { | |
4252 msg_start(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
4253 msg_puts_attr(tbuf, HL_ATTR(HLF_E) + MSG_HIST); |
7 | 4254 if (*mesg2 != NUL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
4255 msg_puts_attr(mesg2, HL_ATTR(HLF_W) + MSG_HIST); |
7 | 4256 msg_clr_eos(); |
4257 (void)msg_end(); | |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4258 if (emsg_silent == 0 && !in_assert_fails) |
7 | 4259 { |
4260 out_flush(); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4261 #ifdef FEAT_GUI |
7 | 4262 if (!focus) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4263 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4264 // give the user some time to think about it |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
4265 ui_delay(1004L, TRUE); |
7 | 4266 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4267 // don't redraw and erase the message |
7 | 4268 redraw_cmdline = FALSE; |
4269 } | |
4270 } | |
4271 already_warned = TRUE; | |
4272 } | |
4273 | |
4274 vim_free(path); | |
4275 vim_free(tbuf); | |
4276 } | |
4277 } | |
4278 | |
4279 if (reload) | |
3776 | 4280 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4281 // Reload the buffer. |
628 | 4282 buf_reload(buf, orig_mode); |
3776 | 4283 #ifdef FEAT_PERSISTENT_UNDO |
4284 if (buf->b_p_udf && buf->b_ffname != NULL) | |
4285 { | |
4286 char_u hash[UNDO_HASH_SIZE]; | |
4287 buf_T *save_curbuf = curbuf; | |
4288 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4289 // Any existing undo file is unusable, write it now. |
3776 | 4290 curbuf = buf; |
4291 u_compute_hash(hash); | |
4292 u_write_undo(NULL, FALSE, buf, hash); | |
4293 curbuf = save_curbuf; | |
4294 } | |
4295 #endif | |
4296 } | |
7 | 4297 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4298 // Trigger FileChangedShell when the file was changed in any way. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4299 if (bufref_valid(&bufref) && retval != 0) |
765 | 4300 (void)apply_autocmds(EVENT_FILECHANGEDSHELLPOST, |
4301 buf->b_fname, buf->b_fname, FALSE, buf); | |
7 | 4302 #ifdef FEAT_GUI |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4303 // restore this in case an autocommand has set it; it would break |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4304 // 'mousefocus' |
7 | 4305 need_mouse_correct = save_mouse_correct; |
4306 #endif | |
4307 | |
4308 return retval; | |
4309 } | |
4310 | |
311 | 4311 /* |
4312 * Reload a buffer that is already loaded. | |
4313 * Used when the file was changed outside of Vim. | |
628 | 4314 * "orig_mode" is buf->b_orig_mode before the need for reloading was detected. |
4315 * buf->b_orig_mode may have been reset already. | |
311 | 4316 */ |
4317 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4318 buf_reload(buf_T *buf, int orig_mode) |
311 | 4319 { |
4320 exarg_T ea; | |
4321 pos_T old_cursor; | |
4322 linenr_T old_topline; | |
4323 int old_ro = buf->b_p_ro; | |
4324 buf_T *savebuf; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4325 bufref_T bufref; |
311 | 4326 int saved = OK; |
4327 aco_save_T aco; | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4328 int flags = READ_NEW; |
311 | 4329 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4330 // set curwin/curbuf for "buf" and save some things |
311 | 4331 aucmd_prepbuf(&aco, buf); |
4332 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4333 // We only want to read the text from the file, not reset the syntax |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4334 // highlighting, clear marks, diff status, etc. Force the fileformat |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4335 // and encoding to be the same. |
311 | 4336 if (prep_exarg(&ea, buf) == OK) |
4337 { | |
4338 old_cursor = curwin->w_cursor; | |
4339 old_topline = curwin->w_topline; | |
4340 | |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
4341 if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4342 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4343 // Save all the text, so that the reload can be undone. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4344 // Sync first so that this is a separate undo-able action. |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4345 u_sync(FALSE); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4346 saved = u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4347 flags |= READ_KEEP_UNDO; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4348 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4349 |
311 | 4350 /* |
4351 * To behave like when a new file is edited (matters for | |
4352 * BufReadPost autocommands) we first need to delete the current | |
4353 * buffer contents. But if reading the file fails we should keep | |
4354 * the old contents. Can't use memory only, the file might be | |
4355 * too big. Use a hidden buffer to move the buffer contents to. | |
4356 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
4357 if (BUFEMPTY() || saved == FAIL) |
311 | 4358 savebuf = NULL; |
4359 else | |
4360 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4361 // Allocate a buffer without putting it in the buffer list. |
311 | 4362 savebuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4363 set_bufref(&bufref, savebuf); |
837 | 4364 if (savebuf != NULL && buf == curbuf) |
311 | 4365 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4366 // Open the memline. |
311 | 4367 curbuf = savebuf; |
4368 curwin->w_buffer = savebuf; | |
625 | 4369 saved = ml_open(curbuf); |
311 | 4370 curbuf = buf; |
4371 curwin->w_buffer = buf; | |
4372 } | |
837 | 4373 if (savebuf == NULL || saved == FAIL || buf != curbuf |
311 | 4374 || move_lines(buf, savebuf) == FAIL) |
4375 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4376 semsg(_("E462: Could not prepare for reloading \"%s\""), |
311 | 4377 buf->b_fname); |
4378 saved = FAIL; | |
4379 } | |
4380 } | |
4381 | |
4382 if (saved == OK) | |
4383 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4384 curbuf->b_flags |= BF_CHECK_RO; // check for RO again |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4385 keep_filetype = TRUE; // don't detect 'filetype' |
311 | 4386 if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, |
4387 (linenr_T)0, | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
4388 (linenr_T)MAXLNUM, &ea, flags) != OK) |
311 | 4389 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4390 #if defined(FEAT_EVAL) |
311 | 4391 if (!aborting()) |
4392 #endif | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4393 semsg(_("E321: Could not reload \"%s\""), buf->b_fname); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4394 if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) |
311 | 4395 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4396 // Put the text back from the save buffer. First |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4397 // delete any lines that readfile() added. |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
4398 while (!BUFEMPTY()) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20311
diff
changeset
|
4399 if (ml_delete(buf->b_ml.ml_line_count) == FAIL) |
311 | 4400 break; |
4401 (void)move_lines(savebuf, buf); | |
4402 } | |
4403 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4404 else if (buf == curbuf) // "buf" still valid |
311 | 4405 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4406 // Mark the buffer as unmodified and free undo info. |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
4407 unchanged(buf, TRUE, TRUE); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4408 if ((flags & READ_KEEP_UNDO) == 0) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4409 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4410 u_blockfree(buf); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4411 u_clearall(buf); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4412 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4413 else |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
4414 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4415 // Mark all undo states as changed. |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4416 u_unchanged(curbuf); |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
4417 } |
311 | 4418 } |
4419 } | |
4420 vim_free(ea.cmd); | |
4421 | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4422 if (savebuf != NULL && bufref_valid(&bufref)) |
311 | 4423 wipe_buffer(savebuf, FALSE); |
4424 | |
4425 #ifdef FEAT_DIFF | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4426 // Invalidate diff info if necessary. |
837 | 4427 diff_invalidate(curbuf); |
311 | 4428 #endif |
4429 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4430 // Restore the topline and cursor position and check it (lines may |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4431 // have been removed). |
311 | 4432 if (old_topline > curbuf->b_ml.ml_line_count) |
4433 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
4434 else | |
4435 curwin->w_topline = old_topline; | |
4436 curwin->w_cursor = old_cursor; | |
4437 check_cursor(); | |
4438 update_topline(); | |
4439 keep_filetype = FALSE; | |
4440 #ifdef FEAT_FOLDING | |
4441 { | |
1863 | 4442 win_T *wp; |
4443 tabpage_T *tp; | |
311 | 4444 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4445 // Update folds unless they are defined manually. |
1863 | 4446 FOR_ALL_TAB_WINDOWS(tp, wp) |
311 | 4447 if (wp->w_buffer == curwin->w_buffer |
4448 && !foldmethodIsManual(wp)) | |
4449 foldUpdateAll(wp); | |
4450 } | |
4451 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4452 // If the mode didn't change and 'readonly' was set, keep the old |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4453 // value; the user probably used the ":view" command. But don't |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4454 // reset it, might have had a read error. |
311 | 4455 if (orig_mode == curbuf->b_orig_mode) |
4456 curbuf->b_p_ro |= old_ro; | |
4071 | 4457 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4458 // Modelines must override settings done by autocommands. |
4071 | 4459 do_modelines(0); |
311 | 4460 } |
4461 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4462 // restore curwin/curbuf and a few other things |
311 | 4463 aucmd_restbuf(&aco); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4464 // Careful: autocommands may have made "buf" invalid! |
311 | 4465 } |
4466 | |
7 | 4467 void |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
4468 buf_store_time(buf_T *buf, stat_T *st, char_u *fname UNUSED) |
7 | 4469 { |
4470 buf->b_mtime = (long)st->st_mtime; | |
2241
60da25e3aab7
Correct use of long instead of off_t for file size. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
4471 buf->b_orig_size = st->st_size; |
7 | 4472 #ifdef HAVE_ST_MODE |
4473 buf->b_orig_mode = (int)st->st_mode; | |
4474 #else | |
4475 buf->b_orig_mode = mch_getperm(fname); | |
4476 #endif | |
4477 } | |
4478 | |
4479 /* | |
4480 * Adjust the line with missing eol, used for the next write. | |
4481 * Used for do_filter(), when the input lines for the filter are deleted. | |
4482 */ | |
4483 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4484 write_lnum_adjust(linenr_T offset) |
7 | 4485 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4486 if (curbuf->b_no_eol_lnum != 0) // only if there is a missing eol |
2707 | 4487 curbuf->b_no_eol_lnum += offset; |
7 | 4488 } |
4489 | |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4490 // Subfuncions for readdirex() |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4491 #ifdef FEAT_EVAL |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4492 # ifdef MSWIN |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4493 static char_u * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4494 getfpermwfd(WIN32_FIND_DATAW *wfd, char_u *perm) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4495 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4496 stat_T st; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4497 unsigned short st_mode; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4498 DWORD flag = wfd->dwFileAttributes; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4499 WCHAR *wp; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4500 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4501 st_mode = (flag & FILE_ATTRIBUTE_DIRECTORY) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4502 ? (_S_IFDIR | _S_IEXEC) : _S_IFREG; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4503 st_mode |= (flag & FILE_ATTRIBUTE_READONLY) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4504 ? _S_IREAD : (_S_IREAD | _S_IWRITE); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4505 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4506 wp = wcsrchr(wfd->cFileName, L'.'); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4507 if (wp != NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4508 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4509 if (_wcsicmp(wp, L".exe") == 0 || |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4510 _wcsicmp(wp, L".com") == 0 || |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4511 _wcsicmp(wp, L".cmd") == 0 || |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4512 _wcsicmp(wp, L".bat") == 0) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4513 st_mode |= _S_IEXEC; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4514 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4515 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4516 // Copy user bits to group/other. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4517 st_mode |= (st_mode & 0700) >> 3; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4518 st_mode |= (st_mode & 0700) >> 6; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4519 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4520 st.st_mode = st_mode; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4521 return getfpermst(&st, perm); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4522 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4523 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4524 static char_u * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4525 getftypewfd(WIN32_FIND_DATAW *wfd) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4526 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4527 DWORD flag = wfd->dwFileAttributes; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4528 DWORD tag = wfd->dwReserved0; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4529 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4530 if (flag & FILE_ATTRIBUTE_REPARSE_POINT) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4531 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4532 if (tag == IO_REPARSE_TAG_MOUNT_POINT) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4533 return (char_u*)"junction"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4534 else if (tag == IO_REPARSE_TAG_SYMLINK) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4535 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4536 if (flag & FILE_ATTRIBUTE_DIRECTORY) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4537 return (char_u*)"linkd"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4538 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4539 return (char_u*)"link"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4540 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4541 return (char_u*)"reparse"; // unknown reparse point type |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4542 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4543 if (flag & FILE_ATTRIBUTE_DIRECTORY) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4544 return (char_u*)"dir"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4545 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4546 return (char_u*)"file"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4547 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4548 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4549 static dict_T * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4550 create_readdirex_item(WIN32_FIND_DATAW *wfd) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4551 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4552 dict_T *item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4553 char_u *p; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4554 varnumber_T size, time; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4555 char_u permbuf[] = "---------"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4556 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4557 item = dict_alloc(); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4558 if (item == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4559 return NULL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4560 item->dv_refcount++; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4561 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4562 p = utf16_to_enc(wfd->cFileName, NULL); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4563 if (p == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4564 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4565 if (dict_add_string(item, "name", p) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4566 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4567 vim_free(p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4568 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4569 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4570 vim_free(p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4571 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4572 size = (((varnumber_T)wfd->nFileSizeHigh) << 32) | wfd->nFileSizeLow; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4573 if (dict_add_number(item, "size", size) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4574 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4575 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4576 // Convert FILETIME to unix time. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4577 time = (((((varnumber_T)wfd->ftLastWriteTime.dwHighDateTime) << 32) | |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4578 wfd->ftLastWriteTime.dwLowDateTime) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4579 - 116444736000000000) / 10000000; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4580 if (dict_add_number(item, "time", time) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4581 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4582 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4583 if (dict_add_string(item, "type", getftypewfd(wfd)) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4584 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4585 if (dict_add_string(item, "perm", getfpermwfd(wfd, permbuf)) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4586 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4587 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4588 if (dict_add_string(item, "user", (char_u*)"") == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4589 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4590 if (dict_add_string(item, "group", (char_u*)"") == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4591 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4592 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4593 return item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4594 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4595 theend: |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4596 dict_unref(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4597 return NULL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4598 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4599 # else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4600 static dict_T * |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4601 create_readdirex_item(char_u *path, char_u *name) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4602 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4603 dict_T *item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4604 char *p; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4605 size_t len; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4606 stat_T st; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4607 int ret, link = FALSE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4608 varnumber_T size; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4609 char_u permbuf[] = "---------"; |
20790
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4610 char_u *q = NULL; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4611 struct passwd *pw; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4612 struct group *gr; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4613 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4614 item = dict_alloc(); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4615 if (item == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4616 return NULL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4617 item->dv_refcount++; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4618 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4619 len = STRLEN(path) + 1 + STRLEN(name) + 1; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4620 p = alloc(len); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4621 if (p == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4622 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4623 vim_snprintf(p, len, "%s/%s", path, name); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4624 ret = mch_lstat(p, &st); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4625 if (ret >= 0 && S_ISLNK(st.st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4626 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4627 link = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4628 ret = mch_stat(p, &st); |
20790
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4629 if (ret < 0) |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4630 q = (char_u*)"link"; |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4631 |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4632 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4633 vim_free(p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4634 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4635 if (dict_add_string(item, "name", name) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4636 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4637 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4638 if (ret >= 0) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4639 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4640 size = (varnumber_T)st.st_size; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4641 if (S_ISDIR(st.st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4642 size = 0; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4643 // non-perfect check for overflow |
20669
2407ffaefc02
patch 8.2.0888: readdirex() returns size -2 for a directory
Bram Moolenaar <Bram@vim.org>
parents:
20643
diff
changeset
|
4644 else if ((off_T)size != (off_T)st.st_size) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4645 size = -2; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4646 if (dict_add_number(item, "size", size) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4647 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4648 if (dict_add_number(item, "time", (varnumber_T)st.st_mtime) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4649 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4650 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4651 if (link) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4652 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4653 if (S_ISDIR(st.st_mode)) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4654 q = (char_u*)"linkd"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4655 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4656 q = (char_u*)"link"; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4657 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4658 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4659 q = getftypest(&st); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4660 if (dict_add_string(item, "type", q) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4661 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4662 if (dict_add_string(item, "perm", getfpermst(&st, permbuf)) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4663 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4664 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4665 pw = getpwuid(st.st_uid); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4666 if (pw == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4667 q = (char_u*)""; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4668 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4669 q = (char_u*)pw->pw_name; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4670 if (dict_add_string(item, "user", q) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4671 goto theend; |
23503
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
4672 # if !defined(VMS) || (defined(VMS) && defined(HAVE_XOS_R_H)) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4673 gr = getgrgid(st.st_gid); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4674 if (gr == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4675 q = (char_u*)""; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4676 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4677 q = (char_u*)gr->gr_name; |
23503
49d866e9b439
patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents:
23467
diff
changeset
|
4678 # endif |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4679 if (dict_add_string(item, "group", q) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4680 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4681 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4682 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4683 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4684 if (dict_add_number(item, "size", -1) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4685 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4686 if (dict_add_number(item, "time", -1) == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4687 goto theend; |
20790
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4688 if (dict_add_string(item, "type", q == NULL ? (char_u*)"" : q) == FAIL) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4689 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4690 if (dict_add_string(item, "perm", (char_u*)"") == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4691 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4692 if (dict_add_string(item, "user", (char_u*)"") == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4693 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4694 if (dict_add_string(item, "group", (char_u*)"") == FAIL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4695 goto theend; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4696 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4697 return item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4698 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4699 theend: |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4700 dict_unref(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4701 return NULL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4702 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4703 # endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4704 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4705 static int |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4706 compare_readdirex_item(const void *p1, const void *p2) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4707 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4708 char_u *name1, *name2; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4709 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4710 name1 = dict_get_string(*(dict_T**)p1, (char_u*)"name", FALSE); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4711 name2 = dict_get_string(*(dict_T**)p2, (char_u*)"name", FALSE); |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4712 if (readdirex_sort == READDIR_SORT_BYTE) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4713 return STRCMP(name1, name2); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4714 else if (readdirex_sort == READDIR_SORT_IC) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4715 return STRICMP(name1, name2); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4716 else |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4717 return STRCOLL(name1, name2); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4718 } |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4719 |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4720 static int |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4721 compare_readdir_item(const void *s1, const void *s2) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4722 { |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4723 if (readdirex_sort == READDIR_SORT_BYTE) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4724 return STRCMP(*(char **)s1, *(char **)s2); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4725 else if (readdirex_sort == READDIR_SORT_IC) |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4726 return STRICMP(*(char **)s1, *(char **)s2); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4727 else |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4728 return STRCOLL(*(char **)s1, *(char **)s2); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4729 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4730 #endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4731 |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4732 #if defined(TEMPDIRNAMES) || defined(FEAT_EVAL) || defined(PROTO) |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4733 /* |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4734 * Core part of "readdir()" and "readdirex()" function. |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4735 * Retrieve the list of files/directories of "path" into "gap". |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4736 * If "withattr" is TRUE, retrieve the names and their attributes. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4737 * If "withattr" is FALSE, retrieve the names only. |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4738 * Return OK for success, FAIL for failure. |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4739 */ |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4740 int |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4741 readdir_core( |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4742 garray_T *gap, |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4743 char_u *path, |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4744 int withattr UNUSED, |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4745 void *context, |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4746 int (*checkitem)(void *context, void *item), |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4747 int sort) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4748 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4749 int failed = FALSE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4750 char_u *p; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4751 # ifdef MSWIN |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4752 char_u *buf; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4753 int ok; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4754 HANDLE hFind = INVALID_HANDLE_VALUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4755 WIN32_FIND_DATAW wfd; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4756 WCHAR *wn = NULL; // UTF-16 name, NULL when not used. |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4757 # else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4758 DIR *dirp; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4759 struct dirent *dp; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4760 # endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4761 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4762 ga_init2(gap, (int)sizeof(void *), 20); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4763 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4764 # ifdef FEAT_EVAL |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4765 # define FREE_ITEM(item) do { \ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4766 if (withattr) \ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4767 dict_unref((dict_T*)item); \ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4768 else \ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4769 vim_free(item); \ |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4770 } while (0) |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4771 |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4772 readdirex_sort = READDIR_SORT_BYTE; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4773 # else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4774 # define FREE_ITEM(item) vim_free(item) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4775 # endif |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4776 |
19301
80baa37506d0
patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents:
18896
diff
changeset
|
4777 # ifdef MSWIN |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4778 buf = alloc(MAXPATHL); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4779 if (buf == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4780 return FAIL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4781 STRNCPY(buf, path, MAXPATHL-5); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4782 p = buf + STRLEN(buf); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4783 MB_PTR_BACK(buf, p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4784 if (*p == '\\' || *p == '/') |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4785 *p = NUL; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4786 STRCAT(p, "\\*"); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4787 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4788 wn = enc_to_utf16(buf, NULL); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4789 if (wn != NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4790 hFind = FindFirstFileW(wn, &wfd); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4791 ok = (hFind != INVALID_HANDLE_VALUE); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4792 if (!ok) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4793 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4794 failed = TRUE; |
22568
fdc72bf4de35
patch 8.2.1832: readdirex() error is displayed as a message
Bram Moolenaar <Bram@vim.org>
parents:
22490
diff
changeset
|
4795 semsg(_(e_notopen), path); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4796 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4797 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4798 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4799 while (ok) |
19526
22f0dda71638
patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
4800 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4801 int ignore; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4802 void *item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4803 WCHAR *wp; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4804 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4805 wp = wfd.cFileName; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4806 ignore = wp[0] == L'.' && |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4807 (wp[1] == NUL || |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4808 (wp[1] == L'.' && wp[2] == NUL)); |
20790
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4809 if (ignore) |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4810 { |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4811 ok = FindNextFileW(hFind, &wfd); |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4812 continue; |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4813 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4814 # ifdef FEAT_EVAL |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4815 if (withattr) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4816 item = (void*)create_readdirex_item(&wfd); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4817 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4818 # endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4819 item = (void*)utf16_to_enc(wfd.cFileName, NULL); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4820 if (item == NULL) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4821 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4822 failed = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4823 break; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4824 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4825 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4826 if (!ignore && checkitem != NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4827 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4828 int r = checkitem(context, item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4829 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4830 if (r < 0) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4831 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4832 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4833 break; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4834 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4835 if (r == 0) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4836 ignore = TRUE; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4837 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4838 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4839 if (!ignore) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4840 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4841 if (ga_grow(gap, 1) == OK) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4842 ((void**)gap->ga_data)[gap->ga_len++] = item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4843 else |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4844 { |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4845 failed = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4846 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4847 break; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4848 } |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4849 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4850 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4851 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4852 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4853 ok = FindNextFileW(hFind, &wfd); |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4854 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4855 FindClose(hFind); |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4856 } |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4857 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4858 vim_free(buf); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4859 vim_free(wn); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4860 # else // MSWIN |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4861 dirp = opendir((char *)path); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4862 if (dirp == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4863 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4864 failed = TRUE; |
22568
fdc72bf4de35
patch 8.2.1832: readdirex() error is displayed as a message
Bram Moolenaar <Bram@vim.org>
parents:
22490
diff
changeset
|
4865 semsg(_(e_notopen), path); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4866 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4867 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4868 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4869 for (;;) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4870 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4871 int ignore; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4872 void *item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4873 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4874 dp = readdir(dirp); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4875 if (dp == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4876 break; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4877 p = (char_u *)dp->d_name; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4878 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4879 ignore = p[0] == '.' && |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4880 (p[1] == NUL || |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4881 (p[1] == '.' && p[2] == NUL)); |
20790
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4882 if (ignore) |
5a9c42c6a69e
patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents:
20669
diff
changeset
|
4883 continue; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4884 # ifdef FEAT_EVAL |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4885 if (withattr) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4886 item = (void*)create_readdirex_item(path, p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4887 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4888 # endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4889 item = (void*)vim_strsave(p); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4890 if (item == NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4891 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4892 failed = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4893 break; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4894 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4895 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4896 if (!ignore && checkitem != NULL) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4897 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4898 int r = checkitem(context, item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4899 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4900 if (r < 0) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4901 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4902 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4903 break; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4904 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4905 if (r == 0) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4906 ignore = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4907 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4908 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4909 if (!ignore) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4910 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4911 if (ga_grow(gap, 1) == OK) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4912 ((void**)gap->ga_data)[gap->ga_len++] = item; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4913 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4914 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4915 failed = TRUE; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4916 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4917 break; |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4918 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4919 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4920 else |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4921 FREE_ITEM(item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4922 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4923 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4924 closedir(dirp); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4925 } |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4926 # endif // MSWIN |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4927 |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4928 # undef FREE_ITEM |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4929 |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4930 if (!failed && gap->ga_len > 0 && sort > READDIR_SORT_NONE) |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4931 { |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4932 # ifdef FEAT_EVAL |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4933 readdirex_sort = sort; |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4934 if (withattr) |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4935 qsort((void*)gap->ga_data, (size_t)gap->ga_len, sizeof(dict_T*), |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4936 compare_readdirex_item); |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4937 else |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4938 qsort((void*)gap->ga_data, (size_t)gap->ga_len, sizeof(char_u *), |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4939 compare_readdir_item); |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4940 # else |
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4941 sort_strings((char_u **)gap->ga_data, gap->ga_len); |
20643
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4942 # endif |
c2beb6baa42c
patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4943 } |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4944 |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4945 return failed ? FAIL : OK; |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4946 } |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4947 |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4948 /* |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4949 * Delete "name" and everything in it, recursively. |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4950 * return 0 for success, -1 if some file was not deleted. |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4951 */ |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4952 int |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4953 delete_recursive(char_u *name) |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4954 { |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4955 int result = 0; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4956 int i; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4957 char_u *exp; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4958 garray_T ga; |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4959 |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4960 // A symbolic link to a directory itself is deleted, not the directory it |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4961 // points to. |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4962 if ( |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
4963 # if defined(UNIX) || defined(MSWIN) |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7641
diff
changeset
|
4964 mch_isrealdir(name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4965 # else |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4966 mch_isdir(name) |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4967 # endif |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4968 ) |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4969 { |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4970 exp = vim_strsave(name); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4971 if (exp == NULL) |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4972 return -1; |
20873
69055d27e85e
patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4973 if (readdir_core(&ga, exp, FALSE, NULL, NULL, READDIR_SORT_NONE) == OK) |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4974 { |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4975 for (i = 0; i < ga.ga_len; ++i) |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4976 { |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4977 vim_snprintf((char *)NameBuff, MAXPATHL, "%s/%s", exp, |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4978 ((char_u **)ga.ga_data)[i]); |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4979 if (delete_recursive(NameBuff) != 0) |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4980 result = -1; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4981 } |
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4982 ga_clear_strings(&ga); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4983 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4984 else |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4985 result = -1; |
16752
e2d8d83e6721
patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents:
16744
diff
changeset
|
4986 (void)mch_rmdir(exp); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4987 vim_free(exp); |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4988 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4989 else |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4990 result = mch_remove(name) == 0 ? 0 : -1; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4991 |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4992 return result; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4993 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4994 #endif |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4995 |
7 | 4996 #if defined(TEMPDIRNAMES) || defined(PROTO) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4997 static long temp_count = 0; // Temp filename counter. |
7 | 4998 |
20311
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
4999 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5000 /* |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5001 * Open temporary directory and take file lock to prevent |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5002 * to be auto-cleaned. |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5003 */ |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5004 static void |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5005 vim_opentempdir(void) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5006 { |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5007 DIR *dp = NULL; |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5008 |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5009 if (vim_tempdir_dp != NULL) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5010 return; |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5011 |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5012 dp = opendir((const char*)vim_tempdir); |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5013 |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5014 if (dp != NULL) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5015 { |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5016 vim_tempdir_dp = dp; |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5017 flock(dirfd(vim_tempdir_dp), LOCK_SH); |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5018 } |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5019 } |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5020 |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5021 /* |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5022 * Close temporary directory - it automatically release file lock. |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5023 */ |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5024 static void |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5025 vim_closetempdir(void) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5026 { |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5027 if (vim_tempdir_dp != NULL) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5028 { |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5029 closedir(vim_tempdir_dp); |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5030 vim_tempdir_dp = NULL; |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5031 } |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5032 } |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5033 # endif |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5034 |
7 | 5035 /* |
5036 * Delete the temp directory and all files it contains. | |
5037 */ | |
5038 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5039 vim_deltempdir(void) |
7 | 5040 { |
5041 if (vim_tempdir != NULL) | |
5042 { | |
20311
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5043 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5044 vim_closetempdir(); |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5045 # endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5046 // remove the trailing path separator |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
5047 gettail(vim_tempdir)[-1] = NUL; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
5048 delete_recursive(vim_tempdir); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
5049 VIM_CLEAR(vim_tempdir); |
7 | 5050 } |
5051 } | |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
5052 |
7 | 5053 /* |
1997 | 5054 * Directory "tempdir" was created. Expand this name to a full path and put |
5055 * it in "vim_tempdir". This avoids that using ":cd" would confuse us. | |
5056 * "tempdir" must be no longer than MAXPATHL. | |
5057 */ | |
5058 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5059 vim_settempdir(char_u *tempdir) |
1997 | 5060 { |
5061 char_u *buf; | |
5062 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16754
diff
changeset
|
5063 buf = alloc(MAXPATHL + 2); |
1997 | 5064 if (buf != NULL) |
5065 { | |
5066 if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL) | |
5067 STRCPY(buf, tempdir); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
5068 add_pathsep(buf); |
1997 | 5069 vim_tempdir = vim_strsave(buf); |
20311
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5070 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD) |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5071 vim_opentempdir(); |
05b4efb062a7
patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents:
19836
diff
changeset
|
5072 # endif |
1997 | 5073 vim_free(buf); |
5074 } | |
5075 } | |
2006 | 5076 #endif |
1997 | 5077 |
5078 /* | |
7 | 5079 * vim_tempname(): Return a unique name that can be used for a temp file. |
5080 * | |
9291
bff3cd5cf922
commit https://github.com/vim/vim/commit/76ae22fef3cb224ca7fbf97517f881e825d4d0c2
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
5081 * The temp file is NOT guaranteed to be created. If "keep" is FALSE it is |
bff3cd5cf922
commit https://github.com/vim/vim/commit/76ae22fef3cb224ca7fbf97517f881e825d4d0c2
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
5082 * guaranteed to NOT be created. |
7 | 5083 * |
5084 * The returned pointer is to allocated memory. | |
5085 * The returned pointer is NULL if no valid name was found. | |
5086 */ | |
5087 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5088 vim_tempname( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5089 int extra_char UNUSED, // char to use in the name instead of '?' |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5090 int keep UNUSED) |
7 | 5091 { |
5092 #ifdef USE_TMPNAM | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5093 char_u itmp[L_tmpnam]; // use tmpnam() |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
5094 #elif defined(MSWIN) |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5095 WCHAR itmp[TEMPNAMELEN]; |
7 | 5096 #else |
5097 char_u itmp[TEMPNAMELEN]; | |
5098 #endif | |
5099 | |
5100 #ifdef TEMPDIRNAMES | |
5101 static char *(tempdirs[]) = {TEMPDIRNAMES}; | |
5102 int i; | |
5103 # ifndef EEXIST | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
5104 stat_T st; |
7 | 5105 # endif |
5106 | |
5107 /* | |
5108 * This will create a directory for private use by this instance of Vim. | |
5109 * This is done once, and the same directory is used for all temp files. | |
5110 * This method avoids security problems because of symlink attacks et al. | |
5111 * It's also a bit faster, because we only need to check for an existing | |
5112 * file when creating the directory and not for each temp file. | |
5113 */ | |
5114 if (vim_tempdir == NULL) | |
5115 { | |
5116 /* | |
5117 * Try the entries in TEMPDIRNAMES to create the temp directory. | |
5118 */ | |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24578
diff
changeset
|
5119 for (i = 0; i < (int)ARRAY_LENGTH(tempdirs); ++i) |
7 | 5120 { |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2028
diff
changeset
|
5121 # ifndef HAVE_MKDTEMP |
1997 | 5122 size_t itmplen; |
5123 long nr; | |
5124 long off; | |
5125 # endif | |
5126 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5127 // Expand $TMP, leave room for "/v1100000/999999999". |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5128 // Skip the directory check if the expansion fails. |
7 | 5129 expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20); |
7305
372c785c04b6
commit https://github.com/vim/vim/commit/e1a61991d9b6fd5f65636d17583f93118268cda5
Christian Brabandt <cb@256bit.org>
parents:
7285
diff
changeset
|
5130 if (itmp[0] != '$' && mch_isdir(itmp)) |
372c785c04b6
commit https://github.com/vim/vim/commit/e1a61991d9b6fd5f65636d17583f93118268cda5
Christian Brabandt <cb@256bit.org>
parents:
7285
diff
changeset
|
5131 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5132 // directory exists |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
5133 add_pathsep(itmp); |
1997 | 5134 |
5135 # ifdef HAVE_MKDTEMP | |
9211
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5136 { |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5137 # if defined(UNIX) || defined(VMS) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5138 // Make sure the umask doesn't remove the executable bit. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5139 // "repl" has been reported to use "177". |
9211
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5140 mode_t umask_save = umask(077); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5141 # endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5142 // Leave room for filename |
9211
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5143 STRCAT(itmp, "vXXXXXX"); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5144 if (mkdtemp((char *)itmp) != NULL) |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5145 vim_settempdir(itmp); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5146 # if defined(UNIX) || defined(VMS) |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5147 (void)umask(umask_save); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5148 # endif |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
5149 } |
1997 | 5150 # else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5151 // Get an arbitrary number of up to 6 digits. When it's |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5152 // unlikely that it already exists it will be faster, |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5153 // otherwise it doesn't matter. The use of mkdir() avoids any |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5154 // security problems because of the predictable number. |
7 | 5155 nr = (mch_get_pid() + (long)time(NULL)) % 1000000L; |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2028
diff
changeset
|
5156 itmplen = STRLEN(itmp); |
7 | 5157 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5158 // Try up to 10000 different values until we find a name that |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5159 // doesn't exist. |
7 | 5160 for (off = 0; off < 10000L; ++off) |
5161 { | |
5162 int r; | |
1997 | 5163 # if defined(UNIX) || defined(VMS) |
7 | 5164 mode_t umask_save; |
1997 | 5165 # endif |
5166 | |
5167 sprintf((char *)itmp + itmplen, "v%ld", nr + off); | |
5168 # ifndef EEXIST | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5169 // If mkdir() does not set errno to EEXIST, check for |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5170 // existing file here. There is a race condition then, |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5171 // although it's fail-safe. |
7 | 5172 if (mch_stat((char *)itmp, &st) >= 0) |
5173 continue; | |
1997 | 5174 # endif |
5175 # if defined(UNIX) || defined(VMS) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5176 // Make sure the umask doesn't remove the executable bit. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5177 // "repl" has been reported to use "177". |
7 | 5178 umask_save = umask(077); |
1997 | 5179 # endif |
7 | 5180 r = vim_mkdir(itmp, 0700); |
1997 | 5181 # if defined(UNIX) || defined(VMS) |
7 | 5182 (void)umask(umask_save); |
1997 | 5183 # endif |
7 | 5184 if (r == 0) |
5185 { | |
1997 | 5186 vim_settempdir(itmp); |
7 | 5187 break; |
5188 } | |
1997 | 5189 # ifdef EEXIST |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5190 // If the mkdir() didn't fail because the file/dir exists, |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5191 // we probably can't create any dir here, try another |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5192 // place. |
7 | 5193 if (errno != EEXIST) |
1997 | 5194 # endif |
7 | 5195 break; |
5196 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5197 # endif // HAVE_MKDTEMP |
7 | 5198 if (vim_tempdir != NULL) |
5199 break; | |
5200 } | |
5201 } | |
5202 } | |
5203 | |
5204 if (vim_tempdir != NULL) | |
5205 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5206 // There is no need to check if the file exists, because we own the |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5207 // directory and nobody else creates a file in it. |
7 | 5208 sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++); |
5209 return vim_strsave(itmp); | |
5210 } | |
5211 | |
5212 return NULL; | |
5213 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5214 #else // TEMPDIRNAMES |
7 | 5215 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
5216 # ifdef MSWIN |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5217 WCHAR wszTempFile[_MAX_PATH + 1]; |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5218 WCHAR buf4[4]; |
23017
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5219 WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
7 | 5220 char_u *retval; |
5221 char_u *p; | |
25084
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
5222 char_u *shname; |
23017
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5223 long i; |
7 | 5224 |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5225 wcscpy(itmp, L""); |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5226 if (GetTempPathW(_MAX_PATH, wszTempFile) == 0) |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5227 { |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5228 wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir |
23017
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5229 wszTempFile[1] = L'\\'; |
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5230 wszTempFile[2] = NUL; |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5231 } |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5232 wcscpy(buf4, L"VIM"); |
23017
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5233 |
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5234 // randomize the name to avoid collisions |
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5235 i = mch_get_pid() + extra_char; |
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5236 buf4[1] = chartab[i % 36]; |
d80faed40bec
patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
5237 buf4[2] = chartab[101 * i % 36]; |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5238 if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) |
7 | 5239 return NULL; |
6721 | 5240 if (!keep) |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5241 // GetTempFileName() will create the file, we don't want that |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5242 (void)DeleteFileW(itmp); |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5243 |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5244 // Backslashes in a temp file name cause problems when filtering with |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5245 // "sh". NOTE: This also checks 'shellcmdflag' to help those people who |
25068
0ce24f734615
patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents:
25052
diff
changeset
|
5246 // didn't set 'shellslash' but only if not using PowerShell. |
15776
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
5247 retval = utf16_to_enc(itmp, NULL); |
25084
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
5248 shname = gettail(p_sh); |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
5249 if ((*p_shcf == '-' && !(strstr((char *)shname, "powershell") != NULL |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
5250 || strstr((char *)shname, "pwsh") != NULL )) |
beff72446e2e
patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents:
25068
diff
changeset
|
5251 || p_ssl) |
7 | 5252 for (p = retval; *p; ++p) |
5253 if (*p == '\\') | |
5254 *p = '/'; | |
5255 return retval; | |
5256 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
5257 # else // MSWIN |
7 | 5258 |
5259 # ifdef USE_TMPNAM | |
2697 | 5260 char_u *p; |
5261 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5262 // tmpnam() will make its own name |
2697 | 5263 p = tmpnam((char *)itmp); |
5264 if (p == NULL || *p == NUL) | |
7 | 5265 return NULL; |
5266 # else | |
5267 char_u *p; | |
5268 | |
5269 # ifdef VMS_TEMPNAM | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5270 // mktemp() is not working on VMS. It seems to be |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5271 // a do-nothing function. Therefore we use tempnam(). |
7 | 5272 sprintf((char *)itmp, "VIM%c", extra_char); |
5273 p = (char_u *)tempnam("tmp:", (char *)itmp); | |
5274 if (p != NULL) | |
5275 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5276 // VMS will use '.LIS' if we don't explicitly specify an extension, |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5277 // and VIM will then be unable to find the file later |
7 | 5278 STRCPY(itmp, p); |
5279 STRCAT(itmp, ".txt"); | |
5280 free(p); | |
5281 } | |
5282 else | |
5283 return NULL; | |
5284 # else | |
5285 STRCPY(itmp, TEMPNAME); | |
5286 if ((p = vim_strchr(itmp, '?')) != NULL) | |
5287 *p = extra_char; | |
5288 if (mktemp((char *)itmp) == NULL) | |
5289 return NULL; | |
5290 # endif | |
5291 # endif | |
5292 | |
5293 return vim_strsave(itmp); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
5294 # endif // MSWIN |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5295 #endif // TEMPDIRNAMES |
7 | 5296 } |
5297 | |
5298 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
5299 /* | |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
5300 * Convert all backslashes in fname to forward slashes in-place, unless when |
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
5301 * it looks like a URL. |
7 | 5302 */ |
5303 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5304 forward_slash(char_u *fname) |
7 | 5305 { |
5306 char_u *p; | |
5307 | |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
5308 if (path_with_url(fname)) |
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
5309 return; |
7 | 5310 for (p = fname; *p != NUL; ++p) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5311 // The Big5 encoding can have '\' in the trail byte. |
474 | 5312 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 5313 ++p; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
5314 else if (*p == '\\') |
7 | 5315 *p = '/'; |
5316 } | |
5317 #endif | |
5318 | |
5319 /* | |
153 | 5320 * Try matching a filename with a "pattern" ("prog" is NULL), or use the |
5321 * precompiled regprog "prog" ("pattern" is NULL). That avoids calling | |
5322 * vim_regcomp() often. | |
7 | 5323 * Used for autocommands and 'wildignore'. |
5324 * Returns TRUE if there is a match, FALSE otherwise. | |
5325 */ | |
15634
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
5326 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5327 match_file_pat( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5328 char_u *pattern, // pattern to match with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5329 regprog_T **prog, // pre-compiled regprog or NULL |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5330 char_u *fname, // full path of file name |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5331 char_u *sfname, // short file name or NULL |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5332 char_u *tail, // tail of path |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5333 int allow_dirs) // allow matching with dir |
7 | 5334 { |
5335 regmatch_T regmatch; | |
5336 int result = FALSE; | |
5337 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5338 regmatch.rm_ic = p_fic; // ignore case if 'fileignorecase' is set |
6470 | 5339 if (prog != NULL) |
5340 regmatch.regprog = *prog; | |
7 | 5341 else |
6470 | 5342 regmatch.regprog = vim_regcomp(pattern, RE_MAGIC); |
7 | 5343 |
5344 /* | |
5345 * Try for a match with the pattern with: | |
5346 * 1. the full file name, when the pattern has a '/'. | |
5347 * 2. the short file name, when the pattern has a '/'. | |
5348 * 3. the tail of the file name, when the pattern has no '/'. | |
5349 */ | |
6470 | 5350 if (regmatch.regprog != NULL |
7 | 5351 && ((allow_dirs |
5352 && (vim_regexec(®match, fname, (colnr_T)0) | |
5353 || (sfname != NULL | |
5354 && vim_regexec(®match, sfname, (colnr_T)0)))) | |
6470 | 5355 || (!allow_dirs && vim_regexec(®match, tail, (colnr_T)0)))) |
7 | 5356 result = TRUE; |
5357 | |
6375 | 5358 if (prog != NULL) |
5359 *prog = regmatch.regprog; | |
5360 else | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
5361 vim_regfree(regmatch.regprog); |
7 | 5362 return result; |
5363 } | |
5364 | |
5365 #if defined(FEAT_WILDIGN) || defined(PROTO) | |
5366 /* | |
5367 * Return TRUE if a file matches with a pattern in "list". | |
5368 * "list" is a comma-separated list of patterns, like 'wildignore'. | |
5369 * "sfname" is the short file name or NULL, "ffname" the long file name. | |
5370 */ | |
5371 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5372 match_file_list(char_u *list, char_u *sfname, char_u *ffname) |
7 | 5373 { |
5374 char_u buf[100]; | |
5375 char_u *tail; | |
5376 char_u *regpat; | |
5377 char allow_dirs; | |
5378 int match; | |
5379 char_u *p; | |
5380 | |
5381 tail = gettail(sfname); | |
5382 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5383 // try all patterns in 'wildignore' |
7 | 5384 p = list; |
5385 while (*p) | |
5386 { | |
5387 copy_option_part(&p, buf, 100, ","); | |
5388 regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE); | |
5389 if (regpat == NULL) | |
5390 break; | |
153 | 5391 match = match_file_pat(regpat, NULL, ffname, sfname, |
5392 tail, (int)allow_dirs); | |
7 | 5393 vim_free(regpat); |
5394 if (match) | |
5395 return TRUE; | |
5396 } | |
5397 return FALSE; | |
5398 } | |
5399 #endif | |
5400 | |
5401 /* | |
5402 * Convert the given pattern "pat" which has shell style wildcards in it, into | |
5403 * a regular expression, and return the result in allocated memory. If there | |
5404 * is a directory path separator to be matched, then TRUE is put in | |
5405 * allow_dirs, otherwise FALSE is put there -- webb. | |
5406 * Handle backslashes before special characters, like "\*" and "\ ". | |
5407 * | |
5408 * Returns NULL when out of memory. | |
5409 */ | |
5410 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5411 file_pat_to_reg_pat( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5412 char_u *pat, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5413 char_u *pat_end, // first char after pattern or NULL |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5414 char *allow_dirs, // Result passed back out in here |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5415 int no_bslash UNUSED) // Don't use a backward slash as pathsep |
7 | 5416 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5417 int size = 2; // '^' at start, '$' at end |
7 | 5418 char_u *endp; |
5419 char_u *reg_pat; | |
5420 char_u *p; | |
5421 int i; | |
5422 int nested = 0; | |
5423 int add_dollar = TRUE; | |
5424 | |
5425 if (allow_dirs != NULL) | |
5426 *allow_dirs = FALSE; | |
5427 if (pat_end == NULL) | |
5428 pat_end = pat + STRLEN(pat); | |
5429 | |
5430 for (p = pat; p < pat_end; p++) | |
5431 { | |
5432 switch (*p) | |
5433 { | |
5434 case '*': | |
5435 case '.': | |
5436 case ',': | |
5437 case '{': | |
5438 case '}': | |
5439 case '~': | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5440 size += 2; // extra backslash |
7 | 5441 break; |
5442 #ifdef BACKSLASH_IN_FILENAME | |
5443 case '\\': | |
5444 case '/': | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5445 size += 4; // could become "[\/]" |
7 | 5446 break; |
5447 #endif | |
5448 default: | |
5449 size++; | |
474 | 5450 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 5451 { |
5452 ++p; | |
5453 ++size; | |
5454 } | |
5455 break; | |
5456 } | |
5457 } | |
5458 reg_pat = alloc(size + 1); | |
5459 if (reg_pat == NULL) | |
5460 return NULL; | |
5461 | |
5462 i = 0; | |
5463 | |
5464 if (pat[0] == '*') | |
5465 while (pat[0] == '*' && pat < pat_end - 1) | |
5466 pat++; | |
5467 else | |
5468 reg_pat[i++] = '^'; | |
5469 endp = pat_end - 1; | |
7005 | 5470 if (endp >= pat && *endp == '*') |
7 | 5471 { |
5472 while (endp - pat > 0 && *endp == '*') | |
5473 endp--; | |
5474 add_dollar = FALSE; | |
5475 } | |
5476 for (p = pat; *p && nested >= 0 && p <= endp; p++) | |
5477 { | |
5478 switch (*p) | |
5479 { | |
5480 case '*': | |
5481 reg_pat[i++] = '.'; | |
5482 reg_pat[i++] = '*'; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5483 while (p[1] == '*') // "**" matches like "*" |
444 | 5484 ++p; |
7 | 5485 break; |
5486 case '.': | |
5487 case '~': | |
5488 reg_pat[i++] = '\\'; | |
5489 reg_pat[i++] = *p; | |
5490 break; | |
5491 case '?': | |
5492 reg_pat[i++] = '.'; | |
5493 break; | |
5494 case '\\': | |
5495 if (p[1] == NUL) | |
5496 break; | |
5497 #ifdef BACKSLASH_IN_FILENAME | |
5498 if (!no_bslash) | |
5499 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5500 // translate: |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5501 // "\x" to "\\x" e.g., "dir\file" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5502 // "\*" to "\\.*" e.g., "dir\*.c" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5503 // "\?" to "\\." e.g., "dir\??.c" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5504 // "\+" to "\+" e.g., "fileX\+.c" |
7 | 5505 if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?') |
5506 && p[1] != '+') | |
5507 { | |
5508 reg_pat[i++] = '['; | |
5509 reg_pat[i++] = '\\'; | |
5510 reg_pat[i++] = '/'; | |
5511 reg_pat[i++] = ']'; | |
5512 if (allow_dirs != NULL) | |
5513 *allow_dirs = TRUE; | |
5514 break; | |
5515 } | |
5516 } | |
5517 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5518 // Undo escaping from ExpandEscape(): |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5519 // foo\?bar -> foo?bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5520 // foo\%bar -> foo%bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5521 // foo\,bar -> foo,bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5522 // foo\ bar -> foo bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5523 // Don't unescape \, * and others that are also special in a |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5524 // regexp. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5525 // An escaped { must be unescaped since we use magic not |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5526 // verymagic. Use "\\\{n,m\}"" to get "\{n,m}". |
7 | 5527 if (*++p == '?' |
5528 #ifdef BACKSLASH_IN_FILENAME | |
5529 && no_bslash | |
5530 #endif | |
5531 ) | |
5532 reg_pat[i++] = '?'; | |
5533 else | |
5104
93cccad6a26b
updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents:
5008
diff
changeset
|
5534 if (*p == ',' || *p == '%' || *p == '#' |
6999 | 5535 || vim_isspace(*p) || *p == '{' || *p == '}') |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2241
diff
changeset
|
5536 reg_pat[i++] = *p; |
5259
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5537 else if (*p == '\\' && p[1] == '\\' && p[2] == '{') |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5538 { |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5539 reg_pat[i++] = '\\'; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5540 reg_pat[i++] = '{'; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5541 p += 2; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5542 } |
7 | 5543 else |
5544 { | |
5545 if (allow_dirs != NULL && vim_ispathsep(*p) | |
5546 #ifdef BACKSLASH_IN_FILENAME | |
5547 && (!no_bslash || *p != '\\') | |
5548 #endif | |
5549 ) | |
5550 *allow_dirs = TRUE; | |
5551 reg_pat[i++] = '\\'; | |
5552 reg_pat[i++] = *p; | |
5553 } | |
5554 break; | |
5555 #ifdef BACKSLASH_IN_FILENAME | |
5556 case '/': | |
5557 reg_pat[i++] = '['; | |
5558 reg_pat[i++] = '\\'; | |
5559 reg_pat[i++] = '/'; | |
5560 reg_pat[i++] = ']'; | |
5561 if (allow_dirs != NULL) | |
5562 *allow_dirs = TRUE; | |
5563 break; | |
5564 #endif | |
5565 case '{': | |
5566 reg_pat[i++] = '\\'; | |
5567 reg_pat[i++] = '('; | |
5568 nested++; | |
5569 break; | |
5570 case '}': | |
5571 reg_pat[i++] = '\\'; | |
5572 reg_pat[i++] = ')'; | |
5573 --nested; | |
5574 break; | |
5575 case ',': | |
5576 if (nested) | |
5577 { | |
5578 reg_pat[i++] = '\\'; | |
5579 reg_pat[i++] = '|'; | |
5580 } | |
5581 else | |
5582 reg_pat[i++] = ','; | |
5583 break; | |
5584 default: | |
474 | 5585 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 5586 reg_pat[i++] = *p++; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
5587 else if (allow_dirs != NULL && vim_ispathsep(*p)) |
7 | 5588 *allow_dirs = TRUE; |
5589 reg_pat[i++] = *p; | |
5590 break; | |
5591 } | |
5592 } | |
5593 if (add_dollar) | |
5594 reg_pat[i++] = '$'; | |
5595 reg_pat[i] = NUL; | |
5596 if (nested != 0) | |
5597 { | |
5598 if (nested < 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
5599 emsg(_("E219: Missing {.")); |
7 | 5600 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
5601 emsg(_("E220: Missing }.")); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
5602 VIM_CLEAR(reg_pat); |
7 | 5603 } |
5604 return reg_pat; | |
5605 } | |
2664 | 5606 |
5607 #if defined(EINTR) || defined(PROTO) | |
5608 /* | |
5609 * Version of read() that retries when interrupted by EINTR (possibly | |
5610 * by a SIGWINCH). | |
5611 */ | |
5612 long | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5613 read_eintr(int fd, void *buf, size_t bufsize) |
2664 | 5614 { |
5615 long ret; | |
5616 | |
5617 for (;;) | |
5618 { | |
5619 ret = vim_read(fd, buf, bufsize); | |
5620 if (ret >= 0 || errno != EINTR) | |
5621 break; | |
5622 } | |
5623 return ret; | |
5624 } | |
5625 | |
5626 /* | |
5627 * Version of write() that retries when interrupted by EINTR (possibly | |
5628 * by a SIGWINCH). | |
5629 */ | |
5630 long | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5631 write_eintr(int fd, void *buf, size_t bufsize) |
2664 | 5632 { |
5633 long ret = 0; | |
5634 long wlen; | |
5635 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5636 // Repeat the write() so long it didn't fail, other than being interrupted |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5637 // by a signal. |
2664 | 5638 while (ret < (long)bufsize) |
5639 { | |
2666 | 5640 wlen = vim_write(fd, (char *)buf + ret, bufsize - ret); |
2664 | 5641 if (wlen < 0) |
5642 { | |
5643 if (errno != EINTR) | |
5644 break; | |
5645 } | |
5646 else | |
5647 ret += wlen; | |
5648 } | |
5649 return ret; | |
5650 } | |
5651 #endif |