Mercurial > vim
annotate src/fileio.c @ 18779:8f05b3cf8557 v8.1.2379
patch 8.1.2379: using old C style comments
Commit: https://github.com/vim/vim/commit/217e1b8359447f5550dcb0d1ee43380a90c253c5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 21:41:28 2019 +0100
patch 8.1.2379: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 21:45:04 +0100 |
parents | 068337e86133 |
children | 4481f3b29fc5 |
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 | |
2014 | 16 #if defined(__TANDEM) || defined(__MINT__) |
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 |
19 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
20 // Is there any system that doesn't have access()? |
574 | 21 #define USE_MCH_ACCESS |
7 | 22 |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
23 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
|
24 #ifdef FEAT_EVAL |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
25 static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp); |
7 | 26 #endif |
27 #ifdef FEAT_CRYPT | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
28 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 | 29 #endif |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7657
diff
changeset
|
30 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
|
31 static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags); |
1834 | 32 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
|
33 |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
34 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
35 filemess( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
36 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
37 char_u *name, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
38 char_u *s, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
39 int attr) |
7 | 40 { |
41 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
|
42 int prev_msg_col = msg_col; |
7 | 43 |
44 if (msg_silent != 0) | |
45 return; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
46 msg_add_fname(buf, name); // put file name in IObuff with quotes |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
47 // If it's extremely long, truncate it. |
7 | 48 if (STRLEN(IObuff) > IOSIZE - 80) |
49 IObuff[IOSIZE - 80] = NUL; | |
50 STRCAT(IObuff, s); | |
51 /* | |
52 * For the first message may have to start a new line. | |
53 * For further ones overwrite the previous one, reset msg_scroll before | |
54 * calling filemess(). | |
55 */ | |
56 msg_scroll_save = msg_scroll; | |
57 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
58 msg_scroll = FALSE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
59 if (!msg_scroll) // wait a bit when overwriting an error msg |
7 | 60 check_for_delay(FALSE); |
61 msg_start(); | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
62 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
|
63 msg_putchar('\r'); // overwrite any previous message. |
7 | 64 msg_scroll = msg_scroll_save; |
65 msg_scrolled_ign = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
66 // may truncate the message to avoid a hit-return prompt |
7 | 67 msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr); |
68 msg_clr_eos(); | |
69 out_flush(); | |
70 msg_scrolled_ign = FALSE; | |
71 } | |
72 | |
73 /* | |
74 * Read lines from file "fname" into the buffer after line "from". | |
75 * | |
76 * 1. We allocate blocks with lalloc, as big as possible. | |
77 * 2. Each block is filled with characters from the file with a single read(). | |
78 * 3. The lines are inserted in the buffer with ml_append(). | |
79 * | |
80 * (caller must check that fname != NULL, unless READ_STDIN is used) | |
81 * | |
82 * "lines_to_skip" is the number of lines that must be skipped | |
83 * "lines_to_read" is the number of lines that are appended | |
84 * When not recovering lines_to_skip is 0 and lines_to_read MAXLNUM. | |
85 * | |
86 * flags: | |
87 * READ_NEW starting to edit a new buffer | |
88 * READ_FILTER reading filter output | |
89 * READ_STDIN read from stdin instead of a file | |
90 * READ_BUFFER read from curbuf instead of a file (converting after reading | |
91 * stdin) | |
92 * 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
|
93 * 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
|
94 * READ_FIFO read from fifo/socket instead of a file |
7 | 95 * |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
96 * return FAIL for failure, NOTDONE for directory (failure), or OK |
7 | 97 */ |
98 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
99 readfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
100 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
101 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
102 linenr_T from, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
103 linenr_T lines_to_skip, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
104 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
|
105 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
|
106 int flags) |
7 | 107 { |
108 int fd = 0; | |
109 int newfile = (flags & READ_NEW); | |
110 int check_readonly; | |
111 int filtering = (flags & READ_FILTER); | |
112 int read_stdin = (flags & READ_STDIN); | |
113 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
|
114 int read_fifo = (flags & READ_FIFO); |
1486 | 115 int set_options = newfile || read_buffer |
116 || (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
|
117 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
|
118 colnr_T read_buf_col = 0; // next char to read from this line |
7 | 119 char_u c; |
120 linenr_T lnum = from; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 int wasempty; // buffer was empty before reading |
7 | 126 colnr_T len; |
127 long size = 0; | |
128 char_u *p; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
129 off_T filesize = 0; |
7 | 130 int skip_read = FALSE; |
131 #ifdef FEAT_CRYPT | |
132 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
|
133 int did_ask_for_key = FALSE; |
7 | 134 #endif |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
135 #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
|
136 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
|
137 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
|
138 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
139 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
|
140 #define UNKNOWN 0x0fffffff // file size is unknown |
7 | 141 linenr_T linecnt; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
142 int error = FALSE; // errors encountered |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
143 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
|
144 long linerest = 0; // remaining chars in line |
7 | 145 #ifdef UNIX |
146 int perm = 0; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
147 int swap_mode = -1; // protection bits for swap file |
7 | 148 #else |
149 int perm; | |
150 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
151 int fileformat = 0; // end-of-line format |
7 | 152 int keep_fileformat = FALSE; |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
153 stat_T st; |
7 | 154 int file_readonly; |
155 linenr_T skip_count = 0; | |
156 linenr_T read_count = 0; | |
157 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
|
158 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
|
159 // 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
|
160 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
|
161 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
|
162 int try_unix; |
7 | 163 int file_rewind = FALSE; |
164 int can_retry; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 // in destination encoding |
595 | 169 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
|
170 // 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
|
171 // replace with |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
172 char_u *tmpname = NULL; // name of 'charconvert' output file |
7 | 173 int fio_flags = 0; |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
174 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
|
175 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
|
176 char_u *fenc_next = NULL; // next item in 'fencs' or NULL |
7 | 177 int advance_fenc = FALSE; |
178 long real_size = 0; | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
179 #ifdef USE_ICONV |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
180 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
|
181 # ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
182 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
|
183 // 'charconvert' next |
7 | 184 # endif |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
185 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
186 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
|
187 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
|
188 // wasn't possible |
7 | 189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 int using_b_fname; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
197 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
198 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
|
199 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
200 curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read |
7 | 201 |
202 /* | |
203 * If there is no file name yet, use the one for the read file. | |
204 * BF_NOTEDITED is set to reflect this. | |
205 * Don't do this for a read from a filter. | |
206 * Only do this when 'cpoptions' contains the 'f' flag. | |
207 */ | |
208 if (curbuf->b_ffname == NULL | |
209 && !filtering | |
210 && fname != NULL | |
211 && vim_strchr(p_cpo, CPO_FNAMER) != NULL | |
212 && !(flags & READ_DUMMY)) | |
213 { | |
633 | 214 if (set_rw_fname(fname, sfname) == FAIL) |
215 return FAIL; | |
7 | 216 } |
217 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
218 // 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
|
219 // 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
|
220 // 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
|
221 // 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 || (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
|
227 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
|
228 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
229 // 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
|
230 // display the line. |
167 | 231 ex_no_reprint = TRUE; |
232 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
233 // don't display the file info for another buffer now |
968 | 234 need_fileinfo = FALSE; |
235 | |
7 | 236 /* |
237 * For Unix: Use the short file name whenever possible. | |
238 * Avoids problems with networks and when directory names are changed. | |
239 * Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to | |
240 * another directory, which we don't detect. | |
241 */ | |
242 if (sfname == NULL) | |
243 sfname = fname; | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
244 #if defined(UNIX) |
7 | 245 fname = sfname; |
246 #endif | |
247 | |
248 /* | |
249 * The BufReadCmd and FileReadCmd events intercept the reading process by | |
250 * executing the associated commands instead. | |
251 */ | |
252 if (!filtering && !read_stdin && !read_buffer) | |
253 { | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
254 orig_start = curbuf->b_op_start; |
7 | 255 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
256 // Set '[ mark to the line above where the lines go (line 1 if zero). |
7 | 257 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); |
258 curbuf->b_op_start.col = 0; | |
259 | |
260 if (newfile) | |
261 { | |
262 if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname, | |
263 FALSE, curbuf, eap)) | |
264 #ifdef FEAT_EVAL | |
265 return aborting() ? FAIL : OK; | |
266 #else | |
267 return OK; | |
268 #endif | |
269 } | |
270 else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname, | |
271 FALSE, NULL, eap)) | |
272 #ifdef FEAT_EVAL | |
273 return aborting() ? FAIL : OK; | |
274 #else | |
275 return OK; | |
276 #endif | |
277 | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
278 curbuf->b_op_start = orig_start; |
7 | 279 } |
280 | |
281 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
|
282 msg_scroll = FALSE; // overwrite previous file message |
7 | 283 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
284 msg_scroll = TRUE; // don't overwrite previous file message |
7 | 285 |
286 /* | |
287 * If the name ends in a path separator, we can't open it. Check here, | |
288 * because reading the file may actually work, but then creating the swap | |
289 * file may destroy it! Reported on MS-DOS and Win 95. | |
290 * If the name is too long we might crash further on, quit here. | |
291 */ | |
23 | 292 if (fname != NULL && *fname != NUL) |
293 { | |
39 | 294 p = fname + STRLEN(fname); |
295 if (after_pathsep(fname, p) || STRLEN(fname) >= MAXPATHL) | |
23 | 296 { |
297 filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0); | |
298 msg_end(); | |
299 msg_scroll = msg_save; | |
300 return FAIL; | |
301 } | |
7 | 302 } |
303 | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
304 if (!read_stdin && !read_buffer && !read_fifo) |
5322 | 305 { |
7 | 306 #ifdef UNIX |
5322 | 307 /* |
308 * On Unix it is possible to read a directory, so we have to | |
309 * check for it before the mch_open(). | |
310 */ | |
7 | 311 perm = mch_getperm(fname); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
312 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
|
313 && !S_ISFIFO(perm) // ... or fifo |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
314 && !S_ISSOCK(perm) // ... or socket |
1313 | 315 # ifdef OPEN_CHR_FILES |
316 && !(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
|
317 // ... or a character special file named /dev/fd/<n> |
1313 | 318 # endif |
7 | 319 ) |
320 { | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
321 int retval = FAIL; |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
322 |
7 | 323 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
|
324 { |
7 | 325 filemess(curbuf, fname, (char_u *)_("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
|
326 retval = NOTDONE; |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10221
diff
changeset
|
327 } |
7 | 328 else |
329 filemess(curbuf, fname, (char_u *)_("is not a file"), 0); | |
330 msg_end(); | |
331 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
|
332 return retval; |
7 | 333 } |
5322 | 334 #endif |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
335 #if defined(MSWIN) |
1006 | 336 /* |
337 * MS-Windows allows opening a device, but we will probably get stuck | |
338 * trying to read it. | |
339 */ | |
340 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE) | |
341 { | |
1303 | 342 filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0); |
1006 | 343 msg_end(); |
344 msg_scroll = msg_save; | |
345 return FAIL; | |
346 } | |
5322 | 347 #endif |
348 } | |
1004 | 349 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
350 // Set default or forced 'fileformat' and 'binary'. |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
351 set_file_options(set_options, eap); |
7 | 352 |
353 /* | |
354 * When opening a new file we take the readonly flag from the file. | |
355 * Default is r/w, can be set to r/o below. | |
356 * Don't reset it when in readonly mode | |
357 * Only set/reset b_p_ro when BF_CHECK_RO is set. | |
358 */ | |
359 check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO)); | |
164 | 360 if (check_readonly && !readonlymode) |
7 | 361 curbuf->b_p_ro = FALSE; |
362 | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
363 if (newfile && !read_stdin && !read_buffer && !read_fifo) |
7 | 364 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
365 // Remember time of file. |
7 | 366 if (mch_stat((char *)fname, &st) >= 0) |
367 { | |
368 buf_store_time(curbuf, &st, fname); | |
369 curbuf->b_mtime_read = curbuf->b_mtime; | |
370 #ifdef UNIX | |
371 /* | |
372 * Use the protection bits of the original file for the swap file. | |
373 * This makes it possible for others to read the name of the | |
374 * edited file from the swapfile, but only if they can read the | |
375 * edited file. | |
376 * Remove the "write" and "execute" bits for group and others | |
377 * (they must not write the swapfile). | |
378 * Add the "read" and "write" bits for the user, otherwise we may | |
379 * not be able to write to the file ourselves. | |
380 * Setting the bits is done below, after creating the swap file. | |
381 */ | |
382 swap_mode = (st.st_mode & 0644) | 0600; | |
383 #endif | |
384 #ifdef FEAT_CW_EDITOR | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
385 // Get the FSSpec on MacOS |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
386 // TODO: Update it properly when the buffer name changes |
7 | 387 (void)GetFSSpecFromPath(curbuf->b_ffname, &curbuf->b_FSSpec); |
388 #endif | |
389 #ifdef VMS | |
390 curbuf->b_fab_rfm = st.st_fab_rfm; | |
22 | 391 curbuf->b_fab_rat = st.st_fab_rat; |
392 curbuf->b_fab_mrs = st.st_fab_mrs; | |
7 | 393 #endif |
394 } | |
395 else | |
396 { | |
397 curbuf->b_mtime = 0; | |
398 curbuf->b_mtime_read = 0; | |
399 curbuf->b_orig_size = 0; | |
400 curbuf->b_orig_mode = 0; | |
401 } | |
402 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
403 // 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
|
404 // file doesn't exist. |
7 | 405 curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); |
406 } | |
407 | |
408 /* | |
409 * 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
|
410 * for Amiga: check readonly by trying to open the file for writing |
7 | 411 */ |
412 file_readonly = FALSE; | |
413 if (read_stdin) | |
414 { | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
415 #if defined(MSWIN) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
416 // Force binary I/O on stdin to avoid CR-LF -> LF conversion. |
7 | 417 setmode(0, O_BINARY); |
418 #endif | |
419 } | |
420 else if (!read_buffer) | |
421 { | |
422 #ifdef USE_MCH_ACCESS | |
423 if ( | |
424 # ifdef UNIX | |
425 !(perm & 0222) || | |
426 # endif | |
427 mch_access((char *)fname, W_OK)) | |
428 file_readonly = TRUE; | |
429 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); | |
430 #else | |
431 if (!newfile | |
432 || readonlymode | |
433 || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) | |
434 { | |
435 file_readonly = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
436 // try to open ro |
7 | 437 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); |
438 } | |
439 #endif | |
440 } | |
441 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
442 if (fd < 0) // cannot open at all |
7 | 443 { |
444 #ifndef UNIX | |
445 int isdir_f; | |
446 #endif | |
447 msg_scroll = msg_save; | |
448 #ifndef UNIX | |
449 /* | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
450 * On Amiga we can't open a directory, check here. |
7 | 451 */ |
452 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
|
453 perm = mch_getperm(fname); // check if the file exists |
7 | 454 if (isdir_f) |
455 { | |
456 filemess(curbuf, sfname, (char_u *)_("is a directory"), 0); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
457 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 458 } |
459 else | |
460 #endif | |
461 if (newfile) | |
462 { | |
2147
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
463 if (perm < 0 |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
464 #ifdef ENOENT |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
465 && errno == ENOENT |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
466 #endif |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
467 ) |
7 | 468 { |
469 /* | |
470 * Set the 'new-file' flag, so that when the file has | |
471 * been created by someone else, a ":w" will complain. | |
472 */ | |
473 curbuf->b_flags |= BF_NEW; | |
474 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
475 // 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
|
476 // 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
|
477 // "nofile" or "nowrite" buffer type. |
7 | 478 #ifdef FEAT_QUICKFIX |
479 if (!bt_dontwrite(curbuf)) | |
480 #endif | |
1834 | 481 { |
7 | 482 check_need_swap(newfile); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
483 // SwapExists autocommand may mess things up |
1834 | 484 if (curbuf != old_curbuf |
485 || (using_b_ffname | |
486 && (old_b_ffname != curbuf->b_ffname)) | |
487 || (using_b_fname | |
488 && (old_b_fname != curbuf->b_fname))) | |
489 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
490 emsg(_(e_auchangedbuf)); |
1834 | 491 return FAIL; |
492 } | |
493 } | |
592 | 494 if (dir_of_file_exists(fname)) |
495 filemess(curbuf, sfname, (char_u *)_("[New File]"), 0); | |
496 else | |
497 filemess(curbuf, sfname, | |
498 (char_u *)_("[New DIRECTORY]"), 0); | |
7 | 499 #ifdef FEAT_VIMINFO |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
500 // 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
|
501 // edited before and deleted. Get the old marks. |
7 | 502 check_marks_read(); |
503 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
504 // Set forced 'fileencoding'. |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
505 if (eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
506 set_forced_fenc(eap); |
7 | 507 apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, |
508 FALSE, curbuf, eap); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
509 // remember the current fileformat |
7 | 510 save_file_ff(curbuf); |
511 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
512 #if defined(FEAT_EVAL) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
513 if (aborting()) // autocmds may abort script processing |
7 | 514 return FAIL; |
515 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
516 return OK; // a new file is not an error |
7 | 517 } |
518 else | |
519 { | |
550 | 520 filemess(curbuf, sfname, (char_u *)( |
521 # ifdef EFBIG | |
522 (errno == EFBIG) ? _("[File too big]") : | |
523 # endif | |
2147
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
524 # ifdef EOVERFLOW |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
525 (errno == EOVERFLOW) ? _("[File too big]") : |
2bd29808d1f6
updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents:
2095
diff
changeset
|
526 # endif |
550 | 527 _("[Permission Denied]")), 0); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
528 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 529 } |
530 } | |
531 | |
532 return FAIL; | |
533 } | |
534 | |
535 /* | |
536 * Only set the 'ro' flag for readonly files the first time they are | |
537 * loaded. Help files always get readonly mode | |
538 */ | |
539 if ((check_readonly && file_readonly) || curbuf->b_help) | |
540 curbuf->b_p_ro = TRUE; | |
541 | |
819 | 542 if (set_options) |
7 | 543 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
544 // 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
|
545 // correctly set when reading stdin. |
1486 | 546 if (!read_buffer) |
547 { | |
548 curbuf->b_p_eol = TRUE; | |
549 curbuf->b_start_eol = TRUE; | |
550 } | |
7 | 551 curbuf->b_p_bomb = FALSE; |
1352 | 552 curbuf->b_start_bomb = FALSE; |
7 | 553 } |
554 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
555 // 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
|
556 // editing this file. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
557 // Don't do this for a "nofile" or "nowrite" buffer type. |
7 | 558 #ifdef FEAT_QUICKFIX |
559 if (!bt_dontwrite(curbuf)) | |
560 #endif | |
561 { | |
562 check_need_swap(newfile); | |
1834 | 563 if (!read_stdin && (curbuf != old_curbuf |
564 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) | |
565 || (using_b_fname && (old_b_fname != curbuf->b_fname)))) | |
566 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
567 emsg(_(e_auchangedbuf)); |
1834 | 568 if (!read_buffer) |
569 close(fd); | |
570 return FAIL; | |
571 } | |
7 | 572 #ifdef UNIX |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
573 // Set swap file protection bits after creating it. |
1918 | 574 if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL |
575 && 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
|
576 { |
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
|
577 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
|
578 |
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
|
579 /* |
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
|
580 * 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
|
581 * 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
|
582 * 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
|
583 * 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
|
584 * 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
|
585 */ |
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
|
586 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
|
587 { |
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
|
588 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
|
589 |
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
|
590 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
|
591 && 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
|
592 # 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
|
593 && 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
|
594 == -1 |
13730
7b818f7bb738
patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
595 # endif |
7b818f7bb738
patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
596 ) |
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
|
597 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
|
598 } |
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
|
599 |
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
|
600 (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
|
601 } |
7 | 602 #endif |
603 } | |
604 | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
605 // If "Quit" selected at ATTENTION dialog, don't load the file |
7 | 606 if (swap_exists_action == SEA_QUIT) |
607 { | |
608 if (!read_buffer && !read_stdin) | |
609 close(fd); | |
610 return FAIL; | |
611 } | |
612 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
613 ++no_wait_return; // don't wait for return yet |
7 | 614 |
615 /* | |
616 * Set '[ mark to the line above where the lines go (line 1 if zero). | |
617 */ | |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
618 orig_start = curbuf->b_op_start; |
7 | 619 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); |
620 curbuf->b_op_start.col = 0; | |
621 | |
10668
6a252c6afd5b
patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
622 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
|
623 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
|
624 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
|
625 |
7 | 626 if (!read_buffer) |
627 { | |
628 int m = msg_scroll; | |
629 int n = msg_scrolled; | |
630 | |
631 /* | |
632 * The file must be closed again, the autocommands may want to change | |
633 * the file before reading it. | |
634 */ | |
635 if (!read_stdin) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
636 close(fd); // ignore errors |
7 | 637 |
638 /* | |
639 * The output from the autocommands should not overwrite anything and | |
640 * should not be overwritten: Set msg_scroll, restore its value if no | |
641 * output was done. | |
642 */ | |
643 msg_scroll = TRUE; | |
644 if (filtering) | |
645 apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname, | |
646 FALSE, curbuf, eap); | |
647 else if (read_stdin) | |
648 apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname, | |
649 FALSE, curbuf, eap); | |
650 else if (newfile) | |
651 apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname, | |
652 FALSE, curbuf, eap); | |
653 else | |
654 apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, | |
655 FALSE, NULL, eap); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
656 // 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 |
7 | 662 if (msg_scrolled == n) |
663 msg_scroll = m; | |
664 | |
665 #ifdef FEAT_EVAL | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
666 if (aborting()) // autocmds may abort script processing |
7 | 667 { |
668 --no_wait_return; | |
669 msg_scroll = msg_save; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
670 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 671 return FAIL; |
672 } | |
673 #endif | |
674 /* | |
675 * Don't allow the autocommands to change the current buffer. | |
676 * Try to re-open the file. | |
1834 | 677 * |
678 * Don't allow the autocommands to change the buffer name either | |
679 * (cd for example) if it invalidates fname or sfname. | |
7 | 680 */ |
681 if (!read_stdin && (curbuf != old_curbuf | |
1834 | 682 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) |
683 || (using_b_fname && (old_b_fname != curbuf->b_fname)) | |
7 | 684 || (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0)) |
685 { | |
686 --no_wait_return; | |
687 msg_scroll = msg_save; | |
688 if (fd < 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
689 emsg(_("E200: *ReadPre autocommands made the file unreadable")); |
7 | 690 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
691 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
|
692 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 693 return FAIL; |
694 } | |
695 } | |
696 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
697 // Autocommands may add lines to the file, need to check if it is empty |
7 | 698 wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
699 | |
700 if (!recoverymode && !filtering && !(flags & READ_DUMMY)) | |
701 { | |
702 /* | |
703 * Show the user that we are busy reading the input. Sometimes this | |
704 * may take a while. When reading from stdin another program may | |
705 * still be running, don't move the cursor to the last line, unless | |
706 * always using the GUI. | |
707 */ | |
708 if (read_stdin) | |
709 { | |
12863
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
710 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
|
711 { |
7 | 712 #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
|
713 # 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
|
714 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
|
715 # 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
|
716 mch_msg(_("Vim: Reading from stdin...\n")); |
7 | 717 #endif |
718 #ifdef FEAT_GUI | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
719 // 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
|
720 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
|
721 { |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
722 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
|
723 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
|
724 } |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
725 #endif |
e7ec107f6354
patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents:
12861
diff
changeset
|
726 } |
7 | 727 } |
728 else if (!read_buffer) | |
729 filemess(curbuf, sfname, (char_u *)"", 0); | |
730 } | |
731 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
732 msg_scroll = FALSE; // overwrite the file message |
7 | 733 |
734 /* | |
735 * Set linecnt now, before the "retry" caused by a wrong guess for | |
736 * fileformat, and after the autocommands, which may change them. | |
737 */ | |
738 linecnt = curbuf->b_ml.ml_line_count; | |
739 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
740 // "++bad=" argument. |
595 | 741 if (eap != NULL && eap->bad_char != 0) |
612 | 742 { |
595 | 743 bad_char_behavior = eap->bad_char; |
819 | 744 if (set_options) |
612 | 745 curbuf->b_bad_char = eap->bad_char; |
746 } | |
747 else | |
748 curbuf->b_bad_char = 0; | |
595 | 749 |
7 | 750 /* |
595 | 751 * Decide which 'encoding' to use or use first. |
7 | 752 */ |
753 if (eap != NULL && eap->force_enc != 0) | |
754 { | |
755 fenc = enc_canonize(eap->cmd + eap->force_enc); | |
756 fenc_alloced = TRUE; | |
595 | 757 keep_dest_enc = TRUE; |
7 | 758 } |
759 else if (curbuf->b_p_bin) | |
760 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
761 fenc = (char_u *)""; // binary: don't convert |
7 | 762 fenc_alloced = FALSE; |
763 } | |
764 else if (curbuf->b_help) | |
765 { | |
766 char_u firstline[80]; | |
301 | 767 int fc; |
7 | 768 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
769 // 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
|
770 // fails it must be latin1. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
771 // 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
|
772 // 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
|
773 // 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
|
774 // That is only in *.??x files. |
7 | 775 fenc = (char_u *)"latin1"; |
776 c = enc_utf8; | |
301 | 777 if (!c && !read_stdin) |
778 { | |
779 fc = fname[STRLEN(fname) - 1]; | |
780 if (TOLOWER_ASC(fc) == 'x') | |
781 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
782 // 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
|
783 // the start of the file. If the read() fails "len" is -1. |
2664 | 784 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
|
785 vim_lseek(fd, (off_T)0L, SEEK_SET); |
301 | 786 for (p = firstline; p < firstline + len; ++p) |
787 if (*p >= 0x80) | |
788 { | |
789 c = TRUE; | |
790 break; | |
791 } | |
792 } | |
7 | 793 } |
794 | |
795 if (c) | |
796 { | |
797 fenc_next = fenc; | |
798 fenc = (char_u *)"utf-8"; | |
799 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
800 // 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
|
801 // '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
|
802 // doesn't make sense. |
844 | 803 if (!enc_utf8) |
804 keep_dest_enc = TRUE; | |
7 | 805 } |
806 fenc_alloced = FALSE; | |
807 } | |
808 else if (*p_fencs == NUL) | |
809 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
810 fenc = curbuf->b_p_fenc; // use format from buffer |
7 | 811 fenc_alloced = FALSE; |
812 } | |
813 else | |
814 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
815 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
|
816 fenc = next_fenc(&fenc_next, &fenc_alloced); |
7 | 817 } |
818 | |
819 /* | |
820 * Jump back here to retry reading the file in different ways. | |
821 * Reasons to retry: | |
822 * - encoding conversion failed: try another one from "fenc_next" | |
823 * - BOM detected and fenc was set, need to setup conversion | |
824 * - "fileformat" check failed: try another | |
825 * | |
826 * Variables set for special retry actions: | |
827 * "file_rewind" Rewind the file to start reading it again. | |
828 * "advance_fenc" Advance "fenc" using "fenc_next". | |
829 * "skip_read" Re-use already read bytes (BOM detected). | |
830 * "did_iconv" iconv() conversion failed, try 'charconvert'. | |
831 * "keep_fileformat" Don't reset "fileformat". | |
832 * | |
833 * Other status indicators: | |
834 * "tmpname" When != NULL did conversion with 'charconvert'. | |
835 * Output file has to be deleted afterwards. | |
836 * "iconv_fd" When != -1 did conversion with iconv(). | |
837 */ | |
838 retry: | |
839 | |
840 if (file_rewind) | |
841 { | |
842 if (read_buffer) | |
843 { | |
844 read_buf_lnum = 1; | |
845 read_buf_col = 0; | |
846 } | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
847 else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0) |
7 | 848 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
849 // Can't rewind the file, give up. |
7 | 850 error = TRUE; |
851 goto failed; | |
852 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
853 // Delete the previously read lines. |
7 | 854 while (lnum > from) |
855 ml_delete(lnum--, FALSE); | |
856 file_rewind = FALSE; | |
819 | 857 if (set_options) |
1352 | 858 { |
7 | 859 curbuf->b_p_bomb = FALSE; |
1352 | 860 curbuf->b_start_bomb = FALSE; |
861 } | |
595 | 862 conv_error = 0; |
7 | 863 } |
864 | |
865 /* | |
866 * When retrying with another "fenc" and the first time "fileformat" | |
867 * will be reset. | |
868 */ | |
869 if (keep_fileformat) | |
870 keep_fileformat = FALSE; | |
871 else | |
872 { | |
873 if (eap != NULL && eap->force_ff != 0) | |
1742 | 874 { |
7 | 875 fileformat = get_fileformat_force(curbuf, eap); |
1742 | 876 try_unix = try_dos = try_mac = FALSE; |
877 } | |
7 | 878 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
|
879 fileformat = EOL_UNIX; // binary: use Unix format |
7 | 880 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
|
881 fileformat = get_fileformat(curbuf);// use format from buffer |
7 | 882 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
883 fileformat = EOL_UNKNOWN; // detect from file |
7 | 884 } |
885 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
886 #ifdef USE_ICONV |
7 | 887 if (iconv_fd != (iconv_t)-1) |
888 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
889 // aborted conversion with iconv(), close the descriptor |
7 | 890 iconv_close(iconv_fd); |
891 iconv_fd = (iconv_t)-1; | |
892 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
893 #endif |
7 | 894 |
895 if (advance_fenc) | |
896 { | |
897 /* | |
898 * Try the next entry in 'fileencodings'. | |
899 */ | |
900 advance_fenc = FALSE; | |
901 | |
902 if (eap != NULL && eap->force_enc != 0) | |
903 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
904 // 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
|
905 // without conversion. |
7 | 906 notconverted = TRUE; |
595 | 907 conv_error = 0; |
7 | 908 if (fenc_alloced) |
909 vim_free(fenc); | |
910 fenc = (char_u *)""; | |
911 fenc_alloced = FALSE; | |
912 } | |
913 else | |
914 { | |
915 if (fenc_alloced) | |
916 vim_free(fenc); | |
917 if (fenc_next != NULL) | |
918 { | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
919 fenc = next_fenc(&fenc_next, &fenc_alloced); |
7 | 920 } |
921 else | |
922 { | |
923 fenc = (char_u *)""; | |
924 fenc_alloced = FALSE; | |
925 } | |
926 } | |
927 if (tmpname != NULL) | |
928 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
929 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
|
930 VIM_CLEAR(tmpname); |
7 | 931 } |
932 } | |
933 | |
934 /* | |
1948 | 935 * Conversion may be required when the encoding of the file is different |
936 * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4. | |
7 | 937 */ |
938 fio_flags = 0; | |
1948 | 939 converted = need_conversion(fenc); |
940 if (converted) | |
7 | 941 { |
942 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
943 // "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
|
944 // for a BOM. |
7 | 945 if (STRCMP(fenc, ENC_UCSBOM) == 0) |
946 fio_flags = FIO_UCSBOM; | |
947 | |
948 /* | |
949 * Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be | |
950 * done. This is handled below after read(). Prepare the | |
951 * fio_flags to avoid having to parse the string each time. | |
952 * Also check for Unicode to Latin1 conversion, because iconv() | |
953 * appears not to handle this correctly. This works just like | |
954 * conversion to UTF-8 except how the resulting character is put in | |
955 * the buffer. | |
956 */ | |
957 else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0) | |
958 fio_flags = get_fio_flags(fenc); | |
959 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
960 #ifdef MSWIN |
7 | 961 /* |
962 * Conversion from an MS-Windows codepage to UTF-8 or another codepage | |
963 * is handled with MultiByteToWideChar(). | |
964 */ | |
965 if (fio_flags == 0) | |
966 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
|
967 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
968 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
969 #ifdef MACOS_CONVERT |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
970 // Conversion from Apple MacRoman to latin1 or UTF-8 |
7 | 971 if (fio_flags == 0) |
972 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
|
973 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
974 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
975 #ifdef USE_ICONV |
7 | 976 /* |
977 * Try using iconv() if we can't convert internally. | |
978 */ | |
979 if (fio_flags == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
980 # ifdef FEAT_EVAL |
7 | 981 && !did_iconv |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
982 # endif |
7 | 983 ) |
984 iconv_fd = (iconv_t)my_iconv_open( | |
985 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
|
986 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
987 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
988 #ifdef FEAT_EVAL |
7 | 989 /* |
990 * Use the 'charconvert' expression when conversion is required | |
991 * and we can't do it internally or with iconv(). | |
992 */ | |
993 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
|
994 && !read_fifo |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
995 # ifdef USE_ICONV |
7 | 996 && iconv_fd == (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
997 # endif |
7 | 998 ) |
999 { | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1000 # ifdef USE_ICONV |
7 | 1001 did_iconv = FALSE; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1002 # endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1003 // 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
|
1004 // "fileformat"). |
7 | 1005 if (tmpname == NULL) |
1006 { | |
1007 tmpname = readfile_charconvert(fname, fenc, &fd); | |
1008 if (tmpname == NULL) | |
1009 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1010 // Conversion failed. Try another one. |
7 | 1011 advance_fenc = TRUE; |
1012 if (fd < 0) | |
1013 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1014 // 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
|
1015 emsg(_("E202: Conversion made file unreadable!")); |
7 | 1016 error = TRUE; |
1017 goto failed; | |
1018 } | |
1019 goto retry; | |
1020 } | |
1021 } | |
1022 } | |
1023 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1024 #endif |
7 | 1025 { |
1026 if (fio_flags == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1027 #ifdef USE_ICONV |
7 | 1028 && iconv_fd == (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1029 #endif |
7 | 1030 ) |
1031 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1032 // 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
|
1033 // Try the next conversion in 'fileencodings' |
7 | 1034 advance_fenc = TRUE; |
1035 goto retry; | |
1036 } | |
1037 } | |
1038 } | |
1039 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1040 // 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
|
1041 // 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
|
1042 // 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
|
1043 can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc); |
7 | 1044 |
1045 if (!skip_read) | |
1046 { | |
1047 linerest = 0; | |
1048 filesize = 0; | |
1049 skip_count = lines_to_skip; | |
1050 read_count = lines_to_read; | |
1051 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
|
1052 #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
|
1053 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
|
1054 && 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
|
1055 && 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
|
1056 && !filtering |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
1057 && !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
|
1058 && !read_stdin |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1059 && !read_buffer); |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1060 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
|
1061 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
|
1062 #endif |
6122 | 1063 #ifdef FEAT_CRYPT |
1064 if (curbuf->b_cryptstate != NULL) | |
1065 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1066 // 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
|
1067 // it again. |
6122 | 1068 crypt_free_state(curbuf->b_cryptstate); |
1069 curbuf->b_cryptstate = NULL; | |
1070 } | |
1071 #endif | |
7 | 1072 } |
1073 | |
1074 while (!error && !got_int) | |
1075 { | |
1076 /* | |
1077 * We allocate as much space for the file as we can get, plus | |
1078 * space for the old line plus room for one terminating NUL. | |
1079 * 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
|
1080 * up to max_unsigned characters (and other things). |
7 | 1081 */ |
13804
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1082 if (!skip_read) |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1083 { |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1084 #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
|
1085 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
|
1086 #else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1087 // 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
|
1088 // 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
|
1089 // 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
|
1090 size = 0x10000L + linerest; |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1091 if (size > 0x100000L) |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1092 size = 0x100000L; |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1093 #endif |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1094 } |
8a35543f5f97
patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
1095 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1096 // 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
|
1097 if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL) |
7 | 1098 { |
1099 ++split; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1100 *ptr = NL; // split line by inserting a NL |
7 | 1101 size = 1; |
1102 } | |
1103 else | |
1104 { | |
1105 if (!skip_read) | |
1106 { | |
836 | 1107 for ( ; size >= 10; size = (long)((long_u)size >> 1)) |
7 | 1108 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16766
diff
changeset
|
1109 if ((new_buffer = lalloc(size + linerest + 1, |
7 | 1110 FALSE)) != NULL) |
1111 break; | |
1112 } | |
1113 if (new_buffer == NULL) | |
1114 { | |
1115 do_outofmem_msg((long_u)(size * 2 + linerest + 1)); | |
1116 error = TRUE; | |
1117 break; | |
1118 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1119 if (linerest) // copy characters from the previous buffer |
7 | 1120 mch_memmove(new_buffer, ptr - linerest, (size_t)linerest); |
1121 vim_free(buffer); | |
1122 buffer = new_buffer; | |
1123 ptr = buffer + linerest; | |
1124 line_start = buffer; | |
1125 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1126 // 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
|
1127 // 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
|
1128 // factor ICONV_MULT. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1129 // 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
|
1130 // 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
|
1131 // 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
|
1132 // 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
|
1133 // multiple of 2 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1134 // 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
|
1135 // multiple of 4 |
835 | 1136 real_size = (int)size; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1137 #ifdef USE_ICONV |
7 | 1138 if (iconv_fd != (iconv_t)-1) |
1139 size = size / ICONV_MULT; | |
1140 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1141 #endif |
7 | 1142 if (fio_flags & FIO_LATIN1) |
1143 size = size / 2; | |
1144 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1145 size = (size * 2 / 3) & ~1; | |
1146 else if (fio_flags & FIO_UCS4) | |
1147 size = (size * 2 / 3) & ~3; | |
1148 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
|
1149 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
|
1150 #ifdef MSWIN |
7 | 1151 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
|
1152 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
|
1153 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1154 #ifdef MACOS_CONVERT |
7 | 1155 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
|
1156 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
|
1157 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1158 |
7 | 1159 if (conv_restlen > 0) |
1160 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1161 // Insert unconverted bytes from previous line. |
7 | 1162 mch_memmove(ptr, conv_rest, conv_restlen); |
1163 ptr += conv_restlen; | |
1164 size -= conv_restlen; | |
1165 } | |
1166 | |
1167 if (read_buffer) | |
1168 { | |
1169 /* | |
1170 * Read bytes from curbuf. Used for converting text read | |
1171 * from stdin. | |
1172 */ | |
1173 if (read_buf_lnum > from) | |
1174 size = 0; | |
1175 else | |
1176 { | |
1177 int n, ni; | |
1178 long tlen; | |
1179 | |
1180 tlen = 0; | |
1181 for (;;) | |
1182 { | |
1183 p = ml_get(read_buf_lnum) + read_buf_col; | |
1184 n = (int)STRLEN(p); | |
1185 if ((int)tlen + n + 1 > size) | |
1186 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1187 // 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
|
1188 // 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
|
1189 // below. |
835 | 1190 n = (int)(size - tlen); |
7 | 1191 for (ni = 0; ni < n; ++ni) |
1192 { | |
1193 if (p[ni] == NL) | |
1194 ptr[tlen++] = NUL; | |
1195 else | |
1196 ptr[tlen++] = p[ni]; | |
1197 } | |
1198 read_buf_col += n; | |
1199 break; | |
1200 } | |
1201 else | |
1202 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1203 // 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
|
1204 // to NUL to reverse the effect done below. |
7 | 1205 for (ni = 0; ni < n; ++ni) |
1206 { | |
1207 if (p[ni] == NL) | |
1208 ptr[tlen++] = NUL; | |
1209 else | |
1210 ptr[tlen++] = p[ni]; | |
1211 } | |
1212 ptr[tlen++] = NL; | |
1213 read_buf_col = 0; | |
1214 if (++read_buf_lnum > from) | |
1215 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1216 // 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
|
1217 // end-of-line don't add it now either. |
7 | 1218 if (!curbuf->b_p_eol) |
1219 --tlen; | |
1220 size = tlen; | |
1221 break; | |
1222 } | |
1223 } | |
1224 } | |
1225 } | |
1226 } | |
1227 else | |
1228 { | |
1229 /* | |
1230 * Read bytes from the file. | |
1231 */ | |
2664 | 1232 size = read_eintr(fd, ptr, size); |
7 | 1233 } |
1234 | |
6122 | 1235 #ifdef FEAT_CRYPT |
1236 /* | |
1237 * At start of file: Check for magic number of encryption. | |
1238 */ | |
1239 if (filesize == 0 && size > 0) | |
1240 cryptkey = check_for_cryptkey(cryptkey, ptr, &size, | |
1241 &filesize, newfile, sfname, | |
1242 &did_ask_for_key); | |
1243 /* | |
1244 * Decrypt the read bytes. This is done before checking for | |
1245 * EOF because the crypt layer may be buffering. | |
1246 */ | |
12216
e971ef6c0dee
patch 8.0.0988: warning from Covscan about using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
12064
diff
changeset
|
1247 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
|
1248 && size > 0) |
6122 | 1249 { |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1250 # ifdef CRYPT_NOT_INPLACE |
6122 | 1251 if (crypt_works_inplace(curbuf->b_cryptstate)) |
1252 { | |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1253 # endif |
6122 | 1254 crypt_decode_inplace(curbuf->b_cryptstate, ptr, size); |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1255 # ifdef CRYPT_NOT_INPLACE |
6122 | 1256 } |
1257 else | |
1258 { | |
1259 char_u *newptr = NULL; | |
1260 int decrypted_size; | |
1261 | |
1262 decrypted_size = crypt_decode_alloc( | |
1263 curbuf->b_cryptstate, ptr, size, &newptr); | |
1264 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1265 // 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
|
1266 // 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
|
1267 if (decrypted_size == 0) |
6122 | 1268 continue; |
1269 | |
1270 if (linerest == 0) | |
1271 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1272 // 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
|
1273 // NULL, checked later). |
6122 | 1274 new_buffer = newptr; |
1275 } | |
1276 else | |
1277 { | |
1278 long_u new_size; | |
1279 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1280 // Need new buffer to add bytes carried over. |
6122 | 1281 new_size = (long_u)(decrypted_size + linerest + 1); |
1282 new_buffer = lalloc(new_size, FALSE); | |
1283 if (new_buffer == NULL) | |
1284 { | |
1285 do_outofmem_msg(new_size); | |
1286 error = TRUE; | |
1287 break; | |
1288 } | |
1289 | |
1290 mch_memmove(new_buffer, buffer, linerest); | |
1291 if (newptr != NULL) | |
1292 mch_memmove(new_buffer + linerest, newptr, | |
1293 decrypted_size); | |
1294 } | |
1295 | |
1296 if (new_buffer != NULL) | |
1297 { | |
1298 vim_free(buffer); | |
1299 buffer = new_buffer; | |
1300 new_buffer = NULL; | |
1301 line_start = buffer; | |
1302 ptr = buffer + linerest; | |
1303 } | |
1304 size = decrypted_size; | |
1305 } | |
15531
959cf4c63b18
patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1306 # endif |
6122 | 1307 } |
1308 #endif | |
1309 | |
7 | 1310 if (size <= 0) |
1311 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1312 if (size < 0) // read error |
7 | 1313 error = TRUE; |
1314 else if (conv_restlen > 0) | |
595 | 1315 { |
1597 | 1316 /* |
1317 * Reached end-of-file but some trailing bytes could | |
1318 * not be converted. Truncated file? | |
1319 */ | |
1320 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1321 // When we did a conversion report an error. |
1597 | 1322 if (fio_flags != 0 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1323 #ifdef USE_ICONV |
1597 | 1324 || iconv_fd != (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1325 #endif |
1597 | 1326 ) |
1327 { | |
4331 | 1328 if (can_retry) |
1329 goto rewind_retry; | |
1597 | 1330 if (conv_error == 0) |
1331 conv_error = curbuf->b_ml.ml_line_count | |
1332 - linecnt + 1; | |
1333 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1334 // Remember the first linenr with an illegal byte |
1597 | 1335 else if (illegal_byte == 0) |
1336 illegal_byte = curbuf->b_ml.ml_line_count | |
1337 - linecnt + 1; | |
1338 if (bad_char_behavior == BAD_DROP) | |
595 | 1339 { |
1597 | 1340 *(ptr - conv_restlen) = NUL; |
1341 conv_restlen = 0; | |
1342 } | |
1343 else | |
1344 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1345 // 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
|
1346 // 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
|
1347 // 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
|
1348 // works slightly differently. |
1597 | 1349 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
|
1350 #ifdef USE_ICONV |
1597 | 1351 || iconv_fd != (iconv_t)-1 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1352 #endif |
1597 | 1353 )) |
1354 { | |
1355 while (conv_restlen > 0) | |
1356 { | |
1357 *(--ptr) = bad_char_behavior; | |
1358 --conv_restlen; | |
1359 } | |
1360 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1361 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
|
1362 #ifdef USE_ICONV |
834 | 1363 if (iconv_fd != (iconv_t)-1) |
1364 { | |
1365 iconv_close(iconv_fd); | |
1366 iconv_fd = (iconv_t)-1; | |
1367 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1368 #endif |
595 | 1369 } |
1370 } | |
7 | 1371 } |
1372 } | |
1373 skip_read = FALSE; | |
1374 | |
1375 /* | |
1376 * At start of file (or after crypt magic number): Check for BOM. | |
1377 * Also check for a BOM for other Unicode encodings, but not after | |
1378 * converting with 'charconvert' or when a BOM has already been | |
1379 * found. | |
1380 */ | |
1381 if ((filesize == 0 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1382 #ifdef FEAT_CRYPT |
6122 | 1383 || (cryptkey != NULL |
1384 && filesize == crypt_get_header_len( | |
1385 crypt_get_method_nr(curbuf))) | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1386 #endif |
7 | 1387 ) |
1388 && (fio_flags == FIO_UCSBOM | |
1389 || (!curbuf->b_p_bomb | |
1390 && tmpname == NULL | |
1391 && (*fenc == 'u' || (*fenc == NUL && enc_utf8))))) | |
1392 { | |
1393 char_u *ccname; | |
1394 int blen; | |
1395 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1396 // no BOM detection in a short file or in binary mode |
7 | 1397 if (size < 2 || curbuf->b_p_bin) |
1398 ccname = NULL; | |
1399 else | |
1400 ccname = check_for_bom(ptr, size, &blen, | |
1401 fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); | |
1402 if (ccname != NULL) | |
1403 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1404 // Remove BOM from the text |
7 | 1405 filesize += blen; |
1406 size -= blen; | |
1407 mch_memmove(ptr, ptr + blen, (size_t)size); | |
819 | 1408 if (set_options) |
1352 | 1409 { |
7 | 1410 curbuf->b_p_bomb = TRUE; |
1352 | 1411 curbuf->b_start_bomb = TRUE; |
1412 } | |
7 | 1413 } |
1414 | |
1415 if (fio_flags == FIO_UCSBOM) | |
1416 { | |
1417 if (ccname == NULL) | |
1418 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1419 // No BOM detected: retry with next encoding. |
7 | 1420 advance_fenc = TRUE; |
1421 } | |
1422 else | |
1423 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1424 // BOM detected: set "fenc" and jump back |
7 | 1425 if (fenc_alloced) |
1426 vim_free(fenc); | |
1427 fenc = ccname; | |
1428 fenc_alloced = FALSE; | |
1429 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1430 // retry reading without getting new bytes or rewinding |
7 | 1431 skip_read = TRUE; |
1432 goto retry; | |
1433 } | |
1434 } | |
1597 | 1435 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1436 // Include not converted bytes. |
1597 | 1437 ptr -= conv_restlen; |
1438 size += conv_restlen; | |
1439 conv_restlen = 0; | |
7 | 1440 /* |
1441 * Break here for a read error or end-of-file. | |
1442 */ | |
1443 if (size <= 0) | |
1444 break; | |
1445 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1446 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1447 #ifdef USE_ICONV |
7 | 1448 if (iconv_fd != (iconv_t)-1) |
1449 { | |
1450 /* | |
1451 * Attempt conversion of the read bytes to 'encoding' using | |
1452 * iconv(). | |
1453 */ | |
1454 const char *fromp; | |
1455 char *top; | |
1456 size_t from_size; | |
1457 size_t to_size; | |
1458 | |
1459 fromp = (char *)ptr; | |
1460 from_size = size; | |
1461 ptr += size; | |
1462 top = (char *)ptr; | |
1463 to_size = real_size - size; | |
1464 | |
1465 /* | |
1466 * If there is conversion error or not enough room try using | |
179 | 1467 * another conversion. Except for when there is no |
1468 * alternative (help files). | |
7 | 1469 */ |
177 | 1470 while ((iconv(iconv_fd, (void *)&fromp, &from_size, |
1471 &top, &to_size) | |
7 | 1472 == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) |
1473 || from_size > CONV_RESTLEN) | |
177 | 1474 { |
595 | 1475 if (can_retry) |
375 | 1476 goto rewind_retry; |
595 | 1477 if (conv_error == 0) |
1478 conv_error = readfile_linenr(linecnt, | |
1479 ptr, (char_u *)top); | |
1480 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1481 // Deal with a bad byte and continue with the next. |
177 | 1482 ++fromp; |
1483 --from_size; | |
595 | 1484 if (bad_char_behavior == BAD_KEEP) |
1485 { | |
1486 *top++ = *(fromp - 1); | |
1487 --to_size; | |
1488 } | |
1489 else if (bad_char_behavior != BAD_DROP) | |
1490 { | |
1491 *top++ = bad_char_behavior; | |
1492 --to_size; | |
1493 } | |
177 | 1494 } |
7 | 1495 |
1496 if (from_size > 0) | |
1497 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1498 // 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
|
1499 // round. |
7 | 1500 mch_memmove(conv_rest, (char_u *)fromp, from_size); |
1501 conv_restlen = (int)from_size; | |
1502 } | |
1503 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1504 // move the linerest to before the converted characters |
7 | 1505 line_start = ptr - linerest; |
1506 mch_memmove(line_start, buffer, (size_t)linerest); | |
1507 size = (long)((char_u *)top - ptr); | |
1508 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1509 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1510 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
1511 #ifdef MSWIN |
7 | 1512 if (fio_flags & FIO_CODEPAGE) |
1513 { | |
595 | 1514 char_u *src, *dst; |
1515 WCHAR ucs2buf[3]; | |
1516 int ucs2len; | |
1517 int codepage = FIO_GET_CP(fio_flags); | |
1518 int bytelen; | |
1519 int found_bad; | |
1520 char replstr[2]; | |
1521 | |
7 | 1522 /* |
1523 * Conversion from an MS-Windows codepage or UTF-8 to UTF-8 or | |
595 | 1524 * a codepage, using standard MS-Windows functions. This |
1525 * requires two steps: | |
1526 * 1. convert from 'fileencoding' to ucs-2 | |
1527 * 2. convert from ucs-2 to 'encoding' | |
1528 * | |
1529 * Because there may be illegal bytes AND an incomplete byte | |
1530 * sequence at the end, we may have to do the conversion one | |
1531 * character at a time to get it right. | |
7 | 1532 */ |
595 | 1533 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1534 // Replacement string for WideCharToMultiByte(). |
595 | 1535 if (bad_char_behavior > 0) |
1536 replstr[0] = bad_char_behavior; | |
1537 else | |
1538 replstr[0] = '?'; | |
1539 replstr[1] = NUL; | |
1540 | |
1541 /* | |
1542 * Move the bytes to the end of the buffer, so that we have | |
1543 * room to put the result at the start. | |
1544 */ | |
1545 src = ptr + real_size - size; | |
1546 mch_memmove(src, ptr, size); | |
7 | 1547 |
1548 /* | |
595 | 1549 * Do the conversion. |
7 | 1550 */ |
595 | 1551 dst = ptr; |
1552 size = size; | |
1553 while (size > 0) | |
7 | 1554 { |
595 | 1555 found_bad = FALSE; |
7 | 1556 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1557 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 |
595 | 1558 if (codepage == CP_UTF8) |
7 | 1559 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1560 // 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
|
1561 // trailing bytes properly. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1562 // Get one UTF-8 character from src. |
835 | 1563 bytelen = (int)utf_ptr2len_len(src, size); |
595 | 1564 if (bytelen > size) |
1565 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1566 // 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
|
1567 // 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
|
1568 // deal with it as if they were illegal bytes. |
595 | 1569 if (bytelen <= CONV_RESTLEN) |
1570 break; | |
1571 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1572 // weird overlong byte sequence |
595 | 1573 bytelen = size; |
1574 found_bad = TRUE; | |
1575 } | |
1576 else | |
1577 { | |
799 | 1578 int u8c = utf_ptr2char(src); |
1579 | |
622 | 1580 if (u8c > 0xffff || (*src >= 0x80 && bytelen == 1)) |
595 | 1581 found_bad = TRUE; |
1582 ucs2buf[0] = u8c; | |
1583 ucs2len = 1; | |
1584 } | |
7 | 1585 } |
595 | 1586 else |
7 | 1587 # endif |
595 | 1588 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1589 // 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
|
1590 // from one to three bytes. |
595 | 1591 for (bytelen = 1; bytelen <= size && bytelen <= 3; |
1592 ++bytelen) | |
1593 { | |
1594 ucs2len = MultiByteToWideChar(codepage, | |
1595 MB_ERR_INVALID_CHARS, | |
1596 (LPCSTR)src, bytelen, | |
1597 ucs2buf, 3); | |
1598 if (ucs2len > 0) | |
1599 break; | |
1600 } | |
1601 if (ucs2len == 0) | |
1602 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1603 // 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
|
1604 // incomplete byte sequence. Otherwise discard |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1605 // one byte as a bad character. |
595 | 1606 if (size == 1) |
1607 break; | |
1608 found_bad = TRUE; | |
1609 bytelen = 1; | |
1610 } | |
1611 } | |
1612 | |
1613 if (!found_bad) | |
7 | 1614 { |
595 | 1615 int i; |
1616 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1617 // Convert "ucs2buf[ucs2len]" to 'enc' in "dst". |
595 | 1618 if (enc_utf8) |
1619 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1620 // From UCS-2 to UTF-8. Cannot fail. |
595 | 1621 for (i = 0; i < ucs2len; ++i) |
1622 dst += utf_char2bytes(ucs2buf[i], dst); | |
1623 } | |
1624 else | |
1625 { | |
1626 BOOL bad = FALSE; | |
1627 int dstlen; | |
1628 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1629 // 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
|
1630 // conversion uses the default character "?", |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1631 // the data doesn't fit in this encoding. |
595 | 1632 dstlen = WideCharToMultiByte(enc_codepage, 0, |
1633 (LPCWSTR)ucs2buf, ucs2len, | |
835 | 1634 (LPSTR)dst, (int)(src - dst), |
595 | 1635 replstr, &bad); |
1636 if (bad) | |
1637 found_bad = TRUE; | |
1638 else | |
1639 dst += dstlen; | |
1640 } | |
7 | 1641 } |
595 | 1642 |
1643 if (found_bad) | |
1644 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1645 // Deal with bytes we can't convert. |
595 | 1646 if (can_retry) |
1647 goto rewind_retry; | |
1648 if (conv_error == 0) | |
1649 conv_error = readfile_linenr(linecnt, ptr, dst); | |
1650 if (bad_char_behavior != BAD_DROP) | |
1651 { | |
1652 if (bad_char_behavior == BAD_KEEP) | |
1653 { | |
1654 mch_memmove(dst, src, bytelen); | |
1655 dst += bytelen; | |
1656 } | |
1657 else | |
1658 *dst++ = bad_char_behavior; | |
1659 } | |
1660 } | |
1661 | |
1662 src += bytelen; | |
1663 size -= bytelen; | |
7 | 1664 } |
595 | 1665 |
1666 if (size > 0) | |
7 | 1667 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1668 // An incomplete byte sequence remaining. |
595 | 1669 mch_memmove(conv_rest, src, size); |
1670 conv_restlen = size; | |
7 | 1671 } |
595 | 1672 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1673 // The new size is equal to how much "dst" was advanced. |
835 | 1674 size = (long)(dst - ptr); |
7 | 1675 } |
1676 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1677 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1678 #ifdef MACOS_CONVERT |
7 | 1679 if (fio_flags & FIO_MACROMAN) |
1680 { | |
1681 /* | |
1682 * Conversion from Apple MacRoman char encoding to UTF-8 or | |
18 | 1683 * latin1. This is in os_mac_conv.c. |
7 | 1684 */ |
18 | 1685 if (macroman2enc(ptr, &size, real_size) == FAIL) |
7 | 1686 goto rewind_retry; |
1687 } | |
1688 else | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1689 #endif |
7 | 1690 if (fio_flags != 0) |
1691 { | |
1692 int u8c; | |
1693 char_u *dest; | |
1694 char_u *tail = NULL; | |
1695 | |
1696 /* | |
1697 * "enc_utf8" set: Convert Unicode or Latin1 to UTF-8. | |
1698 * "enc_utf8" not set: Convert Unicode to Latin1. | |
1699 * Go from end to start through the buffer, because the number | |
1700 * of bytes may increase. | |
1701 * "dest" points to after where the UTF-8 bytes go, "p" points | |
1702 * to after the next character to convert. | |
1703 */ | |
1704 dest = ptr + real_size; | |
1705 if (fio_flags == FIO_LATIN1 || fio_flags == FIO_UTF8) | |
1706 { | |
1707 p = ptr + size; | |
1708 if (fio_flags == FIO_UTF8) | |
1709 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1710 // Check for a trailing incomplete UTF-8 sequence |
7 | 1711 tail = ptr + size - 1; |
1712 while (tail > ptr && (*tail & 0xc0) == 0x80) | |
1713 --tail; | |
1714 if (tail + utf_byte2len(*tail) <= ptr + size) | |
1715 tail = NULL; | |
1716 else | |
1717 p = tail; | |
1718 } | |
1719 } | |
1720 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1721 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1722 // Check for a trailing byte |
7 | 1723 p = ptr + (size & ~1); |
1724 if (size & 1) | |
1725 tail = p; | |
1726 if ((fio_flags & FIO_UTF16) && p > ptr) | |
1727 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1728 // Check for a trailing leading word |
7 | 1729 if (fio_flags & FIO_ENDIAN_L) |
1730 { | |
1731 u8c = (*--p << 8); | |
1732 u8c += *--p; | |
1733 } | |
1734 else | |
1735 { | |
1736 u8c = *--p; | |
1737 u8c += (*--p << 8); | |
1738 } | |
1739 if (u8c >= 0xd800 && u8c <= 0xdbff) | |
1740 tail = p; | |
1741 else | |
1742 p += 2; | |
1743 } | |
1744 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1745 else // FIO_UCS4 |
7 | 1746 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1747 // Check for trailing 1, 2 or 3 bytes |
7 | 1748 p = ptr + (size & ~3); |
1749 if (size & 3) | |
1750 tail = p; | |
1751 } | |
1752 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1753 // 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
|
1754 // conv_rest[]. |
7 | 1755 if (tail != NULL) |
1756 { | |
1757 conv_restlen = (int)((ptr + size) - tail); | |
1758 mch_memmove(conv_rest, (char_u *)tail, conv_restlen); | |
1759 size -= conv_restlen; | |
1760 } | |
1761 | |
1762 | |
1763 while (p > ptr) | |
1764 { | |
1765 if (fio_flags & FIO_LATIN1) | |
1766 u8c = *--p; | |
1767 else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) | |
1768 { | |
1769 if (fio_flags & FIO_ENDIAN_L) | |
1770 { | |
1771 u8c = (*--p << 8); | |
1772 u8c += *--p; | |
1773 } | |
1774 else | |
1775 { | |
1776 u8c = *--p; | |
1777 u8c += (*--p << 8); | |
1778 } | |
1779 if ((fio_flags & FIO_UTF16) | |
1780 && u8c >= 0xdc00 && u8c <= 0xdfff) | |
1781 { | |
1782 int u16c; | |
1783 | |
1784 if (p == ptr) | |
1785 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1786 // Missing leading word. |
7 | 1787 if (can_retry) |
1788 goto rewind_retry; | |
595 | 1789 if (conv_error == 0) |
1790 conv_error = readfile_linenr(linecnt, | |
1791 ptr, p); | |
1792 if (bad_char_behavior == BAD_DROP) | |
1793 continue; | |
1794 if (bad_char_behavior != BAD_KEEP) | |
1795 u8c = bad_char_behavior; | |
7 | 1796 } |
1797 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1798 // 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
|
1799 // word and compute the resulting character |
7 | 1800 if (fio_flags & FIO_ENDIAN_L) |
1801 { | |
1802 u16c = (*--p << 8); | |
1803 u16c += *--p; | |
1804 } | |
1805 else | |
1806 { | |
1807 u16c = *--p; | |
1808 u16c += (*--p << 8); | |
1809 } | |
595 | 1810 u8c = 0x10000 + ((u16c & 0x3ff) << 10) |
1811 + (u8c & 0x3ff); | |
1812 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1813 // Check if the word is indeed a leading word. |
7 | 1814 if (u16c < 0xd800 || u16c > 0xdbff) |
1815 { | |
1816 if (can_retry) | |
1817 goto rewind_retry; | |
595 | 1818 if (conv_error == 0) |
1819 conv_error = readfile_linenr(linecnt, | |
1820 ptr, p); | |
1821 if (bad_char_behavior == BAD_DROP) | |
1822 continue; | |
1823 if (bad_char_behavior != BAD_KEEP) | |
1824 u8c = bad_char_behavior; | |
7 | 1825 } |
1826 } | |
1827 } | |
1828 else if (fio_flags & FIO_UCS4) | |
1829 { | |
1830 if (fio_flags & FIO_ENDIAN_L) | |
1831 { | |
12698
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1832 u8c = (unsigned)*--p << 24; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1833 u8c += (unsigned)*--p << 16; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1834 u8c += (unsigned)*--p << 8; |
7 | 1835 u8c += *--p; |
1836 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1837 else // big endian |
7 | 1838 { |
1839 u8c = *--p; | |
12698
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1840 u8c += (unsigned)*--p << 8; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1841 u8c += (unsigned)*--p << 16; |
6d3d64be7945
patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
1842 u8c += (unsigned)*--p << 24; |
7 | 1843 } |
1844 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1845 else // UTF-8 |
7 | 1846 { |
1847 if (*--p < 0x80) | |
1848 u8c = *p; | |
1849 else | |
1850 { | |
1851 len = utf_head_off(ptr, p); | |
595 | 1852 p -= len; |
1853 u8c = utf_ptr2char(p); | |
7 | 1854 if (len == 0) |
1855 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1856 // 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
|
1857 // 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
|
1858 // report the error. |
7 | 1859 if (can_retry) |
1860 goto rewind_retry; | |
595 | 1861 if (conv_error == 0) |
1862 conv_error = readfile_linenr(linecnt, | |
1863 ptr, p); | |
1864 if (bad_char_behavior == BAD_DROP) | |
1865 continue; | |
1866 if (bad_char_behavior != BAD_KEEP) | |
1867 u8c = bad_char_behavior; | |
7 | 1868 } |
1869 } | |
1870 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1871 if (enc_utf8) // produce UTF-8 |
7 | 1872 { |
1873 dest -= utf_char2len(u8c); | |
1874 (void)utf_char2bytes(u8c, dest); | |
1875 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1876 else // produce Latin1 |
7 | 1877 { |
1878 --dest; | |
1879 if (u8c >= 0x100) | |
1880 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1881 // 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
|
1882 // 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
|
1883 // report the error. |
595 | 1884 if (can_retry) |
7 | 1885 goto rewind_retry; |
595 | 1886 if (conv_error == 0) |
1887 conv_error = readfile_linenr(linecnt, ptr, p); | |
1888 if (bad_char_behavior == BAD_DROP) | |
1889 ++dest; | |
1890 else if (bad_char_behavior == BAD_KEEP) | |
1891 *dest = u8c; | |
1892 else if (eap != NULL && eap->bad_char != 0) | |
1893 *dest = bad_char_behavior; | |
1894 else | |
1895 *dest = 0xBF; | |
7 | 1896 } |
1897 else | |
1898 *dest = u8c; | |
1899 } | |
1900 } | |
1901 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1902 // move the linerest to before the converted characters |
7 | 1903 line_start = dest - linerest; |
1904 mch_memmove(line_start, buffer, (size_t)linerest); | |
1905 size = (long)((ptr + real_size) - dest); | |
1906 ptr = dest; | |
1907 } | |
1597 | 1908 else if (enc_utf8 && !curbuf->b_p_bin) |
1909 { | |
1910 int incomplete_tail = FALSE; | |
1911 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1912 // Reading UTF-8: Check if the bytes are valid UTF-8. |
1597 | 1913 for (p = ptr; ; ++p) |
7 | 1914 { |
835 | 1915 int todo = (int)((ptr + size) - p); |
595 | 1916 int l; |
1917 | |
1918 if (todo <= 0) | |
1919 break; | |
7 | 1920 if (*p >= 0x80) |
1921 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1922 // 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
|
1923 // 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
|
1924 // 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
|
1925 // then. |
595 | 1926 l = utf_ptr2len_len(p, todo); |
1597 | 1927 if (l > todo && !incomplete_tail) |
7 | 1928 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1929 // 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
|
1930 // 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
|
1931 // 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
|
1932 // we have already done so. |
1597 | 1933 if (p > ptr || filesize > 0) |
1934 incomplete_tail = TRUE; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1935 // 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
|
1936 // 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
|
1937 // already done so. |
1597 | 1938 if (p > ptr) |
1939 { | |
1940 conv_restlen = todo; | |
1941 mch_memmove(conv_rest, p, conv_restlen); | |
1942 size -= conv_restlen; | |
1943 break; | |
1944 } | |
7 | 1945 } |
1597 | 1946 if (l == 1 || l > todo) |
595 | 1947 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1948 // 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
|
1949 // 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
|
1950 // file is more likely than a conversion error. |
1597 | 1951 if (can_retry && !incomplete_tail) |
595 | 1952 break; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1953 #ifdef USE_ICONV |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1954 // When we did a conversion report an error. |
595 | 1955 if (iconv_fd != (iconv_t)-1 && conv_error == 0) |
1956 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
|
1957 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1958 // Remember the first linenr with an illegal byte |
1597 | 1959 if (conv_error == 0 && illegal_byte == 0) |
1960 illegal_byte = readfile_linenr(linecnt, ptr, p); | |
595 | 1961 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1962 // Drop, keep or replace the bad byte. |
595 | 1963 if (bad_char_behavior == BAD_DROP) |
1964 { | |
1597 | 1965 mch_memmove(p, p + 1, todo - 1); |
595 | 1966 --p; |
1967 --size; | |
1968 } | |
1969 else if (bad_char_behavior != BAD_KEEP) | |
1970 *p = bad_char_behavior; | |
1971 } | |
1597 | 1972 else |
1973 p += l - 1; | |
7 | 1974 } |
1975 } | |
1597 | 1976 if (p < ptr + size && !incomplete_tail) |
7 | 1977 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1978 // Detected a UTF-8 error. |
7 | 1979 rewind_retry: |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1980 // Retry reading with another conversion. |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1981 #if defined(FEAT_EVAL) && defined(USE_ICONV) |
595 | 1982 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
|
1983 // iconv() failed, try 'charconvert' |
595 | 1984 did_iconv = TRUE; |
7 | 1985 else |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1986 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1987 // use next item from 'fileencodings' |
595 | 1988 advance_fenc = TRUE; |
1989 file_rewind = TRUE; | |
1990 goto retry; | |
7 | 1991 } |
1992 } | |
1993 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
1994 // count the number of characters (after conversion!) |
7 | 1995 filesize += size; |
1996 | |
1997 /* | |
1998 * when reading the first part of a file: guess EOL type | |
1999 */ | |
2000 if (fileformat == EOL_UNKNOWN) | |
2001 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2002 // First try finding a NL, for Dos and Unix |
7 | 2003 if (try_dos || try_unix) |
2004 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2005 // Reset the carriage return counter. |
6635 | 2006 if (try_mac) |
2007 try_mac = 1; | |
2008 | |
7 | 2009 for (p = ptr; p < ptr + size; ++p) |
2010 { | |
2011 if (*p == NL) | |
2012 { | |
2013 if (!try_unix | |
2014 || (try_dos && p > ptr && p[-1] == CAR)) | |
2015 fileformat = EOL_DOS; | |
2016 else | |
2017 fileformat = EOL_UNIX; | |
2018 break; | |
2019 } | |
6618 | 2020 else if (*p == CAR && try_mac) |
2021 try_mac++; | |
7 | 2022 } |
2023 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2024 // Don't give in to EOL_UNIX if EOL_MAC is more likely |
7 | 2025 if (fileformat == EOL_UNIX && try_mac) |
2026 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2027 // Need to reset the counters when retrying fenc. |
7 | 2028 try_mac = 1; |
2029 try_unix = 1; | |
2030 for (; p >= ptr && *p != CAR; p--) | |
2031 ; | |
2032 if (p >= ptr) | |
2033 { | |
2034 for (p = ptr; p < ptr + size; ++p) | |
2035 { | |
2036 if (*p == NL) | |
2037 try_unix++; | |
2038 else if (*p == CAR) | |
2039 try_mac++; | |
2040 } | |
2041 if (try_mac > try_unix) | |
2042 fileformat = EOL_MAC; | |
2043 } | |
2044 } | |
6618 | 2045 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
|
2046 // 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
|
2047 // all: use the default format. |
6618 | 2048 fileformat = default_fileformat(); |
7 | 2049 } |
2050 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2051 // No NL found: may use Mac format |
7 | 2052 if (fileformat == EOL_UNKNOWN && try_mac) |
2053 fileformat = EOL_MAC; | |
2054 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2055 // Still nothing found? Use first format in 'ffs' |
7 | 2056 if (fileformat == EOL_UNKNOWN) |
2057 fileformat = default_fileformat(); | |
2058 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2059 // if editing a new file: may set p_tx and p_ff |
819 | 2060 if (set_options) |
7 | 2061 set_fileformat(fileformat, OPT_LOCAL); |
2062 } | |
2063 } | |
2064 | |
2065 /* | |
2066 * This loop is executed once for every character read. | |
2067 * Keep it fast! | |
2068 */ | |
2069 if (fileformat == EOL_MAC) | |
2070 { | |
2071 --ptr; | |
2072 while (++ptr, --size >= 0) | |
2073 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2074 // catch most common case first |
7 | 2075 if ((c = *ptr) != NUL && c != CAR && c != NL) |
2076 continue; | |
2077 if (c == NUL) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2078 *ptr = NL; // NULs are replaced by newlines! |
7 | 2079 else if (c == NL) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2080 *ptr = CAR; // NLs are replaced by CRs! |
7 | 2081 else |
2082 { | |
2083 if (skip_count == 0) | |
2084 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2085 *ptr = NUL; // end of line |
7 | 2086 len = (colnr_T) (ptr - line_start + 1); |
2087 if (ml_append(lnum, line_start, len, newfile) == FAIL) | |
2088 { | |
2089 error = TRUE; | |
2090 break; | |
2091 } | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2092 #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
|
2093 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
|
2094 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
|
2095 #endif |
7 | 2096 ++lnum; |
2097 if (--read_count == 0) | |
2098 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2099 error = TRUE; // break loop |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2100 line_start = ptr; // nothing left to write |
7 | 2101 break; |
2102 } | |
2103 } | |
2104 else | |
2105 --skip_count; | |
2106 line_start = ptr + 1; | |
2107 } | |
2108 } | |
2109 } | |
2110 else | |
2111 { | |
2112 --ptr; | |
2113 while (++ptr, --size >= 0) | |
2114 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2115 if ((c = *ptr) != NUL && c != NL) // catch most common case |
7 | 2116 continue; |
2117 if (c == NUL) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2118 *ptr = NL; // NULs are replaced by newlines! |
7 | 2119 else |
2120 { | |
2121 if (skip_count == 0) | |
2122 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2123 *ptr = NUL; // end of line |
7 | 2124 len = (colnr_T)(ptr - line_start + 1); |
2125 if (fileformat == EOL_DOS) | |
2126 { | |
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
|
2127 if (ptr > line_start && ptr[-1] == CAR) |
7 | 2128 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2129 // remove CR before NL |
7 | 2130 ptr[-1] = NUL; |
2131 --len; | |
2132 } | |
2133 /* | |
2134 * Reading in Dos format, but no CR-LF found! | |
2135 * When 'fileformats' includes "unix", delete all | |
2136 * the lines read so far and start all over again. | |
2137 * Otherwise give an error message later. | |
2138 */ | |
2139 else if (ff_error != EOL_DOS) | |
2140 { | |
2141 if ( try_unix | |
2142 && !read_stdin | |
2143 && (read_buffer | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
2144 || 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
|
2145 == 0)) |
7 | 2146 { |
2147 fileformat = EOL_UNIX; | |
819 | 2148 if (set_options) |
7 | 2149 set_fileformat(EOL_UNIX, OPT_LOCAL); |
2150 file_rewind = TRUE; | |
2151 keep_fileformat = TRUE; | |
2152 goto retry; | |
2153 } | |
2154 ff_error = EOL_DOS; | |
2155 } | |
2156 } | |
2157 if (ml_append(lnum, line_start, len, newfile) == FAIL) | |
2158 { | |
2159 error = TRUE; | |
2160 break; | |
2161 } | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2162 #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
|
2163 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
|
2164 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
|
2165 #endif |
7 | 2166 ++lnum; |
2167 if (--read_count == 0) | |
2168 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2169 error = TRUE; // break loop |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2170 line_start = ptr; // nothing left to write |
7 | 2171 break; |
2172 } | |
2173 } | |
2174 else | |
2175 --skip_count; | |
2176 line_start = ptr + 1; | |
2177 } | |
2178 } | |
2179 } | |
2180 linerest = (long)(ptr - line_start); | |
2181 ui_breakcheck(); | |
2182 } | |
2183 | |
2184 failed: | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2185 // not an error, max. number of lines reached |
7 | 2186 if (error && read_count == 0) |
2187 error = FALSE; | |
2188 | |
2189 /* | |
2190 * If we get EOF in the middle of a line, note the fact and | |
2191 * complete the line ourselves. | |
2192 * In Dos format ignore a trailing CTRL-Z, unless 'binary' set. | |
2193 */ | |
2194 if (!error | |
2195 && !got_int | |
2196 && linerest != 0 | |
2197 && !(!curbuf->b_p_bin | |
2198 && fileformat == EOL_DOS | |
2199 && *line_start == Ctrl_Z | |
2200 && ptr == line_start + 1)) | |
2201 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2202 // remember for when writing |
819 | 2203 if (set_options) |
7 | 2204 curbuf->b_p_eol = FALSE; |
2205 *ptr = NUL; | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2206 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
|
2207 if (ml_append(lnum, line_start, len, newfile) == FAIL) |
7 | 2208 error = TRUE; |
2209 else | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2210 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2211 #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
|
2212 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
|
2213 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
|
2214 #endif |
7 | 2215 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
|
2216 } |
7 | 2217 } |
2218 | |
819 | 2219 if (set_options) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2220 save_file_ff(curbuf); // remember the current file format |
7 | 2221 |
2222 #ifdef FEAT_CRYPT | |
6122 | 2223 if (curbuf->b_cryptstate != NULL) |
2224 { | |
2225 crypt_free_state(curbuf->b_cryptstate); | |
2226 curbuf->b_cryptstate = NULL; | |
2227 } | |
2228 if (cryptkey != NULL && cryptkey != curbuf->b_p_key) | |
2229 crypt_free_key(cryptkey); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2230 // 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
|
2231 // encryption was used. |
7 | 2232 #endif |
2233 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2234 // 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
|
2235 // Also for ":read ++edit file". |
819 | 2236 if (set_options) |
7 | 2237 set_string_option_direct((char_u *)"fenc", -1, fenc, |
694 | 2238 OPT_FREE|OPT_LOCAL, 0); |
7 | 2239 if (fenc_alloced) |
2240 vim_free(fenc); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2241 #ifdef USE_ICONV |
7 | 2242 if (iconv_fd != (iconv_t)-1) |
2243 iconv_close(iconv_fd); | |
2244 #endif | |
2245 | |
2246 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
|
2247 close(fd); // errors are ignored |
2003 | 2248 #ifdef HAVE_FD_CLOEXEC |
2249 else | |
2250 { | |
2251 int fdflags = fcntl(fd, F_GETFD); | |
2252 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
|
2253 (void)fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); |
2003 | 2254 } |
2255 #endif | |
7 | 2256 vim_free(buffer); |
2257 | |
2258 #ifdef HAVE_DUP | |
2259 if (read_stdin) | |
2260 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2261 // Use stderr for stdin, makes shell commands work. |
7 | 2262 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
|
2263 vim_ignored = dup(2); |
7 | 2264 } |
2265 #endif | |
2266 | |
2267 if (tmpname != NULL) | |
2268 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2269 mch_remove(tmpname); // delete converted file |
7 | 2270 vim_free(tmpname); |
2271 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2272 --no_wait_return; // may wait for return now |
7 | 2273 |
2274 /* | |
2275 * In recovery mode everything but autocommands is skipped. | |
2276 */ | |
2277 if (!recoverymode) | |
2278 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2279 // need to delete the last line, which comes from the empty buffer |
7 | 2280 if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) |
2281 { | |
2282 #ifdef FEAT_NETBEANS_INTG | |
2283 netbeansFireChanges = 0; | |
2284 #endif | |
2285 ml_delete(curbuf->b_ml.ml_line_count, FALSE); | |
2286 #ifdef FEAT_NETBEANS_INTG | |
2287 netbeansFireChanges = 1; | |
2288 #endif | |
2289 --linecnt; | |
2290 } | |
2291 linecnt = curbuf->b_ml.ml_line_count - linecnt; | |
2292 if (filesize == 0) | |
2293 linecnt = 0; | |
2294 if (newfile || read_buffer) | |
1201 | 2295 { |
7 | 2296 redraw_curbuf_later(NOT_VALID); |
1201 | 2297 #ifdef FEAT_DIFF |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2298 // 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
|
2299 // be updated. |
1201 | 2300 diff_invalidate(curbuf); |
2301 #endif | |
2302 #ifdef FEAT_FOLDING | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2303 // 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
|
2304 // before triggering autocommands. |
1201 | 2305 foldUpdateAll(curwin); |
2306 #endif | |
2307 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2308 else if (linecnt) // appended at least one line |
7 | 2309 appended_lines_mark(from, linecnt); |
2310 | |
2311 #ifndef ALWAYS_USE_GUI | |
2312 /* | |
2313 * If we were reading from the same terminal as where messages go, | |
2314 * the screen will have been messed up. | |
2315 * Switch on raw mode now and clear the screen. | |
2316 */ | |
2317 if (read_stdin) | |
2318 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2319 settmode(TMODE_RAW); // set to raw mode |
7 | 2320 starttermcap(); |
2321 screenclear(); | |
2322 } | |
2323 #endif | |
2324 | |
2325 if (got_int) | |
2326 { | |
2327 if (!(flags & READ_DUMMY)) | |
2328 { | |
2329 filemess(curbuf, sfname, (char_u *)_(e_interr), 0); | |
2330 if (newfile) | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2331 curbuf->b_p_ro = TRUE; // must use "w!" now |
7 | 2332 } |
2333 msg_scroll = msg_save; | |
2334 #ifdef FEAT_VIMINFO | |
2335 check_marks_read(); | |
2336 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2337 return OK; // an interrupt isn't really an error |
7 | 2338 } |
2339 | |
2340 if (!filtering && !(flags & READ_DUMMY)) | |
2341 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2342 msg_add_fname(curbuf, sfname); // fname in IObuff with quotes |
7 | 2343 c = FALSE; |
2344 | |
2345 #ifdef UNIX | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2346 if (S_ISFIFO(perm)) // fifo |
7 | 2347 { |
2348 STRCAT(IObuff, _("[fifo]")); | |
2349 c = TRUE; | |
2350 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2351 if (S_ISSOCK(perm)) // or socket |
7 | 2352 { |
2353 STRCAT(IObuff, _("[socket]")); | |
2354 c = TRUE; | |
2355 } | |
1313 | 2356 # ifdef OPEN_CHR_FILES |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2357 if (S_ISCHR(perm)) // or character special |
1313 | 2358 { |
2359 STRCAT(IObuff, _("[character special]")); | |
2360 c = TRUE; | |
2361 } | |
2362 # endif | |
7 | 2363 #endif |
2364 if (curbuf->b_p_ro) | |
2365 { | |
2366 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]")); | |
2367 c = TRUE; | |
2368 } | |
2369 if (read_no_eol_lnum) | |
2370 { | |
2371 msg_add_eol(); | |
2372 c = TRUE; | |
2373 } | |
2374 if (ff_error == EOL_DOS) | |
2375 { | |
2376 STRCAT(IObuff, _("[CR missing]")); | |
2377 c = TRUE; | |
2378 } | |
2379 if (split) | |
2380 { | |
2381 STRCAT(IObuff, _("[long lines split]")); | |
2382 c = TRUE; | |
2383 } | |
2384 if (notconverted) | |
2385 { | |
2386 STRCAT(IObuff, _("[NOT converted]")); | |
2387 c = TRUE; | |
2388 } | |
2389 else if (converted) | |
2390 { | |
2391 STRCAT(IObuff, _("[converted]")); | |
2392 c = TRUE; | |
2393 } | |
2394 #ifdef FEAT_CRYPT | |
2395 if (cryptkey != NULL) | |
2396 { | |
6122 | 2397 crypt_append_msg(curbuf); |
7 | 2398 c = TRUE; |
2399 } | |
2400 #endif | |
595 | 2401 if (conv_error != 0) |
2402 { | |
2403 sprintf((char *)IObuff + STRLEN(IObuff), | |
2404 _("[CONVERSION ERROR in line %ld]"), (long)conv_error); | |
7 | 2405 c = TRUE; |
2406 } | |
2407 else if (illegal_byte > 0) | |
2408 { | |
2409 sprintf((char *)IObuff + STRLEN(IObuff), | |
2410 _("[ILLEGAL BYTE in line %ld]"), (long)illegal_byte); | |
2411 c = TRUE; | |
2412 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2413 else if (error) |
7 | 2414 { |
2415 STRCAT(IObuff, _("[READ ERRORS]")); | |
2416 c = TRUE; | |
2417 } | |
2418 if (msg_add_fileformat(fileformat)) | |
2419 c = TRUE; | |
2420 #ifdef FEAT_CRYPT | |
2421 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
|
2422 msg_add_lines(c, (long)linecnt, filesize |
6122 | 2423 - crypt_get_header_len(crypt_get_method_nr(curbuf))); |
7 | 2424 else |
2425 #endif | |
2426 msg_add_lines(c, (long)linecnt, filesize); | |
2427 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
2428 VIM_CLEAR(keep_msg); |
7 | 2429 msg_scrolled_ign = TRUE; |
2430 #ifdef ALWAYS_USE_GUI | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2431 // 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
|
2432 // message box (which might be shown when exiting!) |
7 | 2433 if (read_stdin || read_buffer) |
2434 p = msg_may_trunc(FALSE, IObuff); | |
2435 else | |
2436 #endif | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2437 { |
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2438 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
|
2439 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
|
2440 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
|
2441 } |
7 | 2442 if (read_stdin || read_buffer || restart_edit != 0 |
540 | 2443 || (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
|
2444 // 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
|
2445 // - 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
|
2446 // - 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
|
2447 // before redrawing). |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2448 // - 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
|
2449 // prompt. |
679 | 2450 set_keep_msg(p, 0); |
7 | 2451 msg_scrolled_ign = FALSE; |
2452 } | |
2453 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2454 // with errors writing the file requires ":w!" |
7 | 2455 if (newfile && (error |
595 | 2456 || conv_error != 0 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2457 || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP))) |
7 | 2458 curbuf->b_p_ro = TRUE; |
2459 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2460 u_clearline(); // cannot use "U" command after adding lines |
7 | 2461 |
2462 /* | |
2463 * In Ex mode: cursor at last new line. | |
2464 * Otherwise: cursor at first new line. | |
2465 */ | |
2466 if (exmode_active) | |
2467 curwin->w_cursor.lnum = from + linecnt; | |
2468 else | |
2469 curwin->w_cursor.lnum = from + 1; | |
2470 check_cursor_lnum(); | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2471 beginline(BL_WHITE | BL_FIX); // on first non-blank |
7 | 2472 |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2473 if (!cmdmod.lockmarks) |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2474 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18199
diff
changeset
|
2475 // 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
|
2476 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
|
2477 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
|
2478 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
|
2479 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
|
2480 } |
696 | 2481 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2482 #ifdef MSWIN |
696 | 2483 /* |
2484 * Work around a weird problem: When a file has two links (only | |
2485 * possible on NTFS) and we write through one link, then stat() it | |
1651 | 2486 * through the other link, the timestamp information may be wrong. |
696 | 2487 * It's correct again after reading the file, thus reset the timestamp |
2488 * here. | |
2489 */ | |
2490 if (newfile && !read_stdin && !read_buffer | |
2491 && mch_stat((char *)fname, &st) >= 0) | |
2492 { | |
2493 buf_store_time(curbuf, &st, fname); | |
2494 curbuf->b_mtime_read = curbuf->b_mtime; | |
2495 } | |
2496 #endif | |
7 | 2497 } |
2498 msg_scroll = msg_save; | |
2499 | |
2500 #ifdef FEAT_VIMINFO | |
2501 /* | |
2502 * Get the marks before executing autocommands, so they can be used there. | |
2503 */ | |
2504 check_marks_read(); | |
2505 #endif | |
2506 | |
2507 /* | |
6933 | 2508 * We remember if the last line of the read didn't have |
2509 * an eol even when 'binary' is off, to support turning 'fixeol' off, | |
2510 * or writing the read again with 'binary' on. The latter is required | |
2511 * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work. | |
7 | 2512 */ |
2707 | 2513 curbuf->b_no_eol_lnum = read_no_eol_lnum; |
7 | 2514 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2515 // 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
|
2516 // different. |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
2517 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
|
2518 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
|
2519 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2520 #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
|
2521 /* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2522 * 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
|
2523 */ |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2524 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
|
2525 { |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2526 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
|
2527 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2528 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
|
2529 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
|
2530 } |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2531 #endif |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2532 |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
2533 if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL)) |
7 | 2534 { |
2535 int m = msg_scroll; | |
2536 int n = msg_scrolled; | |
2537 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2538 // 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
|
2539 // modified if the format/encoding was automatically detected. |
819 | 2540 if (set_options) |
7 | 2541 save_file_ff(curbuf); |
2542 | |
2543 /* | |
2544 * The output from the autocommands should not overwrite anything and | |
2545 * should not be overwritten: Set msg_scroll, restore its value if no | |
2546 * output was done. | |
2547 */ | |
2548 msg_scroll = TRUE; | |
2549 if (filtering) | |
2550 apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname, | |
2551 FALSE, curbuf, eap); | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9682
diff
changeset
|
2552 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
|
2553 { |
7 | 2554 apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname, |
2555 FALSE, curbuf, eap); | |
8937
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2556 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
|
2557 /* |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2558 * 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
|
2559 * 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
|
2560 */ |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2561 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
|
2562 TRUE, curbuf); |
da4f6e238374
commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
2563 } |
7 | 2564 else |
2565 apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname, | |
2566 FALSE, NULL, eap); | |
2567 if (msg_scrolled == n) | |
2568 msg_scroll = m; | |
2707 | 2569 # ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2570 if (aborting()) // autocmds may abort script processing |
7 | 2571 return FAIL; |
2707 | 2572 # endif |
2573 } | |
2574 | |
7 | 2575 if (recoverymode && error) |
2576 return FAIL; | |
2577 return OK; | |
2578 } | |
2579 | |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9828
diff
changeset
|
2580 #if defined(OPEN_CHR_FILES) || defined(PROTO) |
1313 | 2581 /* |
2582 * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+", | |
2583 * which is the name of files used for process substitution output by | |
2584 * some shells on some operating systems, e.g., bash on SunOS. | |
2585 * Do not accept "/dev/fd/[012]", opening these may hang Vim. | |
2586 */ | |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9828
diff
changeset
|
2587 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2588 is_dev_fd_file(char_u *fname) |
1313 | 2589 { |
2590 return (STRNCMP(fname, "/dev/fd/", 8) == 0 | |
2591 && VIM_ISDIGIT(fname[8]) | |
2592 && *skipdigits(fname + 9) == NUL | |
2593 && (fname[9] != NUL | |
2594 || (fname[8] != '0' && fname[8] != '1' && fname[8] != '2'))); | |
2595 } | |
2596 #endif | |
2597 | |
595 | 2598 /* |
2599 * From the current line count and characters read after that, estimate the | |
2600 * line number where we are now. | |
2601 * Used for error messages that include a line number. | |
2602 */ | |
2603 static linenr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2604 readfile_linenr( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2605 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
|
2606 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
|
2607 char_u *endp) // end of more bytes read |
595 | 2608 { |
2609 char_u *s; | |
2610 linenr_T lnum; | |
2611 | |
2612 lnum = curbuf->b_ml.ml_line_count - linecnt + 1; | |
2613 for (s = p; s < endp; ++s) | |
2614 if (*s == '\n') | |
2615 ++lnum; | |
2616 return lnum; | |
2617 } | |
2618 | |
7 | 2619 /* |
612 | 2620 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be |
2621 * equal to the buffer "buf". Used for calling readfile(). | |
7 | 2622 * Returns OK or FAIL. |
2623 */ | |
2624 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2625 prep_exarg(exarg_T *eap, buf_T *buf) |
7 | 2626 { |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2627 eap->cmd = alloc(15 + (unsigned)STRLEN(buf->b_p_fenc)); |
7 | 2628 if (eap->cmd == NULL) |
2629 return FAIL; | |
2630 | |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2631 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
|
2632 eap->force_enc = 8; |
612 | 2633 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
|
2634 eap->force_ff = *buf->b_p_ff; |
612 | 2635 |
2636 eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN; | |
819 | 2637 eap->read_edit = FALSE; |
612 | 2638 eap->forceit = FALSE; |
7 | 2639 return OK; |
2640 } | |
2641 | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2642 /* |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2643 * Set default or forced 'fileformat' and 'binary'. |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2644 */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2645 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2646 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
|
2647 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2648 // set default 'fileformat' |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2649 if (set_options) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2650 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2651 if (eap != NULL && eap->force_ff != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2652 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
|
2653 else if (*p_ffs != NUL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2654 set_fileformat(default_fileformat(), OPT_LOCAL); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2655 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2656 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2657 // set or reset 'binary' |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2658 if (eap != NULL && eap->force_bin != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2659 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2660 int oldval = curbuf->b_p_bin; |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2661 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2662 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
|
2663 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
|
2664 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2665 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2666 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2667 /* |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2668 * Set forced 'fileencoding'. |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2669 */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2670 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2671 set_forced_fenc(exarg_T *eap) |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2672 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2673 if (eap->force_enc != 0) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2674 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2675 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
|
2676 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2677 if (fenc != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2678 set_string_option_direct((char_u *)"fenc", -1, |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2679 fenc, OPT_FREE|OPT_LOCAL, 0); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2680 vim_free(fenc); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2681 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2682 } |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
5104
diff
changeset
|
2683 |
7 | 2684 /* |
2685 * Find next fileencoding to use from 'fileencodings'. | |
2686 * "pp" points to fenc_next. It's advanced to the next item. | |
2687 * When there are no more items, an empty string is returned and *pp is set to | |
2688 * NULL. | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2689 * 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
|
2690 * is set to TRUE. |
7 | 2691 */ |
2692 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
|
2693 next_fenc(char_u **pp, int *alloced) |
7 | 2694 { |
2695 char_u *p; | |
2696 char_u *r; | |
2697 | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2698 *alloced = FALSE; |
7 | 2699 if (**pp == NUL) |
2700 { | |
2701 *pp = NULL; | |
2702 return (char_u *)""; | |
2703 } | |
2704 p = vim_strchr(*pp, ','); | |
2705 if (p == NULL) | |
2706 { | |
2707 r = enc_canonize(*pp); | |
2708 *pp += STRLEN(*pp); | |
2709 } | |
2710 else | |
2711 { | |
2712 r = vim_strnsave(*pp, (int)(p - *pp)); | |
2713 *pp = p + 1; | |
2714 if (r != NULL) | |
2715 { | |
2716 p = enc_canonize(r); | |
2717 vim_free(r); | |
2718 r = p; | |
2719 } | |
2720 } | |
17692
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2721 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
|
2722 *alloced = TRUE; |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2723 else |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2724 { |
1e3ff1eae4c3
patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents:
17584
diff
changeset
|
2725 // out of memory |
7 | 2726 r = (char_u *)""; |
2727 *pp = NULL; | |
2728 } | |
2729 return r; | |
2730 } | |
2731 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2732 #ifdef FEAT_EVAL |
7 | 2733 /* |
2734 * Convert a file with the 'charconvert' expression. | |
2735 * This closes the file which is to be read, converts it and opens the | |
2736 * resulting file for reading. | |
2737 * Returns name of the resulting converted file (the caller should delete it | |
2738 * after reading it). | |
2739 * Returns NULL if the conversion failed ("*fdp" is not set) . | |
2740 */ | |
2741 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2742 readfile_charconvert( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2743 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
|
2744 char_u *fenc, // converted from |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2745 int *fdp) // in/out: file descriptor of file |
7 | 2746 { |
2747 char_u *tmpname; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2748 char *errmsg = NULL; |
7 | 2749 |
6721 | 2750 tmpname = vim_tempname('r', FALSE); |
7 | 2751 if (tmpname == NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2752 errmsg = _("Can't find temp file for conversion"); |
7 | 2753 else |
2754 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2755 close(*fdp); // close the input file, ignore errors |
7 | 2756 *fdp = -1; |
2757 if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc, | |
2758 fname, tmpname) == FAIL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
2759 errmsg = _("Conversion with 'charconvert' failed"); |
7 | 2760 if (errmsg == NULL && (*fdp = mch_open((char *)tmpname, |
2761 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
|
2762 errmsg = _("can't read output of 'charconvert'"); |
7 | 2763 } |
2764 | |
2765 if (errmsg != NULL) | |
2766 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2767 // 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
|
2768 // 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
|
2769 msg(errmsg); |
7 | 2770 if (tmpname != NULL) |
2771 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2772 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
|
2773 VIM_CLEAR(tmpname); |
7 | 2774 } |
2775 } | |
2776 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2777 // If the input file is closed, open it (caller should check for error). |
7 | 2778 if (*fdp < 0) |
2779 *fdp = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); | |
2780 | |
2781 return tmpname; | |
2782 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2783 #endif |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2784 |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
2785 #if defined(FEAT_CRYPT) || defined(PROTO) |
7 | 2786 /* |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2787 * Check for magic number used for encryption. Applies to the current buffer. |
7 | 2788 * If found, the magic number is removed from ptr[*sizep] and *sizep and |
2789 * *filesizep are updated. | |
2790 * Return the (new) encryption key, NULL for no encryption. | |
2791 */ | |
2792 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2793 check_for_cryptkey( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2794 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
|
2795 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
|
2796 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
|
2797 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
|
2798 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
|
2799 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
|
2800 int *did_ask) // flag: whether already asked for key |
7 | 2801 { |
6122 | 2802 int method = crypt_method_nr_from_magic((char *)ptr, *sizep); |
5312 | 2803 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
|
2804 |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2805 if (method >= 0) |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2806 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2807 // 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
|
2808 // Avoids accidentally overwriting the file with garbage. |
5312 | 2809 curbuf->b_p_ro = TRUE; |
2810 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2811 // Set the cryptmethod local to the buffer. |
6122 | 2812 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
|
2813 if (cryptkey == NULL && !*did_ask) |
7 | 2814 { |
2815 if (*curbuf->b_p_key) | |
2816 cryptkey = curbuf->b_p_key; | |
2817 else | |
2818 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2819 // 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
|
2820 // 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
|
2821 // 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
|
2822 // 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
|
2823 smsg(_(need_key_msg), fname); |
2267 | 2824 msg_scroll = TRUE; |
6353 | 2825 crypt_check_method(method); |
6122 | 2826 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
|
2827 *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
|
2828 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2829 // check if empty key entered |
7 | 2830 if (cryptkey != NULL && *cryptkey == NUL) |
2831 { | |
2832 if (cryptkey != curbuf->b_p_key) | |
2833 vim_free(cryptkey); | |
2834 cryptkey = NULL; | |
2835 } | |
2836 } | |
2837 } | |
2838 | |
2839 if (cryptkey != NULL) | |
2840 { | |
6122 | 2841 int header_len; |
2842 | |
2843 curbuf->b_cryptstate = crypt_create_from_header( | |
2844 method, cryptkey, ptr); | |
2845 crypt_set_cm_option(curbuf, method); | |
2846 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2847 // Remove cryptmethod specific header from the text. |
6122 | 2848 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
|
2849 if (*sizep <= header_len) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2850 // 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
|
2851 return NULL; |
6122 | 2852 *filesizep += header_len; |
2853 *sizep -= header_len; | |
2854 mch_memmove(ptr, ptr + header_len, (size_t)*sizep); | |
2855 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2856 // Restore the read-only flag. |
5312 | 2857 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
|
2858 } |
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2147
diff
changeset
|
2859 } |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2860 // 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
|
2861 // 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
|
2862 else if (newfile && *curbuf->b_p_key != NUL && !starting) |
7 | 2863 set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); |
2864 | |
2865 return cryptkey; | |
2866 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2867 #endif // FEAT_CRYPT |
2265
b7cb69ab616d
Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents:
2261
diff
changeset
|
2868 |
22 | 2869 #if defined(VMS) && !defined(MIN) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2870 // Older DECC compiler for VAX doesn't define MIN() |
22 | 2871 # define MIN(a, b) ((a) < (b) ? (a) : (b)) |
2872 #endif | |
2873 | |
7 | 2874 /* |
1303 | 2875 * Return TRUE if a file appears to be read-only from the file permissions. |
2876 */ | |
2877 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2878 check_file_readonly( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2879 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
|
2880 int perm UNUSED) // known permissions on file |
1303 | 2881 { |
2882 #ifndef USE_MCH_ACCESS | |
2883 int fd = 0; | |
2884 #endif | |
2885 | |
2886 return ( | |
2887 #ifdef USE_MCH_ACCESS | |
2888 # ifdef UNIX | |
2889 (perm & 0222) == 0 || | |
2890 # endif | |
2891 mch_access((char *)fname, W_OK) | |
2892 #else | |
2893 (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0 | |
2894 ? TRUE : (close(fd), FALSE) | |
2895 #endif | |
2896 ); | |
2897 } | |
2898 | |
15816
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2899 #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
|
2900 /* |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2901 * 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
|
2902 * 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
|
2903 */ |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2904 int |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2905 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
|
2906 { |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2907 int r; |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2908 |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2909 # ifdef MACOS_X |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2910 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
|
2911 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
|
2912 # endif |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2913 r = fsync(fd); |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2914 return r; |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2915 } |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2916 #endif |
40336d427dd2
patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2917 |
7 | 2918 /* |
633 | 2919 * Set the name of the current buffer. Use when the buffer doesn't have a |
2920 * name and a ":r" or ":w" command with a file name is used. | |
2921 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2922 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2923 set_rw_fname(char_u *fname, char_u *sfname) |
633 | 2924 { |
1905 | 2925 buf_T *buf = curbuf; |
2926 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2927 // It's like the unnamed buffer is deleted.... |
633 | 2928 if (curbuf->b_p_bl) |
2929 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
2930 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
|
2931 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2932 if (aborting()) // autocmds may abort script processing |
633 | 2933 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2934 #endif |
1905 | 2935 if (curbuf != buf) |
2936 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2937 // 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
|
2938 emsg(_(e_auchangedbuf)); |
1905 | 2939 return FAIL; |
2940 } | |
633 | 2941 |
2942 if (setfname(curbuf, fname, sfname, FALSE) == OK) | |
2943 curbuf->b_flags |= BF_NOTEDITED; | |
2944 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2945 // ....and a new named one is created |
633 | 2946 apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); |
2947 if (curbuf->b_p_bl) | |
2948 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
|
2949 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2950 if (aborting()) // autocmds may abort script processing |
633 | 2951 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2952 #endif |
633 | 2953 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
2954 // Do filetype detection now if 'filetype' is empty. |
633 | 2955 if (*curbuf->b_p_ft == NUL) |
2956 { | |
819 | 2957 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
|
2958 (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE, NULL); |
717 | 2959 do_modelines(0); |
633 | 2960 } |
2961 | |
2962 return OK; | |
2963 } | |
2964 | |
2965 /* | |
7 | 2966 * Put file name into IObuff with quotes. |
2967 */ | |
33 | 2968 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2969 msg_add_fname(buf_T *buf, char_u *fname) |
7 | 2970 { |
2971 if (fname == NULL) | |
2972 fname = (char_u *)"-stdin-"; | |
2973 home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE); | |
2974 IObuff[0] = '"'; | |
2975 STRCAT(IObuff, "\" "); | |
2976 } | |
2977 | |
2978 /* | |
2979 * Append message for text mode to IObuff. | |
2980 * Return TRUE if something appended. | |
2981 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
2982 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2983 msg_add_fileformat(int eol_type) |
7 | 2984 { |
2985 #ifndef USE_CRNL | |
2986 if (eol_type == EOL_DOS) | |
2987 { | |
2988 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]")); | |
2989 return TRUE; | |
2990 } | |
2991 #endif | |
2992 if (eol_type == EOL_MAC) | |
2993 { | |
2994 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]")); | |
2995 return TRUE; | |
2996 } | |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15816
diff
changeset
|
2997 #ifdef USE_CRNL |
7 | 2998 if (eol_type == EOL_UNIX) |
2999 { | |
3000 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]")); | |
3001 return TRUE; | |
3002 } | |
3003 #endif | |
3004 return FALSE; | |
3005 } | |
3006 | |
3007 /* | |
3008 * Append line and character count to IObuff. | |
3009 */ | |
33 | 3010 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3011 msg_add_lines( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3012 int insert_space, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3013 long lnum, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3014 off_T nchars) |
7 | 3015 { |
3016 char_u *p; | |
3017 | |
3018 p = IObuff + STRLEN(IObuff); | |
3019 | |
3020 if (insert_space) | |
3021 *p++ = ' '; | |
3022 if (shortmess(SHM_LINES)) | |
9391
4c40631238e4
commit https://github.com/vim/vim/commit/bde9810d6103ffe3a22a9330021cb21db1ed1792
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3023 vim_snprintf((char *)p, IOSIZE - (p - IObuff), |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3024 "%ldL, %lldC", lnum, (long_long_T)nchars); |
7 | 3025 else |
3026 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3027 sprintf((char *)p, NGETTEXT("%ld line, ", "%ld lines, ", lnum), lnum); |
7 | 3028 p += STRLEN(p); |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3029 vim_snprintf((char *)p, IOSIZE - (p - IObuff), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3030 NGETTEXT("%lld character", "%lld characters", nchars), |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3031 (long_long_T)nchars); |
7 | 3032 } |
3033 } | |
3034 | |
3035 /* | |
3036 * Append message for missing line separator to IObuff. | |
3037 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3038 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3039 msg_add_eol(void) |
7 | 3040 { |
3041 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]")); | |
3042 } | |
3043 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3044 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3045 time_differs(long t1, long t2) |
7 | 3046 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3047 #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
|
3048 // 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
|
3049 // 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
|
3050 // time may change unexpectedly by one second!!! |
7 | 3051 return (t1 - t2 > 1 || t2 - t1 > 1); |
3052 #else | |
3053 return (t1 != t2); | |
3054 #endif | |
3055 } | |
3056 | |
3057 /* | |
1948 | 3058 * Return TRUE if file encoding "fenc" requires conversion from or to |
3059 * 'encoding'. | |
7 | 3060 */ |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3061 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3062 need_conversion(char_u *fenc) |
7 | 3063 { |
1948 | 3064 int same_encoding; |
3065 int enc_flags; | |
3066 int fenc_flags; | |
3067 | |
3068 if (*fenc == NUL || STRCMP(p_enc, fenc) == 0) | |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3069 { |
1948 | 3070 same_encoding = TRUE; |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3071 fenc_flags = 0; |
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3072 } |
1948 | 3073 else |
3074 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3075 // 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
|
3076 // "ucs-4be", etc. |
1948 | 3077 enc_flags = get_fio_flags(p_enc); |
3078 fenc_flags = get_fio_flags(fenc); | |
3079 same_encoding = (enc_flags != 0 && fenc_flags == enc_flags); | |
3080 } | |
3081 if (same_encoding) | |
3082 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3083 // 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
|
3084 // conversion when 'encoding' is Unicode but not UTF-8. |
1948 | 3085 return enc_unicode != 0; |
3086 } | |
3087 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3088 // 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
|
3089 // Unicode encoding and the file is UTF-8. |
1948 | 3090 return !(enc_utf8 && fenc_flags == FIO_UTF8); |
7 | 3091 } |
3092 | |
3093 /* | |
3094 * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the | |
3095 * internal conversion. | |
3096 * if "ptr" is an empty string, use 'encoding'. | |
3097 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3098 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3099 get_fio_flags(char_u *ptr) |
7 | 3100 { |
3101 int prop; | |
3102 | |
3103 if (*ptr == NUL) | |
3104 ptr = p_enc; | |
3105 | |
3106 prop = enc_canon_props(ptr); | |
3107 if (prop & ENC_UNICODE) | |
3108 { | |
3109 if (prop & ENC_2BYTE) | |
3110 { | |
3111 if (prop & ENC_ENDIAN_L) | |
3112 return FIO_UCS2 | FIO_ENDIAN_L; | |
3113 return FIO_UCS2; | |
3114 } | |
3115 if (prop & ENC_4BYTE) | |
3116 { | |
3117 if (prop & ENC_ENDIAN_L) | |
3118 return FIO_UCS4 | FIO_ENDIAN_L; | |
3119 return FIO_UCS4; | |
3120 } | |
3121 if (prop & ENC_2WORD) | |
3122 { | |
3123 if (prop & ENC_ENDIAN_L) | |
3124 return FIO_UTF16 | FIO_ENDIAN_L; | |
3125 return FIO_UTF16; | |
3126 } | |
3127 return FIO_UTF8; | |
3128 } | |
3129 if (prop & ENC_LATIN1) | |
3130 return FIO_LATIN1; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3131 // must be ENC_DBCS, requires iconv() |
7 | 3132 return 0; |
3133 } | |
3134 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3135 #if defined(MSWIN) || defined(PROTO) |
7 | 3136 /* |
3137 * Check "ptr" for a MS-Windows codepage name and return the FIO_ flags needed | |
3138 * for the conversion MS-Windows can do for us. Also accept "utf-8". | |
3139 * Used for conversion between 'encoding' and 'fileencoding'. | |
3140 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3141 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3142 get_win_fio_flags(char_u *ptr) |
7 | 3143 { |
3144 int cp; | |
3145 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3146 // Cannot do this when 'encoding' is not utf-8 and not a codepage. |
7 | 3147 if (!enc_utf8 && enc_codepage <= 0) |
3148 return 0; | |
3149 | |
3150 cp = encname2codepage(ptr); | |
3151 if (cp == 0) | |
3152 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3153 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 |
7 | 3154 if (STRCMP(ptr, "utf-8") == 0) |
3155 cp = CP_UTF8; | |
3156 else | |
3157 # endif | |
3158 return 0; | |
3159 } | |
3160 return FIO_PUT_CP(cp) | FIO_CODEPAGE; | |
3161 } | |
3162 #endif | |
3163 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3164 #if defined(MACOS_CONVERT) || defined(PROTO) |
7 | 3165 /* |
3166 * Check "ptr" for a Carbon supported encoding and return the FIO_ flags | |
3167 * needed for the internal conversion to/from utf-8 or latin1. | |
3168 */ | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3169 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3170 get_mac_fio_flags(char_u *ptr) |
7 | 3171 { |
3172 if ((enc_utf8 || STRCMP(p_enc, "latin1") == 0) | |
3173 && (enc_canon_props(ptr) & ENC_MACROMAN)) | |
3174 return FIO_MACROMAN; | |
3175 return 0; | |
3176 } | |
3177 #endif | |
3178 | |
3179 /* | |
3180 * Check for a Unicode BOM (Byte Order Mark) at the start of p[size]. | |
3181 * "size" must be at least 2. | |
3182 * Return the name of the encoding and set "*lenp" to the length. | |
3183 * Returns NULL when no BOM found. | |
3184 */ | |
3185 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3186 check_for_bom( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3187 char_u *p, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3188 long size, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3189 int *lenp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3190 int flags) |
7 | 3191 { |
3192 char *name = NULL; | |
3193 int len = 2; | |
3194 | |
3195 if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf | |
1688 | 3196 && (flags == FIO_ALL || flags == FIO_UTF8 || flags == 0)) |
7 | 3197 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3198 name = "utf-8"; // EF BB BF |
7 | 3199 len = 3; |
3200 } | |
3201 else if (p[0] == 0xff && p[1] == 0xfe) | |
3202 { | |
3203 if (size >= 4 && p[2] == 0 && p[3] == 0 | |
3204 && (flags == FIO_ALL || flags == (FIO_UCS4 | FIO_ENDIAN_L))) | |
3205 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3206 name = "ucs-4le"; // FF FE 00 00 |
7 | 3207 len = 4; |
3208 } | |
1735 | 3209 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
|
3210 name = "ucs-2le"; // FF FE |
1735 | 3211 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
|
3212 // 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
|
3213 name = "utf-16le"; // FF FE |
7 | 3214 } |
3215 else if (p[0] == 0xfe && p[1] == 0xff | |
3216 && (flags == FIO_ALL || flags == FIO_UCS2 || flags == FIO_UTF16)) | |
3217 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3218 // Default to utf-16, it works also for ucs-2 text. |
1547 | 3219 if (flags == FIO_UCS2) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3220 name = "ucs-2"; // FE FF |
1547 | 3221 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3222 name = "utf-16"; // FE FF |
7 | 3223 } |
3224 else if (size >= 4 && p[0] == 0 && p[1] == 0 && p[2] == 0xfe | |
3225 && p[3] == 0xff && (flags == FIO_ALL || flags == FIO_UCS4)) | |
3226 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3227 name = "ucs-4"; // 00 00 FE FF |
7 | 3228 len = 4; |
3229 } | |
3230 | |
3231 *lenp = len; | |
3232 return (char_u *)name; | |
3233 } | |
3234 | |
3235 /* | |
3236 * Try to find a shortname by comparing the fullname with the current | |
3237 * directory. | |
1411 | 3238 * Returns "full_path" or pointer into "full_path" if shortened. |
3239 */ | |
3240 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3241 shorten_fname1(char_u *full_path) |
1411 | 3242 { |
2770 | 3243 char_u *dirname; |
1411 | 3244 char_u *p = full_path; |
3245 | |
2770 | 3246 dirname = alloc(MAXPATHL); |
3247 if (dirname == NULL) | |
3248 return full_path; | |
1411 | 3249 if (mch_dirname(dirname, MAXPATHL) == OK) |
3250 { | |
3251 p = shorten_fname(full_path, dirname); | |
3252 if (p == NULL || *p == NUL) | |
3253 p = full_path; | |
3254 } | |
2770 | 3255 vim_free(dirname); |
1411 | 3256 return p; |
3257 } | |
3258 | |
3259 /* | |
3260 * Try to find a shortname by comparing the fullname with the current | |
3261 * directory. | |
7 | 3262 * Returns NULL if not shorter name possible, pointer into "full_path" |
3263 * otherwise. | |
3264 */ | |
3265 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3266 shorten_fname(char_u *full_path, char_u *dir_name) |
7 | 3267 { |
3268 int len; | |
3269 char_u *p; | |
3270 | |
3271 if (full_path == NULL) | |
3272 return NULL; | |
3273 len = (int)STRLEN(dir_name); | |
3274 if (fnamencmp(dir_name, full_path, len) == 0) | |
3275 { | |
3276 p = full_path + len; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3277 #if defined(MSWIN) |
7 | 3278 /* |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3279 * 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
|
3280 * 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
|
3281 * this case p may already be correct. <negri> |
7 | 3282 */ |
3283 if (!((len > 2) && (*(p - 2) == ':'))) | |
3284 #endif | |
3285 { | |
3286 if (vim_ispathsep(*p)) | |
3287 ++p; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3288 #ifndef VMS // the path separator is always part of the path |
7 | 3289 else |
3290 p = NULL; | |
3291 #endif | |
3292 } | |
3293 } | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3294 #if defined(MSWIN) |
7 | 3295 /* |
3296 * When using a file in the current drive, remove the drive name: | |
3297 * "A:\dir\file" -> "\dir\file". This helps when moving a session file on | |
3298 * a floppy from "A:\dir" to "B:\dir". | |
3299 */ | |
3300 else if (len > 3 | |
3301 && TOUPPER_LOC(full_path[0]) == TOUPPER_LOC(dir_name[0]) | |
3302 && full_path[1] == ':' | |
3303 && vim_ispathsep(full_path[2])) | |
3304 p = full_path + 2; | |
3305 #endif | |
3306 else | |
3307 p = NULL; | |
3308 return p; | |
3309 } | |
3310 | |
3311 /* | |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3312 * Shorten filename of a buffer. |
7 | 3313 * When "force" is TRUE: Use full path from now on for files currently being |
3314 * edited, both for file name and swap file name. Try to shorten the file | |
3315 * names a bit, if safe to do so. | |
3316 * When "force" is FALSE: Only try to shorten absolute file names. | |
3317 * For buffers that have buftype "nofile" or "scratch": never change the file | |
3318 * name. | |
3319 */ | |
3320 void | |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3321 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
|
3322 { |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3323 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
|
3324 |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3325 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
|
3326 #ifdef FEAT_QUICKFIX |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
3327 && !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
|
3328 #endif |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3329 && !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
|
3330 && (force |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3331 || 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
|
3332 || 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
|
3333 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3334 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
|
3335 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
|
3336 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
|
3337 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
|
3338 { |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3339 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
|
3340 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
|
3341 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3342 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
|
3343 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
|
3344 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3345 } |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3346 |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3347 /* |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3348 * 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
|
3349 */ |
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3350 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3351 shorten_fnames(int force) |
7 | 3352 { |
3353 char_u dirname[MAXPATHL]; | |
3354 buf_T *buf; | |
3355 | |
3356 mch_dirname(dirname, MAXPATHL); | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
3357 FOR_ALL_BUFFERS(buf) |
7 | 3358 { |
13819
31bb8e1f7625
patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents:
13810
diff
changeset
|
3359 shorten_buf_fname(buf, dirname, force); |
9 | 3360 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3361 // 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
|
3362 // also have a swap file. |
9 | 3363 mf_fullname(buf->b_ml.ml_mfp); |
7 | 3364 } |
3365 status_redraw_all(); | |
672 | 3366 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
|
3367 #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
|
3368 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
|
3369 #endif |
7 | 3370 } |
3371 | |
3372 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ | |
3373 || defined(FEAT_GUI_MSWIN) \ | |
3374 || defined(FEAT_GUI_MAC) \ | |
3375 || defined(PROTO) | |
3376 /* | |
3377 * Shorten all filenames in "fnames[count]" by current directory. | |
3378 */ | |
3379 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3380 shorten_filenames(char_u **fnames, int count) |
7 | 3381 { |
3382 int i; | |
3383 char_u dirname[MAXPATHL]; | |
3384 char_u *p; | |
3385 | |
3386 if (fnames == NULL || count < 1) | |
3387 return; | |
3388 mch_dirname(dirname, sizeof(dirname)); | |
3389 for (i = 0; i < count; ++i) | |
3390 { | |
3391 if ((p = shorten_fname(fnames[i], dirname)) != NULL) | |
3392 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3393 // 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
|
3394 // "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
|
3395 // "p" first then free fnames[i]. |
7 | 3396 p = vim_strsave(p); |
3397 vim_free(fnames[i]); | |
3398 fnames[i] = p; | |
3399 } | |
3400 } | |
3401 } | |
3402 #endif | |
3403 | |
3404 /* | |
14475
dddba3937532
patch 8.1.0251: using full path is not supported for 'backupdir'
Christian Brabandt <cb@256bit.org>
parents:
14433
diff
changeset
|
3405 * Add extension to file name - change path/fo.o.h to path/fo.o.h.ext or |
7 | 3406 * fo_o_h.ext for MSDOS or when shortname option set. |
3407 * | |
3408 * Assumed that fname is a valid name found in the filesystem we assure that | |
3409 * the return value is a different name and ends in 'ext'. | |
3410 * "ext" MUST be at most 4 characters long if it starts with a dot, 3 | |
3411 * characters otherwise. | |
3412 * Space for the returned name is allocated, must be freed later. | |
3413 * Returns NULL when out of memory. | |
3414 */ | |
3415 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3416 modname( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3417 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3418 char_u *ext, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3419 int prepend_dot) // may prepend a '.' to file name |
7 | 3420 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
8080
diff
changeset
|
3421 return buf_modname((curbuf->b_p_sn || curbuf->b_shortname), |
7 | 3422 fname, ext, prepend_dot); |
3423 } | |
3424 | |
3425 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3426 buf_modname( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3427 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
|
3428 char_u *fname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3429 char_u *ext, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3430 int prepend_dot) // may prepend a '.' to file name |
7 | 3431 { |
3432 char_u *retval; | |
3433 char_u *s; | |
3434 char_u *e; | |
3435 char_u *ptr; | |
3436 int fnamelen, extlen; | |
3437 | |
3438 extlen = (int)STRLEN(ext); | |
3439 | |
3440 /* | |
3441 * If there is no file name we must get the name of the current directory | |
3442 * (we need the full path in case :cd is used). | |
3443 */ | |
3444 if (fname == NULL || *fname == NUL) | |
3445 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16754
diff
changeset
|
3446 retval = alloc(MAXPATHL + extlen + 3); |
7 | 3447 if (retval == NULL) |
3448 return NULL; | |
3449 if (mch_dirname(retval, MAXPATHL) == FAIL || | |
3450 (fnamelen = (int)STRLEN(retval)) == 0) | |
3451 { | |
3452 vim_free(retval); | |
3453 return NULL; | |
3454 } | |
39 | 3455 if (!after_pathsep(retval, retval + fnamelen)) |
7 | 3456 { |
3457 retval[fnamelen++] = PATHSEP; | |
3458 retval[fnamelen] = NUL; | |
3459 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3460 prepend_dot = FALSE; // nothing to prepend a dot to |
7 | 3461 } |
3462 else | |
3463 { | |
3464 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
|
3465 retval = alloc(fnamelen + extlen + 3); |
7 | 3466 if (retval == NULL) |
3467 return NULL; | |
3468 STRCPY(retval, fname); | |
3469 #ifdef VMS | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3470 vms_remove_version(retval); // we do not need versions here |
7 | 3471 #endif |
3472 } | |
3473 | |
3474 /* | |
3475 * search backwards until we hit a '/', '\' or ':' replacing all '.' | |
3476 * by '_' for MSDOS or when shortname option set and ext starts with a dot. | |
3477 * Then truncate what is after the '/', '\' or ':' to 8 characters for | |
3478 * MSDOS and 26 characters for AMIGA, a lot more for UNIX. | |
3479 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3480 for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr)) |
7 | 3481 { |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15776
diff
changeset
|
3482 if (*ext == '.' && shortname) |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3483 if (*ptr == '.') // replace '.' by '_' |
7 | 3484 *ptr = '_'; |
3485 if (vim_ispathsep(*ptr)) | |
391 | 3486 { |
3487 ++ptr; | |
7 | 3488 break; |
391 | 3489 } |
3490 } | |
7 | 3491 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3492 // the file name has at most BASENAMELEN characters. |
7 | 3493 if (STRLEN(ptr) > (unsigned)BASENAMELEN) |
3494 ptr[BASENAMELEN] = '\0'; | |
3495 | |
3496 s = ptr + STRLEN(ptr); | |
3497 | |
3498 /* | |
3499 * For 8.3 file names we may have to reduce the length. | |
3500 */ | |
3501 if (shortname) | |
3502 { | |
3503 /* | |
3504 * If there is no file name, or the file name ends in '/', and the | |
3505 * extension starts with '.', put a '_' before the dot, because just | |
3506 * ".ext" is invalid. | |
3507 */ | |
3508 if (fname == NULL || *fname == NUL | |
3509 || vim_ispathsep(fname[STRLEN(fname) - 1])) | |
3510 { | |
3511 if (*ext == '.') | |
3512 *s++ = '_'; | |
3513 } | |
3514 /* | |
3515 * If the extension starts with '.', truncate the base name at 8 | |
3516 * characters | |
3517 */ | |
3518 else if (*ext == '.') | |
3519 { | |
1877 | 3520 if ((size_t)(s - ptr) > (size_t)8) |
7 | 3521 { |
3522 s = ptr + 8; | |
3523 *s = '\0'; | |
3524 } | |
3525 } | |
3526 /* | |
3527 * If the extension doesn't start with '.', and the file name | |
3528 * doesn't have an extension yet, append a '.' | |
3529 */ | |
3530 else if ((e = vim_strchr(ptr, '.')) == NULL) | |
3531 *s++ = '.'; | |
3532 /* | |
3533 * If the extension doesn't start with '.', and there already is an | |
1201 | 3534 * extension, it may need to be truncated |
7 | 3535 */ |
3536 else if ((int)STRLEN(e) + extlen > 4) | |
3537 s = e + 4 - extlen; | |
3538 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3539 #ifdef MSWIN |
7 | 3540 /* |
3541 * If there is no file name, and the extension starts with '.', put a | |
3542 * '_' before the dot, because just ".ext" may be invalid if it's on a | |
3543 * FAT partition, and on HPFS it doesn't matter. | |
3544 */ | |
3545 else if ((fname == NULL || *fname == NUL) && *ext == '.') | |
3546 *s++ = '_'; | |
3547 #endif | |
3548 | |
3549 /* | |
1651 | 3550 * Append the extension. |
7 | 3551 * ext can start with '.' and cannot exceed 3 more characters. |
3552 */ | |
3553 STRCPY(s, ext); | |
3554 | |
3555 /* | |
3556 * Prepend the dot. | |
3557 */ | |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15776
diff
changeset
|
3558 if (prepend_dot && !shortname && *(e = gettail(retval)) != '.') |
7 | 3559 { |
1620 | 3560 STRMOVE(e + 1, e); |
7 | 3561 *e = '.'; |
3562 } | |
3563 | |
3564 /* | |
3565 * Check that, after appending the extension, the file name is really | |
3566 * different. | |
3567 */ | |
3568 if (fname != NULL && STRCMP(fname, retval) == 0) | |
3569 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3570 // we search for a character that can be replaced by '_' |
7 | 3571 while (--s >= ptr) |
3572 { | |
3573 if (*s != '_') | |
3574 { | |
3575 *s = '_'; | |
3576 break; | |
3577 } | |
3578 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3579 if (s < ptr) // fname was "________.<ext>", how tricky! |
7 | 3580 *ptr = 'v'; |
3581 } | |
3582 return retval; | |
3583 } | |
3584 | |
3585 /* | |
3586 * Like fgets(), but if the file line is too long, it is truncated and the | |
3587 * 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
|
3588 * If the line is truncated then buf[size - 2] will not be NUL. |
7 | 3589 */ |
3590 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3591 vim_fgets(char_u *buf, int size, FILE *fp) |
7 | 3592 { |
3593 char *eof; | |
3594 #define FGETS_SIZE 200 | |
3595 char tbuf[FGETS_SIZE]; | |
3596 | |
3597 buf[size - 2] = NUL; | |
3598 eof = fgets((char *)buf, size, fp); | |
3599 if (buf[size - 2] != NUL && buf[size - 2] != '\n') | |
3600 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3601 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
|
3602 |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3603 // Now throw away the rest of the line: |
7 | 3604 do |
3605 { | |
3606 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
|
3607 vim_ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp); |
7 | 3608 } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); |
3609 } | |
3610 return (eof == NULL); | |
3611 } | |
3612 | |
3613 /* | |
3614 * rename() only works if both files are on the same file system, this | |
3615 * function will (attempts to?) copy the file across if rename fails -- webb | |
3616 * Return -1 for failure, 0 for success. | |
3617 */ | |
3618 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3619 vim_rename(char_u *from, char_u *to) |
7 | 3620 { |
3621 int fd_in; | |
3622 int fd_out; | |
3623 int n; | |
3624 char *errmsg = NULL; | |
3625 char *buffer; | |
3626 #ifdef AMIGA | |
3627 BPTR flock; | |
3628 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3629 stat_T st; |
194 | 3630 long perm; |
199 | 3631 #ifdef HAVE_ACL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3632 vim_acl_T acl; // ACL from original file |
199 | 3633 #endif |
1779 | 3634 int use_tmp_file = FALSE; |
7 | 3635 |
3636 /* | |
1779 | 3637 * When the names are identical, there is nothing to do. When they refer |
3638 * to the same file (ignoring case and slash/backslash differences) but | |
3639 * the file name differs we need to go through a temp file. | |
7 | 3640 */ |
3641 if (fnamecmp(from, to) == 0) | |
1779 | 3642 { |
4242 | 3643 if (p_fic && STRCMP(gettail(from), gettail(to)) != 0) |
1779 | 3644 use_tmp_file = TRUE; |
3645 else | |
3646 return 0; | |
3647 } | |
7 | 3648 |
3649 /* | |
3650 * Fail if the "from" file doesn't exist. Avoids that "to" is deleted. | |
3651 */ | |
3652 if (mch_stat((char *)from, &st) < 0) | |
3653 return -1; | |
3654 | |
1778 | 3655 #ifdef UNIX |
3656 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3657 stat_T st_to; |
1778 | 3658 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3659 // 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
|
3660 // 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
|
3661 // filesystem. In that case go through a temp file name. |
1778 | 3662 if (mch_stat((char *)to, &st_to) >= 0 |
3663 && st.st_dev == st_to.st_dev | |
3664 && st.st_ino == st_to.st_ino) | |
1779 | 3665 use_tmp_file = TRUE; |
3666 } | |
3667 #endif | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
3668 #ifdef MSWIN |
2793 | 3669 { |
3670 BY_HANDLE_FILE_INFORMATION info1, info2; | |
3671 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3672 // 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
|
3673 // 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
|
3674 // "./foo") a no-op (in a complicated way). |
2793 | 3675 if (win32_fileinfo(from, &info1) == FILEINFO_OK |
3676 && win32_fileinfo(to, &info2) == FILEINFO_OK | |
3677 && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber | |
3678 && info1.nFileIndexHigh == info2.nFileIndexHigh | |
3679 && info1.nFileIndexLow == info2.nFileIndexLow) | |
3680 use_tmp_file = TRUE; | |
3681 } | |
3682 #endif | |
1779 | 3683 |
3684 if (use_tmp_file) | |
3685 { | |
3686 char tempname[MAXPATHL + 1]; | |
3687 | |
3688 /* | |
3689 * Find a name that doesn't exist and is in the same directory. | |
3690 * Rename "from" to "tempname" and then rename "tempname" to "to". | |
3691 */ | |
3692 if (STRLEN(from) >= MAXPATHL - 5) | |
3693 return -1; | |
3694 STRCPY(tempname, from); | |
3695 for (n = 123; n < 99999; ++n) | |
3696 { | |
3697 sprintf((char *)gettail((char_u *)tempname), "%d", n); | |
3698 if (mch_stat(tempname, &st) < 0) | |
3699 { | |
3700 if (mch_rename((char *)from, tempname) == 0) | |
1778 | 3701 { |
1779 | 3702 if (mch_rename(tempname, (char *)to) == 0) |
3703 return 0; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3704 // 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
|
3705 // file back and return failure. |
1779 | 3706 mch_rename(tempname, (char *)from); |
1778 | 3707 return -1; |
3708 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3709 // 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
|
3710 // for any temp name, give up. |
1779 | 3711 return -1; |
3712 } | |
3713 } | |
3714 return -1; | |
1778 | 3715 } |
3716 | |
7 | 3717 /* |
3718 * Delete the "to" file, this is required on some systems to make the | |
3719 * mch_rename() work, on other systems it makes sure that we don't have | |
3720 * two files when the mch_rename() fails. | |
3721 */ | |
3722 | |
3723 #ifdef AMIGA | |
3724 /* | |
3725 * With MSDOS-compatible filesystems (crossdos, messydos) it is possible | |
3726 * that the name of the "to" file is the same as the "from" file, even | |
1201 | 3727 * though the names are different. To avoid the chance of accidentally |
7 | 3728 * deleting the "from" file (horror!) we lock it during the remove. |
3729 * | |
3730 * When used for making a backup before writing the file: This should not | |
3731 * happen with ":w", because startscript() should detect this problem and | |
3732 * set buf->b_shortname, causing modname() to return a correct ".bak" file | |
3733 * name. This problem does exist with ":w filename", but then the | |
3734 * original file will be somewhere else so the backup isn't really | |
3735 * important. If autoscripting is off the rename may fail. | |
3736 */ | |
3737 flock = Lock((UBYTE *)from, (long)ACCESS_READ); | |
3738 #endif | |
3739 mch_remove(to); | |
3740 #ifdef AMIGA | |
3741 if (flock) | |
3742 UnLock(flock); | |
3743 #endif | |
3744 | |
3745 /* | |
3746 * First try a normal rename, return if it works. | |
3747 */ | |
3748 if (mch_rename((char *)from, (char *)to) == 0) | |
3749 return 0; | |
3750 | |
3751 /* | |
3752 * Rename() failed, try copying the file. | |
3753 */ | |
194 | 3754 perm = mch_getperm(from); |
199 | 3755 #ifdef HAVE_ACL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3756 // For systems that support ACL: get the ACL from the original file. |
199 | 3757 acl = mch_get_acl(from); |
3758 #endif | |
7 | 3759 fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); |
3760 if (fd_in == -1) | |
1651 | 3761 { |
3762 #ifdef HAVE_ACL | |
3763 mch_free_acl(acl); | |
3764 #endif | |
7 | 3765 return -1; |
1651 | 3766 } |
194 | 3767 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3768 // Create the new file with same permissions as the original. |
557 | 3769 fd_out = mch_open((char *)to, |
3770 O_CREAT|O_EXCL|O_WRONLY|O_EXTRA|O_NOFOLLOW, (int)perm); | |
7 | 3771 if (fd_out == -1) |
3772 { | |
3773 close(fd_in); | |
1651 | 3774 #ifdef HAVE_ACL |
3775 mch_free_acl(acl); | |
3776 #endif | |
7 | 3777 return -1; |
3778 } | |
3779 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3780 buffer = alloc(WRITEBUFSIZE); |
7 | 3781 if (buffer == NULL) |
3782 { | |
1651 | 3783 close(fd_out); |
7 | 3784 close(fd_in); |
1651 | 3785 #ifdef HAVE_ACL |
3786 mch_free_acl(acl); | |
3787 #endif | |
7 | 3788 return -1; |
3789 } | |
3790 | |
18199
e2be5a6485f5
patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3791 while ((n = read_eintr(fd_in, buffer, WRITEBUFSIZE)) > 0) |
2664 | 3792 if (write_eintr(fd_out, buffer, n) != n) |
7 | 3793 { |
3794 errmsg = _("E208: Error writing to \"%s\""); | |
3795 break; | |
3796 } | |
3797 | |
3798 vim_free(buffer); | |
3799 close(fd_in); | |
3800 if (close(fd_out) < 0) | |
3801 errmsg = _("E209: Error closing \"%s\""); | |
3802 if (n < 0) | |
3803 { | |
3804 errmsg = _("E210: Error reading \"%s\""); | |
3805 to = from; | |
3806 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3807 #ifndef UNIX // for Unix mch_open() already set the permission |
194 | 3808 mch_setperm(to, perm); |
570 | 3809 #endif |
199 | 3810 #ifdef HAVE_ACL |
3811 mch_set_acl(to, acl); | |
1651 | 3812 mch_free_acl(acl); |
199 | 3813 #endif |
5788 | 3814 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) |
5483 | 3815 mch_copy_sec(from, to); |
5479 | 3816 #endif |
7 | 3817 if (errmsg != NULL) |
3818 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3819 semsg(errmsg, to); |
7 | 3820 return -1; |
3821 } | |
3822 mch_remove(from); | |
3823 return 0; | |
3824 } | |
3825 | |
3826 static int already_warned = FALSE; | |
3827 | |
3828 /* | |
3829 * Check if any not hidden buffer has been changed. | |
3830 * Postpone the check if there are characters in the stuff buffer, a global | |
3831 * command is being executed, a mapping is being executed or an autocommand is | |
3832 * busy. | |
3833 * Returns TRUE if some message was written (screen should be redrawn and | |
3834 * cursor positioned). | |
3835 */ | |
3836 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3837 check_timestamps( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3838 int focus) // called for GUI focus event |
7 | 3839 { |
3840 buf_T *buf; | |
3841 int didit = 0; | |
3842 int n; | |
3843 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3844 // 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
|
3845 // cause us to lose and gain focus. |
7 | 3846 if (no_check_timestamps > 0) |
3847 return FALSE; | |
3848 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3849 // 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
|
3850 // 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
|
3851 // Do check again after typing something. |
7 | 3852 if (focus && did_check_timestamps) |
3853 { | |
3854 need_check_timestamps = TRUE; | |
3855 return FALSE; | |
3856 } | |
3857 | |
3858 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
|
3859 || 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
|
3860 need_check_timestamps = TRUE; // check later |
7 | 3861 else |
3862 { | |
3863 ++no_wait_return; | |
3864 did_check_timestamps = TRUE; | |
3865 already_warned = FALSE; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9599
diff
changeset
|
3866 FOR_ALL_BUFFERS(buf) |
7 | 3867 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3868 // Only check buffers in a window. |
7 | 3869 if (buf->b_nwindows > 0) |
3870 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3871 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3872 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3873 set_bufref(&bufref, buf); |
7 | 3874 n = buf_check_timestamp(buf, focus); |
3875 if (didit < n) | |
3876 didit = n; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3877 if (n > 0 && !bufref_valid(&bufref)) |
7 | 3878 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3879 // 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
|
3880 // first one again. |
7 | 3881 buf = firstbuf; |
3882 continue; | |
3883 } | |
3884 } | |
3885 } | |
3886 --no_wait_return; | |
3887 need_check_timestamps = FALSE; | |
3888 if (need_wait_return && didit == 2) | |
3889 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3890 // 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
|
3891 msg_puts("\n"); |
7 | 3892 out_flush(); |
3893 } | |
3894 } | |
3895 return didit; | |
3896 } | |
3897 | |
3898 /* | |
3899 * Move all the lines from buffer "frombuf" to buffer "tobuf". | |
3900 * Return OK or FAIL. When FAIL "tobuf" is incomplete and/or "frombuf" is not | |
3901 * empty. | |
3902 */ | |
3903 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3904 move_lines(buf_T *frombuf, buf_T *tobuf) |
7 | 3905 { |
3906 buf_T *tbuf = curbuf; | |
3907 int retval = OK; | |
3908 linenr_T lnum; | |
3909 char_u *p; | |
3910 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3911 // Copy the lines in "frombuf" to "tobuf". |
7 | 3912 curbuf = tobuf; |
3913 for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) | |
3914 { | |
3915 p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); | |
3916 if (p == NULL || ml_append(lnum - 1, p, 0, FALSE) == FAIL) | |
3917 { | |
3918 vim_free(p); | |
3919 retval = FAIL; | |
3920 break; | |
3921 } | |
3922 vim_free(p); | |
3923 } | |
3924 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3925 // Delete all the lines in "frombuf". |
7 | 3926 if (retval != FAIL) |
3927 { | |
3928 curbuf = frombuf; | |
1055 | 3929 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum) |
3930 if (ml_delete(lnum, FALSE) == FAIL) | |
7 | 3931 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3932 // 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
|
3933 // might fail again... |
7 | 3934 retval = FAIL; |
3935 break; | |
3936 } | |
3937 } | |
3938 | |
3939 curbuf = tbuf; | |
3940 return retval; | |
3941 } | |
3942 | |
3943 /* | |
3944 * Check if buffer "buf" has been changed. | |
3945 * Also check if the file for a new buffer unexpectedly appeared. | |
3946 * return 1 if a changed buffer was found. | |
3947 * return 2 if a message has been displayed. | |
3948 * return 0 otherwise. | |
3949 */ | |
3950 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3951 buf_check_timestamp( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3952 buf_T *buf, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3953 int focus UNUSED) // called for GUI focus event |
7 | 3954 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3955 stat_T st; |
7 | 3956 int stat_res; |
3957 int retval = 0; | |
3958 char_u *path; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
3959 char *tbuf; |
7 | 3960 char *mesg = NULL; |
188 | 3961 char *mesg2 = ""; |
7 | 3962 int helpmesg = FALSE; |
3963 int reload = FALSE; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3964 char *reason; |
7 | 3965 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) |
3966 int can_reload = FALSE; | |
3967 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
3968 off_T orig_size = buf->b_orig_size; |
7 | 3969 int orig_mode = buf->b_orig_mode; |
3970 #ifdef FEAT_GUI | |
3971 int save_mouse_correct = need_mouse_correct; | |
3972 #endif | |
3973 static int busy = FALSE; | |
179 | 3974 int n; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3975 #ifdef FEAT_EVAL |
179 | 3976 char_u *s; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3977 #endif |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3978 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3979 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
3980 set_bufref(&bufref, buf); |
7 | 3981 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
3982 // 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
|
3983 // 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
|
3984 // this buffer. |
7 | 3985 if (buf->b_ffname == NULL |
3986 || 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
|
3987 || !bt_normal(buf) |
7 | 3988 || buf->b_saving |
3989 || busy | |
33 | 3990 #ifdef FEAT_NETBEANS_INTG |
3991 || isNetbeansBuffer(buf) | |
3992 #endif | |
12064
407a475c67fd
patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3993 #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
|
3994 || 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
|
3995 #endif |
7 | 3996 ) |
3997 return 0; | |
3998 | |
3999 if ( !(buf->b_flags & BF_NOTEDITED) | |
4000 && buf->b_mtime != 0 | |
4001 && ((stat_res = mch_stat((char *)buf->b_ffname, &st)) < 0 | |
4002 || time_differs((long)st.st_mtime, buf->b_mtime) | |
5863 | 4003 || st.st_size != buf->b_orig_size |
7 | 4004 #ifdef HAVE_ST_MODE |
4005 || (int)st.st_mode != buf->b_orig_mode | |
4006 #else | |
4007 || mch_getperm(buf->b_ffname) != buf->b_orig_mode | |
4008 #endif | |
4009 )) | |
4010 { | |
17565
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4011 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
|
4012 |
7 | 4013 retval = 1; |
4014 | |
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
|
4015 // 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
|
4016 // FileChangedShell autocmd) |
7 | 4017 if (stat_res < 0) |
4018 { | |
16754
8b92f3fea477
patch 8.1.1379: filechanged test hangs
Bram Moolenaar <Bram@vim.org>
parents:
16752
diff
changeset
|
4019 // 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
|
4020 buf->b_mtime = -1; |
7 | 4021 buf->b_orig_size = 0; |
4022 buf->b_orig_mode = 0; | |
4023 } | |
4024 else | |
4025 buf_store_time(buf, &st, buf->b_ffname); | |
4026 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4027 // 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
|
4028 // explorer. |
7 | 4029 if (mch_isdir(buf->b_fname)) |
4030 ; | |
4031 | |
4032 /* | |
4033 * If 'autoread' is set, the buffer has no changes and the file still | |
4034 * exists, reload the buffer. Use the buffer-local option value if it | |
4035 * was set, the global option value otherwise. | |
4036 */ | |
4037 else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) | |
4038 && !bufIsChanged(buf) && stat_res >= 0) | |
4039 reload = TRUE; | |
4040 else | |
4041 { | |
179 | 4042 if (stat_res < 0) |
4043 reason = "deleted"; | |
4044 else if (bufIsChanged(buf)) | |
4045 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
|
4046 /* |
746b95fd25ad
patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
4047 * 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
|
4048 * 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
|
4049 * 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
|
4050 */ |
179 | 4051 else if (orig_size != buf->b_orig_size || buf_contents_changed(buf)) |
4052 reason = "changed"; | |
4053 else if (orig_mode != buf->b_orig_mode) | |
4054 reason = "mode"; | |
4055 else | |
4056 reason = "time"; | |
4057 | |
7 | 4058 /* |
4059 * Only give the warning if there are no FileChangedShell | |
4060 * autocommands. | |
4061 * Avoid being called recursively by setting "busy". | |
4062 */ | |
4063 busy = TRUE; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4064 #ifdef FEAT_EVAL |
179 | 4065 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1); |
4066 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
|
4067 #endif |
1834 | 4068 ++allbuf_lock; |
7 | 4069 n = apply_autocmds(EVENT_FILECHANGEDSHELL, |
4070 buf->b_fname, buf->b_fname, FALSE, buf); | |
1834 | 4071 --allbuf_lock; |
7 | 4072 busy = FALSE; |
4073 if (n) | |
4074 { | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4075 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
|
4076 emsg(_("E246: FileChangedShell autocommand deleted buffer")); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4077 #ifdef FEAT_EVAL |
179 | 4078 s = get_vim_var_str(VV_FCS_CHOICE); |
4079 if (STRCMP(s, "reload") == 0 && *reason != 'd') | |
4080 reload = TRUE; | |
4081 else if (STRCMP(s, "ask") == 0) | |
4082 n = FALSE; | |
4083 else | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4084 #endif |
179 | 4085 return 2; |
7 | 4086 } |
179 | 4087 if (!n) |
7 | 4088 { |
179 | 4089 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
|
4090 { |
0026ea34a8d5
patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents:
17476
diff
changeset
|
4091 // 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
|
4092 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
|
4093 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
|
4094 } |
7 | 4095 else |
4096 { | |
4097 helpmesg = TRUE; | |
4098 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
4099 can_reload = TRUE; | |
4100 #endif | |
179 | 4101 if (reason[2] == 'n') |
4102 { | |
7 | 4103 mesg = _("W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well"); |
179 | 4104 mesg2 = _("See \":help W12\" for more info."); |
4105 } | |
4106 else if (reason[1] == 'h') | |
4107 { | |
7 | 4108 mesg = _("W11: Warning: File \"%s\" has changed since editing started"); |
179 | 4109 mesg2 = _("See \":help W11\" for more info."); |
4110 } | |
4111 else if (*reason == 'm') | |
4112 { | |
7 | 4113 mesg = _("W16: Warning: Mode of file \"%s\" has changed since editing started"); |
179 | 4114 mesg2 = _("See \":help W16\" for more info."); |
4115 } | |
1913 | 4116 else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4117 // 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
|
4118 // in check_mtime() later. |
1913 | 4119 buf->b_mtime_read = buf->b_mtime; |
7 | 4120 } |
4121 } | |
4122 } | |
4123 | |
4124 } | |
4125 else if ((buf->b_flags & BF_NEW) && !(buf->b_flags & BF_NEW_W) | |
4126 && vim_fexists(buf->b_ffname)) | |
4127 { | |
4128 retval = 1; | |
4129 mesg = _("W13: Warning: File \"%s\" has been created after editing started"); | |
4130 buf->b_flags |= BF_NEW_W; | |
4131 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
4132 can_reload = TRUE; | |
4133 #endif | |
4134 } | |
4135 | |
4136 if (mesg != NULL) | |
4137 { | |
4138 path = home_replace_save(buf, buf->b_fname); | |
4139 if (path != NULL) | |
4140 { | |
179 | 4141 if (!helpmesg) |
7 | 4142 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
|
4143 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
|
4144 sprintf(tbuf, mesg, path); |
1848 | 4145 #ifdef FEAT_EVAL |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4146 // 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
|
4147 // 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
|
4148 set_vim_var_string(VV_WARNINGMSG, (char_u *)tbuf, -1); |
1848 | 4149 #endif |
7 | 4150 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) |
4151 if (can_reload) | |
4152 { | |
4153 if (*mesg2 != NUL) | |
4154 { | |
4155 STRCAT(tbuf, "\n"); | |
4156 STRCAT(tbuf, mesg2); | |
4157 } | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4158 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
|
4159 (char_u *)tbuf, |
2684 | 4160 (char_u *)_("&OK\n&Load File"), 1, NULL, TRUE) == 2) |
7 | 4161 reload = TRUE; |
4162 } | |
4163 else | |
4164 #endif | |
4165 if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned) | |
4166 { | |
4167 if (*mesg2 != NUL) | |
4168 { | |
4169 STRCAT(tbuf, "; "); | |
4170 STRCAT(tbuf, mesg2); | |
4171 } | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4172 emsg(tbuf); |
7 | 4173 retval = 2; |
4174 } | |
4175 else | |
4176 { | |
4177 if (!autocmd_busy) | |
4178 { | |
4179 msg_start(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
4180 msg_puts_attr(tbuf, HL_ATTR(HLF_E) + MSG_HIST); |
7 | 4181 if (*mesg2 != NUL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15531
diff
changeset
|
4182 msg_puts_attr(mesg2, HL_ATTR(HLF_W) + MSG_HIST); |
7 | 4183 msg_clr_eos(); |
4184 (void)msg_end(); | |
4185 if (emsg_silent == 0) | |
4186 { | |
4187 out_flush(); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4188 #ifdef FEAT_GUI |
7 | 4189 if (!focus) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4190 #endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4191 // 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
|
4192 ui_delay(1004L, TRUE); |
7 | 4193 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4194 // don't redraw and erase the message |
7 | 4195 redraw_cmdline = FALSE; |
4196 } | |
4197 } | |
4198 already_warned = TRUE; | |
4199 } | |
4200 | |
4201 vim_free(path); | |
4202 vim_free(tbuf); | |
4203 } | |
4204 } | |
4205 | |
4206 if (reload) | |
3776 | 4207 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4208 // Reload the buffer. |
628 | 4209 buf_reload(buf, orig_mode); |
3776 | 4210 #ifdef FEAT_PERSISTENT_UNDO |
4211 if (buf->b_p_udf && buf->b_ffname != NULL) | |
4212 { | |
4213 char_u hash[UNDO_HASH_SIZE]; | |
4214 buf_T *save_curbuf = curbuf; | |
4215 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4216 // Any existing undo file is unusable, write it now. |
3776 | 4217 curbuf = buf; |
4218 u_compute_hash(hash); | |
4219 u_write_undo(NULL, FALSE, buf, hash); | |
4220 curbuf = save_curbuf; | |
4221 } | |
4222 #endif | |
4223 } | |
7 | 4224 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4225 // 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
|
4226 if (bufref_valid(&bufref) && retval != 0) |
765 | 4227 (void)apply_autocmds(EVENT_FILECHANGEDSHELLPOST, |
4228 buf->b_fname, buf->b_fname, FALSE, buf); | |
7 | 4229 #ifdef FEAT_GUI |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4230 // 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
|
4231 // 'mousefocus' |
7 | 4232 need_mouse_correct = save_mouse_correct; |
4233 #endif | |
4234 | |
4235 return retval; | |
4236 } | |
4237 | |
311 | 4238 /* |
4239 * Reload a buffer that is already loaded. | |
4240 * Used when the file was changed outside of Vim. | |
628 | 4241 * "orig_mode" is buf->b_orig_mode before the need for reloading was detected. |
4242 * buf->b_orig_mode may have been reset already. | |
311 | 4243 */ |
4244 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4245 buf_reload(buf_T *buf, int orig_mode) |
311 | 4246 { |
4247 exarg_T ea; | |
4248 pos_T old_cursor; | |
4249 linenr_T old_topline; | |
4250 int old_ro = buf->b_p_ro; | |
4251 buf_T *savebuf; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4252 bufref_T bufref; |
311 | 4253 int saved = OK; |
4254 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
|
4255 int flags = READ_NEW; |
311 | 4256 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4257 // set curwin/curbuf for "buf" and save some things |
311 | 4258 aucmd_prepbuf(&aco, buf); |
4259 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4260 // 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
|
4261 // 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
|
4262 // and encoding to be the same. |
311 | 4263 if (prep_exarg(&ea, buf) == OK) |
4264 { | |
4265 old_cursor = curwin->w_cursor; | |
4266 old_topline = curwin->w_topline; | |
4267 | |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
4268 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
|
4269 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4270 // 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
|
4271 // 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
|
4272 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
|
4273 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
|
4274 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
|
4275 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4276 |
311 | 4277 /* |
4278 * To behave like when a new file is edited (matters for | |
4279 * BufReadPost autocommands) we first need to delete the current | |
4280 * buffer contents. But if reading the file fails we should keep | |
4281 * the old contents. Can't use memory only, the file might be | |
4282 * too big. Use a hidden buffer to move the buffer contents to. | |
4283 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
4284 if (BUFEMPTY() || saved == FAIL) |
311 | 4285 savebuf = NULL; |
4286 else | |
4287 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4288 // Allocate a buffer without putting it in the buffer list. |
311 | 4289 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
|
4290 set_bufref(&bufref, savebuf); |
837 | 4291 if (savebuf != NULL && buf == curbuf) |
311 | 4292 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4293 // Open the memline. |
311 | 4294 curbuf = savebuf; |
4295 curwin->w_buffer = savebuf; | |
625 | 4296 saved = ml_open(curbuf); |
311 | 4297 curbuf = buf; |
4298 curwin->w_buffer = buf; | |
4299 } | |
837 | 4300 if (savebuf == NULL || saved == FAIL || buf != curbuf |
311 | 4301 || move_lines(buf, savebuf) == FAIL) |
4302 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4303 semsg(_("E462: Could not prepare for reloading \"%s\""), |
311 | 4304 buf->b_fname); |
4305 saved = FAIL; | |
4306 } | |
4307 } | |
4308 | |
4309 if (saved == OK) | |
4310 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4311 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
|
4312 keep_filetype = TRUE; // don't detect 'filetype' |
311 | 4313 if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, |
4314 (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
|
4315 (linenr_T)MAXLNUM, &ea, flags) != OK) |
311 | 4316 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4317 #if defined(FEAT_EVAL) |
311 | 4318 if (!aborting()) |
4319 #endif | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
4320 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
|
4321 if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) |
311 | 4322 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4323 // 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
|
4324 // 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
|
4325 while (!BUFEMPTY()) |
837 | 4326 if (ml_delete(buf->b_ml.ml_line_count, FALSE) == FAIL) |
311 | 4327 break; |
4328 (void)move_lines(savebuf, buf); | |
4329 } | |
4330 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4331 else if (buf == curbuf) // "buf" still valid |
311 | 4332 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4333 // 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
|
4334 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
|
4335 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
|
4336 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4337 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
|
4338 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
|
4339 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
4340 else |
2482
88751831fa0a
When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents:
2410
diff
changeset
|
4341 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4342 // 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
|
4343 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
|
4344 } |
311 | 4345 } |
4346 } | |
4347 vim_free(ea.cmd); | |
4348 | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9391
diff
changeset
|
4349 if (savebuf != NULL && bufref_valid(&bufref)) |
311 | 4350 wipe_buffer(savebuf, FALSE); |
4351 | |
4352 #ifdef FEAT_DIFF | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4353 // Invalidate diff info if necessary. |
837 | 4354 diff_invalidate(curbuf); |
311 | 4355 #endif |
4356 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4357 // 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
|
4358 // have been removed). |
311 | 4359 if (old_topline > curbuf->b_ml.ml_line_count) |
4360 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
4361 else | |
4362 curwin->w_topline = old_topline; | |
4363 curwin->w_cursor = old_cursor; | |
4364 check_cursor(); | |
4365 update_topline(); | |
4366 keep_filetype = FALSE; | |
4367 #ifdef FEAT_FOLDING | |
4368 { | |
1863 | 4369 win_T *wp; |
4370 tabpage_T *tp; | |
311 | 4371 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4372 // Update folds unless they are defined manually. |
1863 | 4373 FOR_ALL_TAB_WINDOWS(tp, wp) |
311 | 4374 if (wp->w_buffer == curwin->w_buffer |
4375 && !foldmethodIsManual(wp)) | |
4376 foldUpdateAll(wp); | |
4377 } | |
4378 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4379 // 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
|
4380 // 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
|
4381 // reset it, might have had a read error. |
311 | 4382 if (orig_mode == curbuf->b_orig_mode) |
4383 curbuf->b_p_ro |= old_ro; | |
4071 | 4384 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4385 // Modelines must override settings done by autocommands. |
4071 | 4386 do_modelines(0); |
311 | 4387 } |
4388 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4389 // restore curwin/curbuf and a few other things |
311 | 4390 aucmd_restbuf(&aco); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4391 // Careful: autocommands may have made "buf" invalid! |
311 | 4392 } |
4393 | |
7 | 4394 void |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
4395 buf_store_time(buf_T *buf, stat_T *st, char_u *fname UNUSED) |
7 | 4396 { |
4397 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
|
4398 buf->b_orig_size = st->st_size; |
7 | 4399 #ifdef HAVE_ST_MODE |
4400 buf->b_orig_mode = (int)st->st_mode; | |
4401 #else | |
4402 buf->b_orig_mode = mch_getperm(fname); | |
4403 #endif | |
4404 } | |
4405 | |
4406 /* | |
4407 * Adjust the line with missing eol, used for the next write. | |
4408 * Used for do_filter(), when the input lines for the filter are deleted. | |
4409 */ | |
4410 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4411 write_lnum_adjust(linenr_T offset) |
7 | 4412 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4413 if (curbuf->b_no_eol_lnum != 0) // only if there is a missing eol |
2707 | 4414 curbuf->b_no_eol_lnum += offset; |
7 | 4415 } |
4416 | |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4417 #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
|
4418 /* |
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
|
4419 * Core part of "readdir()" function. |
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
|
4420 * Retrieve the list of files/directories of "path" into "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
|
4421 * 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
|
4422 */ |
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
|
4423 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
|
4424 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
|
4425 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
|
4426 char_u *path, |
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
|
4427 void *context, |
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
|
4428 int (*checkitem)(void *context, char_u *name)) |
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
|
4429 { |
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
|
4430 int failed = FALSE; |
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
|
4431 #ifdef MSWIN |
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
|
4432 char_u *buf, *p; |
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
|
4433 int 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
|
4434 HANDLE hFind = INVALID_HANDLE_VALUE; |
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
|
4435 WIN32_FIND_DATAW wfb; |
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
|
4436 WCHAR *wn = NULL; // UTF-16 name, NULL when not used. |
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
|
4437 #endif |
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
|
4438 |
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
|
4439 ga_init2(gap, (int)sizeof(char *), 20); |
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
|
4440 |
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
|
4441 #ifdef MSWIN |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
4442 buf = alloc(MAXPATHL); |
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
|
4443 if (buf == NULL) |
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
|
4444 return FAIL; |
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
|
4445 STRNCPY(buf, path, MAXPATHL-5); |
16766
d2deaaf21305
patch 8.1.1385: signed/unsigned compiler warning
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4446 p = buf + STRLEN(buf); |
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
|
4447 MB_PTR_BACK(buf, p); |
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
|
4448 if (*p == '\\' || *p == '/') |
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
|
4449 *p = NUL; |
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
|
4450 STRCAT(buf, "\\*"); |
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
|
4451 |
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
|
4452 wn = enc_to_utf16(buf, NULL); |
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
|
4453 if (wn != NULL) |
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
|
4454 hFind = FindFirstFileW(wn, &wfb); |
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
|
4455 ok = (hFind != INVALID_HANDLE_VALUE); |
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
|
4456 if (!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
|
4457 { |
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
|
4458 failed = TRUE; |
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
|
4459 smsg(_(e_notopen), path); |
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
|
4460 } |
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
|
4461 else |
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
|
4462 { |
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
|
4463 while (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
|
4464 { |
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
|
4465 int ignore; |
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
|
4466 |
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
|
4467 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here |
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
|
4468 if (p == NULL) |
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
|
4469 break; // out of memory |
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
|
4470 |
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
|
4471 ignore = p[0] == '.' && (p[1] == NUL |
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
|
4472 || (p[1] == '.' && p[2] == NUL)); |
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
|
4473 if (!ignore && checkitem != NULL) |
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
|
4474 { |
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
|
4475 int r = checkitem(context, p); |
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
|
4476 |
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
|
4477 if (r < 0) |
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
|
4478 { |
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
|
4479 vim_free(p); |
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
|
4480 break; |
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
|
4481 } |
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
|
4482 if (r == 0) |
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
|
4483 ignore = TRUE; |
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
|
4484 } |
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
|
4485 |
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
|
4486 if (!ignore) |
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
|
4487 { |
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
|
4488 if (ga_grow(gap, 1) == 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
|
4489 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); |
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
|
4490 else |
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
|
4491 { |
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
|
4492 failed = TRUE; |
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
|
4493 vim_free(p); |
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
|
4494 break; |
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
|
4495 } |
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
|
4496 } |
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
|
4497 |
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
|
4498 vim_free(p); |
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
|
4499 ok = FindNextFileW(hFind, &wfb); |
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
|
4500 } |
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
|
4501 FindClose(hFind); |
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
|
4502 } |
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
|
4503 |
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
|
4504 vim_free(buf); |
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
|
4505 vim_free(wn); |
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
|
4506 #else |
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
|
4507 DIR *dirp; |
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
|
4508 struct dirent *dp; |
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
|
4509 char_u *p; |
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
|
4510 |
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
|
4511 dirp = opendir((char *)path); |
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
|
4512 if (dirp == NULL) |
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
|
4513 { |
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
|
4514 failed = TRUE; |
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
|
4515 smsg(_(e_notopen), path); |
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
|
4516 } |
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
|
4517 else |
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
|
4518 { |
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
|
4519 for (;;) |
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
|
4520 { |
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
|
4521 int ignore; |
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
|
4522 |
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
|
4523 dp = readdir(dirp); |
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
|
4524 if (dp == NULL) |
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
|
4525 break; |
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
|
4526 p = (char_u *)dp->d_name; |
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
|
4527 |
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
|
4528 ignore = p[0] == '.' && |
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
|
4529 (p[1] == NUL || |
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
|
4530 (p[1] == '.' && p[2] == NUL)); |
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
|
4531 if (!ignore && checkitem != NULL) |
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
|
4532 { |
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
|
4533 int r = checkitem(context, p); |
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
|
4534 |
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
|
4535 if (r < 0) |
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
|
4536 break; |
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
|
4537 if (r == 0) |
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
|
4538 ignore = TRUE; |
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
|
4539 } |
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
|
4540 |
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
|
4541 if (!ignore) |
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
|
4542 { |
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
|
4543 if (ga_grow(gap, 1) == 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
|
4544 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); |
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
|
4545 else |
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
|
4546 { |
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
|
4547 failed = TRUE; |
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
|
4548 break; |
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
|
4549 } |
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
|
4550 } |
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
|
4551 } |
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
|
4552 |
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
|
4553 closedir(dirp); |
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
|
4554 } |
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
|
4555 #endif |
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
|
4556 |
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
|
4557 if (!failed && gap->ga_len > 0) |
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
|
4558 sort_strings((char_u **)gap->ga_data, gap->ga_len); |
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
|
4559 |
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
|
4560 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
|
4561 } |
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
|
4562 |
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
|
4563 /* |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4564 * 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
|
4565 * 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
|
4566 */ |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4567 int |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4568 delete_recursive(char_u *name) |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4569 { |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4570 int result = 0; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4571 int i; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4572 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
|
4573 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
|
4574 |
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
|
4575 // 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
|
4576 // points to. |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4577 if ( |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
4578 # if defined(UNIX) || defined(MSWIN) |
7657
9c5e8254ea6b
commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents:
7641
diff
changeset
|
4579 mch_isrealdir(name) |
7629
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4580 # else |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4581 mch_isdir(name) |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4582 # endif |
befbed72da87
commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents:
7615
diff
changeset
|
4583 ) |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4584 { |
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
|
4585 exp = vim_strsave(name); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4586 if (exp == NULL) |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4587 return -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
|
4588 if (readdir_core(&ga, exp, NULL, NULL) == 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
|
4589 { |
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
|
4590 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
|
4591 { |
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
|
4592 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
|
4593 ((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
|
4594 if (delete_recursive(NameBuff) != 0) |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4595 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
|
4596 } |
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
|
4597 ga_clear_strings(&ga); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4598 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4599 else |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4600 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
|
4601 (void)mch_rmdir(exp); |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4602 vim_free(exp); |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4603 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4604 else |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4605 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
|
4606 |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4607 return result; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4608 } |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4609 #endif |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4610 |
7 | 4611 #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
|
4612 static long temp_count = 0; // Temp filename counter. |
7 | 4613 |
4614 /* | |
4615 * Delete the temp directory and all files it contains. | |
4616 */ | |
4617 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4618 vim_deltempdir(void) |
7 | 4619 { |
4620 if (vim_tempdir != NULL) | |
4621 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4622 // remove the trailing path separator |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4623 gettail(vim_tempdir)[-1] = NUL; |
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4624 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
|
4625 VIM_CLEAR(vim_tempdir); |
7 | 4626 } |
4627 } | |
7615
228ff048db20
commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents:
7410
diff
changeset
|
4628 |
7 | 4629 /* |
1997 | 4630 * Directory "tempdir" was created. Expand this name to a full path and put |
4631 * it in "vim_tempdir". This avoids that using ":cd" would confuse us. | |
4632 * "tempdir" must be no longer than MAXPATHL. | |
4633 */ | |
4634 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4635 vim_settempdir(char_u *tempdir) |
1997 | 4636 { |
4637 char_u *buf; | |
4638 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16754
diff
changeset
|
4639 buf = alloc(MAXPATHL + 2); |
1997 | 4640 if (buf != NULL) |
4641 { | |
4642 if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL) | |
4643 STRCPY(buf, tempdir); | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
4644 add_pathsep(buf); |
1997 | 4645 vim_tempdir = vim_strsave(buf); |
4646 vim_free(buf); | |
4647 } | |
4648 } | |
2006 | 4649 #endif |
1997 | 4650 |
4651 /* | |
7 | 4652 * vim_tempname(): Return a unique name that can be used for a temp file. |
4653 * | |
9291
bff3cd5cf922
commit https://github.com/vim/vim/commit/76ae22fef3cb224ca7fbf97517f881e825d4d0c2
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
4654 * 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
|
4655 * guaranteed to NOT be created. |
7 | 4656 * |
4657 * The returned pointer is to allocated memory. | |
4658 * The returned pointer is NULL if no valid name was found. | |
4659 */ | |
4660 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4661 vim_tempname( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4662 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
|
4663 int keep UNUSED) |
7 | 4664 { |
4665 #ifdef USE_TMPNAM | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4666 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
|
4667 #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
|
4668 WCHAR itmp[TEMPNAMELEN]; |
7 | 4669 #else |
4670 char_u itmp[TEMPNAMELEN]; | |
4671 #endif | |
4672 | |
4673 #ifdef TEMPDIRNAMES | |
4674 static char *(tempdirs[]) = {TEMPDIRNAMES}; | |
4675 int i; | |
4676 # ifndef EEXIST | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9291
diff
changeset
|
4677 stat_T st; |
7 | 4678 # endif |
4679 | |
4680 /* | |
4681 * This will create a directory for private use by this instance of Vim. | |
4682 * This is done once, and the same directory is used for all temp files. | |
4683 * This method avoids security problems because of symlink attacks et al. | |
4684 * It's also a bit faster, because we only need to check for an existing | |
4685 * file when creating the directory and not for each temp file. | |
4686 */ | |
4687 if (vim_tempdir == NULL) | |
4688 { | |
4689 /* | |
4690 * Try the entries in TEMPDIRNAMES to create the temp directory. | |
4691 */ | |
1877 | 4692 for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i) |
7 | 4693 { |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2028
diff
changeset
|
4694 # ifndef HAVE_MKDTEMP |
1997 | 4695 size_t itmplen; |
4696 long nr; | |
4697 long off; | |
4698 # endif | |
4699 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4700 // 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
|
4701 // Skip the directory check if the expansion fails. |
7 | 4702 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
|
4703 if (itmp[0] != '$' && mch_isdir(itmp)) |
372c785c04b6
commit https://github.com/vim/vim/commit/e1a61991d9b6fd5f65636d17583f93118268cda5
Christian Brabandt <cb@256bit.org>
parents:
7285
diff
changeset
|
4704 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4705 // directory exists |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9509
diff
changeset
|
4706 add_pathsep(itmp); |
1997 | 4707 |
4708 # ifdef HAVE_MKDTEMP | |
9211
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4709 { |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4710 # 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
|
4711 // 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
|
4712 // "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
|
4713 mode_t umask_save = umask(077); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4714 # endif |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4715 // Leave room for filename |
9211
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4716 STRCAT(itmp, "vXXXXXX"); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4717 if (mkdtemp((char *)itmp) != NULL) |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4718 vim_settempdir(itmp); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4719 # if defined(UNIX) || defined(VMS) |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4720 (void)umask(umask_save); |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4721 # endif |
d2b9e454c73d
commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents:
9068
diff
changeset
|
4722 } |
1997 | 4723 # else |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4724 // 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
|
4725 // 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
|
4726 // 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
|
4727 // security problems because of the predictable number. |
7 | 4728 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
|
4729 itmplen = STRLEN(itmp); |
7 | 4730 |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4731 // 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
|
4732 // doesn't exist. |
7 | 4733 for (off = 0; off < 10000L; ++off) |
4734 { | |
4735 int r; | |
1997 | 4736 # if defined(UNIX) || defined(VMS) |
7 | 4737 mode_t umask_save; |
1997 | 4738 # endif |
4739 | |
4740 sprintf((char *)itmp + itmplen, "v%ld", nr + off); | |
4741 # ifndef EEXIST | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4742 // 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
|
4743 // 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
|
4744 // although it's fail-safe. |
7 | 4745 if (mch_stat((char *)itmp, &st) >= 0) |
4746 continue; | |
1997 | 4747 # endif |
4748 # 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
|
4749 // 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
|
4750 // "repl" has been reported to use "177". |
7 | 4751 umask_save = umask(077); |
1997 | 4752 # endif |
7 | 4753 r = vim_mkdir(itmp, 0700); |
1997 | 4754 # if defined(UNIX) || defined(VMS) |
7 | 4755 (void)umask(umask_save); |
1997 | 4756 # endif |
7 | 4757 if (r == 0) |
4758 { | |
1997 | 4759 vim_settempdir(itmp); |
7 | 4760 break; |
4761 } | |
1997 | 4762 # ifdef EEXIST |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4763 // 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
|
4764 // 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
|
4765 // place. |
7 | 4766 if (errno != EEXIST) |
1997 | 4767 # endif |
7 | 4768 break; |
4769 } | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4770 # endif // HAVE_MKDTEMP |
7 | 4771 if (vim_tempdir != NULL) |
4772 break; | |
4773 } | |
4774 } | |
4775 } | |
4776 | |
4777 if (vim_tempdir != NULL) | |
4778 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4779 // 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
|
4780 // directory and nobody else creates a file in it. |
7 | 4781 sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++); |
4782 return vim_strsave(itmp); | |
4783 } | |
4784 | |
4785 return NULL; | |
4786 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4787 #else // TEMPDIRNAMES |
7 | 4788 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
4789 # 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
|
4790 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
|
4791 WCHAR buf4[4]; |
7 | 4792 char_u *retval; |
4793 char_u *p; | |
4794 | |
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
|
4795 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
|
4796 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
|
4797 { |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4798 wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4799 wszTempFile[1] = NUL; |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4800 } |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4801 wcscpy(buf4, L"VIM"); |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4802 buf4[2] = extra_char; // make it "VIa", "VIb", etc. |
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
|
4803 if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) |
7 | 4804 return NULL; |
6721 | 4805 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
|
4806 // 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
|
4807 (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
|
4808 |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4809 // 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
|
4810 // "sh". NOTE: This also checks 'shellcmdflag' to help those people who |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4811 // didn't set 'shellslash'. |
7f91de3f5e35
patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents:
15750
diff
changeset
|
4812 retval = utf16_to_enc(itmp, NULL); |
7 | 4813 if (*p_shcf == '-' || p_ssl) |
4814 for (p = retval; *p; ++p) | |
4815 if (*p == '\\') | |
4816 *p = '/'; | |
4817 return retval; | |
4818 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
4819 # else // MSWIN |
7 | 4820 |
4821 # ifdef USE_TMPNAM | |
2697 | 4822 char_u *p; |
4823 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4824 // tmpnam() will make its own name |
2697 | 4825 p = tmpnam((char *)itmp); |
4826 if (p == NULL || *p == NUL) | |
7 | 4827 return NULL; |
4828 # else | |
4829 char_u *p; | |
4830 | |
4831 # ifdef VMS_TEMPNAM | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4832 // 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
|
4833 // a do-nothing function. Therefore we use tempnam(). |
7 | 4834 sprintf((char *)itmp, "VIM%c", extra_char); |
4835 p = (char_u *)tempnam("tmp:", (char *)itmp); | |
4836 if (p != NULL) | |
4837 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4838 // 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
|
4839 // and VIM will then be unable to find the file later |
7 | 4840 STRCPY(itmp, p); |
4841 STRCAT(itmp, ".txt"); | |
4842 free(p); | |
4843 } | |
4844 else | |
4845 return NULL; | |
4846 # else | |
4847 STRCPY(itmp, TEMPNAME); | |
4848 if ((p = vim_strchr(itmp, '?')) != NULL) | |
4849 *p = extra_char; | |
4850 if (mktemp((char *)itmp) == NULL) | |
4851 return NULL; | |
4852 # endif | |
4853 # endif | |
4854 | |
4855 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
|
4856 # endif // MSWIN |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4857 #endif // TEMPDIRNAMES |
7 | 4858 } |
4859 | |
4860 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
4861 /* | |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
4862 * 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
|
4863 * it looks like a URL. |
7 | 4864 */ |
4865 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4866 forward_slash(char_u *fname) |
7 | 4867 { |
4868 char_u *p; | |
4869 | |
7170
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
4870 if (path_with_url(fname)) |
beb67ef38f88
commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents:
7005
diff
changeset
|
4871 return; |
7 | 4872 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
|
4873 // The Big5 encoding can have '\' in the trail byte. |
474 | 4874 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 4875 ++p; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4876 else if (*p == '\\') |
7 | 4877 *p = '/'; |
4878 } | |
4879 #endif | |
4880 | |
4881 /* | |
153 | 4882 * Try matching a filename with a "pattern" ("prog" is NULL), or use the |
4883 * precompiled regprog "prog" ("pattern" is NULL). That avoids calling | |
4884 * vim_regcomp() often. | |
7 | 4885 * Used for autocommands and 'wildignore'. |
4886 * Returns TRUE if there is a match, FALSE otherwise. | |
4887 */ | |
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
|
4888 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4889 match_file_pat( |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4890 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
|
4891 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
|
4892 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
|
4893 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
|
4894 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
|
4895 int allow_dirs) // allow matching with dir |
7 | 4896 { |
4897 regmatch_T regmatch; | |
4898 int result = FALSE; | |
4899 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4900 regmatch.rm_ic = p_fic; // ignore case if 'fileignorecase' is set |
6470 | 4901 if (prog != NULL) |
4902 regmatch.regprog = *prog; | |
7 | 4903 else |
6470 | 4904 regmatch.regprog = vim_regcomp(pattern, RE_MAGIC); |
7 | 4905 |
4906 /* | |
4907 * Try for a match with the pattern with: | |
4908 * 1. the full file name, when the pattern has a '/'. | |
4909 * 2. the short file name, when the pattern has a '/'. | |
4910 * 3. the tail of the file name, when the pattern has no '/'. | |
4911 */ | |
6470 | 4912 if (regmatch.regprog != NULL |
7 | 4913 && ((allow_dirs |
4914 && (vim_regexec(®match, fname, (colnr_T)0) | |
4915 || (sfname != NULL | |
4916 && vim_regexec(®match, sfname, (colnr_T)0)))) | |
6470 | 4917 || (!allow_dirs && vim_regexec(®match, tail, (colnr_T)0)))) |
7 | 4918 result = TRUE; |
4919 | |
6375 | 4920 if (prog != NULL) |
4921 *prog = regmatch.regprog; | |
4922 else | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
4923 vim_regfree(regmatch.regprog); |
7 | 4924 return result; |
4925 } | |
4926 | |
4927 #if defined(FEAT_WILDIGN) || defined(PROTO) | |
4928 /* | |
4929 * Return TRUE if a file matches with a pattern in "list". | |
4930 * "list" is a comma-separated list of patterns, like 'wildignore'. | |
4931 * "sfname" is the short file name or NULL, "ffname" the long file name. | |
4932 */ | |
4933 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4934 match_file_list(char_u *list, char_u *sfname, char_u *ffname) |
7 | 4935 { |
4936 char_u buf[100]; | |
4937 char_u *tail; | |
4938 char_u *regpat; | |
4939 char allow_dirs; | |
4940 int match; | |
4941 char_u *p; | |
4942 | |
4943 tail = gettail(sfname); | |
4944 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4945 // try all patterns in 'wildignore' |
7 | 4946 p = list; |
4947 while (*p) | |
4948 { | |
4949 copy_option_part(&p, buf, 100, ","); | |
4950 regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE); | |
4951 if (regpat == NULL) | |
4952 break; | |
153 | 4953 match = match_file_pat(regpat, NULL, ffname, sfname, |
4954 tail, (int)allow_dirs); | |
7 | 4955 vim_free(regpat); |
4956 if (match) | |
4957 return TRUE; | |
4958 } | |
4959 return FALSE; | |
4960 } | |
4961 #endif | |
4962 | |
4963 /* | |
4964 * Convert the given pattern "pat" which has shell style wildcards in it, into | |
4965 * a regular expression, and return the result in allocated memory. If there | |
4966 * is a directory path separator to be matched, then TRUE is put in | |
4967 * allow_dirs, otherwise FALSE is put there -- webb. | |
4968 * Handle backslashes before special characters, like "\*" and "\ ". | |
4969 * | |
4970 * Returns NULL when out of memory. | |
4971 */ | |
4972 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4973 file_pat_to_reg_pat( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4974 char_u *pat, |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4975 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
|
4976 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
|
4977 int no_bslash UNUSED) // Don't use a backward slash as pathsep |
7 | 4978 { |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
4979 int size = 2; // '^' at start, '$' at end |
7 | 4980 char_u *endp; |
4981 char_u *reg_pat; | |
4982 char_u *p; | |
4983 int i; | |
4984 int nested = 0; | |
4985 int add_dollar = TRUE; | |
4986 | |
4987 if (allow_dirs != NULL) | |
4988 *allow_dirs = FALSE; | |
4989 if (pat_end == NULL) | |
4990 pat_end = pat + STRLEN(pat); | |
4991 | |
4992 for (p = pat; p < pat_end; p++) | |
4993 { | |
4994 switch (*p) | |
4995 { | |
4996 case '*': | |
4997 case '.': | |
4998 case ',': | |
4999 case '{': | |
5000 case '}': | |
5001 case '~': | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5002 size += 2; // extra backslash |
7 | 5003 break; |
5004 #ifdef BACKSLASH_IN_FILENAME | |
5005 case '\\': | |
5006 case '/': | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5007 size += 4; // could become "[\/]" |
7 | 5008 break; |
5009 #endif | |
5010 default: | |
5011 size++; | |
474 | 5012 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 5013 { |
5014 ++p; | |
5015 ++size; | |
5016 } | |
5017 break; | |
5018 } | |
5019 } | |
5020 reg_pat = alloc(size + 1); | |
5021 if (reg_pat == NULL) | |
5022 return NULL; | |
5023 | |
5024 i = 0; | |
5025 | |
5026 if (pat[0] == '*') | |
5027 while (pat[0] == '*' && pat < pat_end - 1) | |
5028 pat++; | |
5029 else | |
5030 reg_pat[i++] = '^'; | |
5031 endp = pat_end - 1; | |
7005 | 5032 if (endp >= pat && *endp == '*') |
7 | 5033 { |
5034 while (endp - pat > 0 && *endp == '*') | |
5035 endp--; | |
5036 add_dollar = FALSE; | |
5037 } | |
5038 for (p = pat; *p && nested >= 0 && p <= endp; p++) | |
5039 { | |
5040 switch (*p) | |
5041 { | |
5042 case '*': | |
5043 reg_pat[i++] = '.'; | |
5044 reg_pat[i++] = '*'; | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5045 while (p[1] == '*') // "**" matches like "*" |
444 | 5046 ++p; |
7 | 5047 break; |
5048 case '.': | |
5049 case '~': | |
5050 reg_pat[i++] = '\\'; | |
5051 reg_pat[i++] = *p; | |
5052 break; | |
5053 case '?': | |
5054 reg_pat[i++] = '.'; | |
5055 break; | |
5056 case '\\': | |
5057 if (p[1] == NUL) | |
5058 break; | |
5059 #ifdef BACKSLASH_IN_FILENAME | |
5060 if (!no_bslash) | |
5061 { | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5062 // translate: |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5063 // "\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
|
5064 // "\*" to "\\.*" e.g., "dir\*.c" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5065 // "\?" to "\\." e.g., "dir\??.c" |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5066 // "\+" to "\+" e.g., "fileX\+.c" |
7 | 5067 if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?') |
5068 && p[1] != '+') | |
5069 { | |
5070 reg_pat[i++] = '['; | |
5071 reg_pat[i++] = '\\'; | |
5072 reg_pat[i++] = '/'; | |
5073 reg_pat[i++] = ']'; | |
5074 if (allow_dirs != NULL) | |
5075 *allow_dirs = TRUE; | |
5076 break; | |
5077 } | |
5078 } | |
5079 #endif | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5080 // Undo escaping from ExpandEscape(): |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5081 // foo\?bar -> foo?bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5082 // foo\%bar -> foo%bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5083 // foo\,bar -> foo,bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5084 // foo\ bar -> foo bar |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5085 // 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
|
5086 // regexp. |
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5087 // 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
|
5088 // verymagic. Use "\\\{n,m\}"" to get "\{n,m}". |
7 | 5089 if (*++p == '?' |
5090 #ifdef BACKSLASH_IN_FILENAME | |
5091 && no_bslash | |
5092 #endif | |
5093 ) | |
5094 reg_pat[i++] = '?'; | |
5095 else | |
5104
93cccad6a26b
updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents:
5008
diff
changeset
|
5096 if (*p == ',' || *p == '%' || *p == '#' |
6999 | 5097 || vim_isspace(*p) || *p == '{' || *p == '}') |
2243
03a5f2897db3
Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents:
2241
diff
changeset
|
5098 reg_pat[i++] = *p; |
5259
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5099 else if (*p == '\\' && p[1] == '\\' && p[2] == '{') |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5100 { |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5101 reg_pat[i++] = '\\'; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5102 reg_pat[i++] = '{'; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5103 p += 2; |
6b7ab6a4f31a
updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
5104 } |
7 | 5105 else |
5106 { | |
5107 if (allow_dirs != NULL && vim_ispathsep(*p) | |
5108 #ifdef BACKSLASH_IN_FILENAME | |
5109 && (!no_bslash || *p != '\\') | |
5110 #endif | |
5111 ) | |
5112 *allow_dirs = TRUE; | |
5113 reg_pat[i++] = '\\'; | |
5114 reg_pat[i++] = *p; | |
5115 } | |
5116 break; | |
5117 #ifdef BACKSLASH_IN_FILENAME | |
5118 case '/': | |
5119 reg_pat[i++] = '['; | |
5120 reg_pat[i++] = '\\'; | |
5121 reg_pat[i++] = '/'; | |
5122 reg_pat[i++] = ']'; | |
5123 if (allow_dirs != NULL) | |
5124 *allow_dirs = TRUE; | |
5125 break; | |
5126 #endif | |
5127 case '{': | |
5128 reg_pat[i++] = '\\'; | |
5129 reg_pat[i++] = '('; | |
5130 nested++; | |
5131 break; | |
5132 case '}': | |
5133 reg_pat[i++] = '\\'; | |
5134 reg_pat[i++] = ')'; | |
5135 --nested; | |
5136 break; | |
5137 case ',': | |
5138 if (nested) | |
5139 { | |
5140 reg_pat[i++] = '\\'; | |
5141 reg_pat[i++] = '|'; | |
5142 } | |
5143 else | |
5144 reg_pat[i++] = ','; | |
5145 break; | |
5146 default: | |
474 | 5147 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) |
7 | 5148 reg_pat[i++] = *p++; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
5149 else if (allow_dirs != NULL && vim_ispathsep(*p)) |
7 | 5150 *allow_dirs = TRUE; |
5151 reg_pat[i++] = *p; | |
5152 break; | |
5153 } | |
5154 } | |
5155 if (add_dollar) | |
5156 reg_pat[i++] = '$'; | |
5157 reg_pat[i] = NUL; | |
5158 if (nested != 0) | |
5159 { | |
5160 if (nested < 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
5161 emsg(_("E219: Missing {.")); |
7 | 5162 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15442
diff
changeset
|
5163 emsg(_("E220: Missing }.")); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
5164 VIM_CLEAR(reg_pat); |
7 | 5165 } |
5166 return reg_pat; | |
5167 } | |
2664 | 5168 |
5169 #if defined(EINTR) || defined(PROTO) | |
5170 /* | |
5171 * Version of read() that retries when interrupted by EINTR (possibly | |
5172 * by a SIGWINCH). | |
5173 */ | |
5174 long | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5175 read_eintr(int fd, void *buf, size_t bufsize) |
2664 | 5176 { |
5177 long ret; | |
5178 | |
5179 for (;;) | |
5180 { | |
5181 ret = vim_read(fd, buf, bufsize); | |
5182 if (ret >= 0 || errno != EINTR) | |
5183 break; | |
5184 } | |
5185 return ret; | |
5186 } | |
5187 | |
5188 /* | |
5189 * Version of write() that retries when interrupted by EINTR (possibly | |
5190 * by a SIGWINCH). | |
5191 */ | |
5192 long | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5193 write_eintr(int fd, void *buf, size_t bufsize) |
2664 | 5194 { |
5195 long ret = 0; | |
5196 long wlen; | |
5197 | |
18779
8f05b3cf8557
patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18767
diff
changeset
|
5198 // 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
|
5199 // by a signal. |
2664 | 5200 while (ret < (long)bufsize) |
5201 { | |
2666 | 5202 wlen = vim_write(fd, (char *)buf + ret, bufsize - ret); |
2664 | 5203 if (wlen < 0) |
5204 { | |
5205 if (errno != EINTR) | |
5206 break; | |
5207 } | |
5208 else | |
5209 ret += wlen; | |
5210 } | |
5211 return ret; | |
5212 } | |
5213 #endif |