annotate src/fileio.c @ 26296:9f32ccdadd22 v8.2.3679

patch 8.2.3679: objc file detected as Octave Commit: https://github.com/vim/vim/commit/7329cfab36356c48edab7ed68f6244eb9e20a5b1 Author: Doug Kearns <dougkearns@gmail.com> Date: Fri Nov 26 13:01:41 2021 +0000 patch 8.2.3679: objc file detected as Octave Problem: objc file detected as Octave. (Antony Lee) Solution: Detect objc by preprocessor lines. (Doug Kearns, closes https://github.com/vim/vim/issues/9223, closes #9220)
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Nov 2021 14:15:05 +0100
parents aaec2028c8fc
children df2de1e63de0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9911
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * fileio.c: read from and write to a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
21329
bb3f60b0aca0 patch 8.2.1215: Atari MiNT support is outdated
Bram Moolenaar <Bram@vim.org>
parents: 21154
diff changeset
16 #if defined(__TANDEM)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
17 # include <limits.h> // for SSIZE_MAX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #endif
23503
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
19 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_EVAL)
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
20 # include <pwd.h>
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
21 # include <grp.h>
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
22 #endif
23503
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
23 #if defined(VMS) && defined(HAVE_XOS_R_H)
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
24 # include <x11/xos_r.h>
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
25 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
27 // Is there any system that doesn't have access()?
574
25a70b1cd2da updated for version 7.0163
vimboss
parents: 570
diff changeset
28 #define USE_MCH_ACCESS
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
22041
f55cba26348f patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents: 21745
diff changeset
30 #if defined(__hpux) && !defined(HAVE_DIRFD)
f55cba26348f patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents: 21745
diff changeset
31 # define dirfd(x) ((x)->__dd_fd)
f55cba26348f patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents: 21745
diff changeset
32 # define HAVE_DIRFD
f55cba26348f patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents: 21745
diff changeset
33 #endif
f55cba26348f patch 8.2.1570: configure check for dirfd() does not work on HPUX
Bram Moolenaar <Bram@vim.org>
parents: 21745
diff changeset
34
17692
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
35 static char_u *next_fenc(char_u **pp, int *alloced);
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
36 #ifdef FEAT_EVAL
7801
a1e71a01dbd6 commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents: 7657
diff changeset
37 static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 #ifdef FEAT_CRYPT
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
40 static char_u *check_for_cryptkey(char_u *cryptkey, char_u *ptr, long *sizep, off_T *filesizep, int newfile, char_u *fname, int *did_ask);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 #endif
7801
a1e71a01dbd6 commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents: 7657
diff changeset
42 static linenr_T readfile_linenr(linenr_T linecnt, char_u *p, char_u *endp);
a1e71a01dbd6 commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents: 7657
diff changeset
43 static char_u *check_for_bom(char_u *p, long size, int *lenp, int flags);
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
44 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name");
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
45
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
46 #ifdef FEAT_EVAL
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
47 static int readdirex_sort;
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
48 #endif
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
49
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
50 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
51 filemess(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
52 buf_T *buf,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
53 char_u *name,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
54 char_u *s,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
55 int attr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 int msg_scroll_save;
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
58 int prev_msg_col = msg_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 if (msg_silent != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 return;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
62 msg_add_fname(buf, name); // put file name in IObuff with quotes
21073
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
63
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
64 // If it's extremely long, truncate it.
21073
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
65 if (STRLEN(IObuff) > IOSIZE - 100)
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
66 IObuff[IOSIZE - 100] = NUL;
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
67
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
68 // Avoid an over-long translation to cause trouble.
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
69 STRNCAT(IObuff, s, 99);
334a8a5a6267 patch 8.2.1088: a very long translation might cause a buffer overflow
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
70
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 * For the first message may have to start a new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 * For further ones overwrite the previous one, reset msg_scroll before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 * calling filemess().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 msg_scroll_save = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 msg_scroll = FALSE;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
79 if (!msg_scroll) // wait a bit when overwriting an error msg
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 check_for_delay(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 msg_start();
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
82 if (prev_msg_col != 0 && msg_col == 0)
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
83 msg_putchar('\r'); // overwrite any previous message.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 msg_scroll = msg_scroll_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 msg_scrolled_ign = TRUE;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
86 // may truncate the message to avoid a hit-return prompt
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 msg_scrolled_ign = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 * Read lines from file "fname" into the buffer after line "from".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 * 1. We allocate blocks with lalloc, as big as possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 * 2. Each block is filled with characters from the file with a single read().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 * 3. The lines are inserted in the buffer with ml_append().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 * (caller must check that fname != NULL, unless READ_STDIN is used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 * "lines_to_skip" is the number of lines that must be skipped
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 * "lines_to_read" is the number of lines that are appended
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * When not recovering lines_to_skip is 0 and lines_to_read MAXLNUM.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 * flags:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 * READ_NEW starting to edit a new buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 * READ_FILTER reading filter output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 * READ_STDIN read from stdin instead of a file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 * READ_BUFFER read from curbuf instead of a file (converting after reading
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 * stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 * READ_DUMMY read into a dummy buffer (to check if file contents changed)
2394
a3aca345aafa Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents: 2360
diff changeset
113 * READ_KEEP_UNDO don't clear undo info or read it from a file
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
114 * READ_FIFO read from fifo/socket instead of a file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 *
10575
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
116 * return FAIL for failure, NOTDONE for directory (failure), or OK
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
119 readfile(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
120 char_u *fname,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
121 char_u *sfname,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
122 linenr_T from,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
123 linenr_T lines_to_skip,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
124 linenr_T lines_to_read,
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
125 exarg_T *eap, // can be NULL!
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
126 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 int fd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 int newfile = (flags & READ_NEW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 int check_readonly;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 int filtering = (flags & READ_FILTER);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 int read_stdin = (flags & READ_STDIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 int read_buffer = (flags & READ_BUFFER);
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
134 int read_fifo = (flags & READ_FIFO);
1486
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
135 int set_options = newfile || read_buffer
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
136 || (eap != NULL && eap->read_edit);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
137 linenr_T read_buf_lnum = 1; // next line to read from curbuf
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
138 colnr_T read_buf_col = 0; // next char to read from this line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 char_u c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 linenr_T lnum = from;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
141 char_u *ptr = NULL; // pointer into read buffer
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
142 char_u *buffer = NULL; // read buffer
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
143 char_u *new_buffer = NULL; // init to shut up gcc
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
144 char_u *line_start = NULL; // init to shut up gcc
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
145 int wasempty; // buffer was empty before reading
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 long size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 char_u *p;
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
149 off_T filesize = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 int skip_read = FALSE;
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
151 off_T filesize_disk = 0; // file size read from disk
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
152 off_T filesize_count = 0; // counter
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 #ifdef FEAT_CRYPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 char_u *cryptkey = NULL;
2204
c493d6bfde09 A few more changes for encryption. Add test that encrypted file can be read.
Bram Moolenaar <bram@vim.org>
parents: 2180
diff changeset
155 int did_ask_for_key = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 #endif
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
157 #ifdef FEAT_PERSISTENT_UNDO
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
158 context_sha256_T sha_ctx;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
159 int read_undo_file = FALSE;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
160 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
161 int split = 0; // number of split lines
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
162 #define UNKNOWN 0x0fffffff // file size is unknown
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 linenr_T linecnt;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
164 int error = FALSE; // errors encountered
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
165 int ff_error = EOL_UNKNOWN; // file format with errors
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
166 long linerest = 0; // remaining chars in line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 int perm = 0;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
169 int swap_mode = -1; // protection bits for swap file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 int perm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
173 int fileformat = 0; // end-of-line format
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 int keep_fileformat = FALSE;
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
175 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 int file_readonly;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 linenr_T skip_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 linenr_T read_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 int msg_save = msg_scroll;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
180 linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
181 // last read was missing the eol
10668
6a252c6afd5b patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents: 10575
diff changeset
182 int try_mac;
6a252c6afd5b patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents: 10575
diff changeset
183 int try_dos;
6a252c6afd5b patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents: 10575
diff changeset
184 int try_unix;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 int file_rewind = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 int can_retry;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
187 linenr_T conv_error = 0; // line nr with conversion error
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
188 linenr_T illegal_byte = 0; // line nr with illegal byte
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
189 int keep_dest_enc = FALSE; // don't retry when char doesn't fit
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
190 // in destination encoding
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
191 int bad_char_behavior = BAD_REPLACE;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
192 // BAD_KEEP, BAD_DROP or character to
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
193 // replace with
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
194 char_u *tmpname = NULL; // name of 'charconvert' output file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 int fio_flags = 0;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
196 char_u *fenc; // fileencoding to use
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
197 int fenc_alloced; // fenc_next is in allocated memory
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
198 char_u *fenc_next = NULL; // next item in 'fencs' or NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 int advance_fenc = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 long real_size = 0;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
201 #ifdef USE_ICONV
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
202 iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
203 # ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
204 int did_iconv = FALSE; // TRUE when iconv() failed and trying
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
205 // 'charconvert' next
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 # endif
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
207 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
208 int converted = FALSE; // TRUE if conversion done
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
209 int notconverted = FALSE; // TRUE if conversion wanted but it
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
210 // wasn't possible
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 char_u conv_rest[CONV_RESTLEN];
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
212 int conv_restlen = 0; // nr of bytes in conv_rest[]
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
213 pos_T orig_start;
2563
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
214 buf_T *old_curbuf;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
215 char_u *old_b_ffname;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
216 char_u *old_b_fname;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
217 int using_b_ffname;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
218 int using_b_fname;
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
219 static char *msg_is_a_directory = N_("is a directory");
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
220 int eof;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
221
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
222 au_did_filetype = FALSE; // reset before triggering any autocommands
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
223
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
224 curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 * If there is no file name yet, use the one for the read file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 * BF_NOTEDITED is set to reflect this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 * Don't do this for a read from a filter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 * Only do this when 'cpoptions' contains the 'f' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 if (curbuf->b_ffname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 && !filtering
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 && fname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 && vim_strchr(p_cpo, CPO_FNAMER) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 && !(flags & READ_DUMMY))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 {
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
238 if (set_rw_fname(fname, sfname) == FAIL)
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
239 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
242 // Remember the initial values of curbuf, curbuf->b_ffname and
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
243 // curbuf->b_fname to detect whether they are altered as a result of
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
244 // executing nasty autocommands. Also check if "fname" and "sfname"
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
245 // point to one of these values.
2563
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
246 old_curbuf = curbuf;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
247 old_b_ffname = curbuf->b_ffname;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
248 old_b_fname = curbuf->b_fname;
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
249 using_b_ffname = (fname == curbuf->b_ffname)
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
250 || (sfname == curbuf->b_ffname);
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
251 using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname);
5769dc787ec5 Fix: in compatible mode, in an empty buffer, ":r file" triggered an error
Bram Moolenaar <bram@vim.org>
parents: 2523
diff changeset
252
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
253 // After reading a file the cursor line changes but we don't want to
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
254 // display the line.
167
c93c9cad9618 updated for version 7.0051
vimboss
parents: 164
diff changeset
255 ex_no_reprint = TRUE;
c93c9cad9618 updated for version 7.0051
vimboss
parents: 164
diff changeset
256
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
257 // don't display the file info for another buffer now
968
994ea4e6f023 updated for version 7.0-094
vimboss
parents: 946
diff changeset
258 need_fileinfo = FALSE;
994ea4e6f023 updated for version 7.0-094
vimboss
parents: 946
diff changeset
259
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 * For Unix: Use the short file name whenever possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 * Avoids problems with networks and when directory names are changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 * Don't do this for MS-DOS, a "cd" in a sub-shell may have moved us to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 * another directory, which we don't detect.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (sfname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 sfname = fname;
9536
b2aada04d84e commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents: 9509
diff changeset
268 #if defined(UNIX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 fname = sfname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 * The BufReadCmd and FileReadCmd events intercept the reading process by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 * executing the associated commands instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 if (!filtering && !read_stdin && !read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 {
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
278 orig_start = curbuf->b_op_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
280 // Set '[ mark to the line above where the lines go (line 1 if zero).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 curbuf->b_op_start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 if (newfile)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 FALSE, curbuf, eap))
19836
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
288 {
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
289 int status = OK;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 #ifdef FEAT_EVAL
19836
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
291 if (aborting())
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
292 status = FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 #endif
19836
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
294 // The BufReadCmd code usually uses ":read" to get the text and
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
295 // perhaps ":file" to change the buffer name. But we should
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
296 // consider this to work like ":edit", thus reset the
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
297 // BF_NOTEDITED flag. Then ":write" will work to overwrite the
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
298 // same file.
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
299 if (status == OK)
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
300 curbuf->b_flags &= ~BF_NOTEDITED;
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
301 return status;
c32b295af9c5 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd
Bram Moolenaar <Bram@vim.org>
parents: 19526
diff changeset
302 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 FALSE, NULL, eap))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 return aborting() ? FAIL : OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
312 curbuf->b_op_start = orig_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
316 msg_scroll = FALSE; // overwrite previous file message
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 else
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
318 msg_scroll = TRUE; // don't overwrite previous file message
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
23
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
320 if (fname != NULL && *fname != NUL)
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
321 {
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
322 size_t namelen = STRLEN(fname);
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
323
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
324 // If the name is too long we might crash further on, quit here.
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
325 if (namelen >= MAXPATHL)
23
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
326 {
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
327 filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0);
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
328 msg_end();
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
329 msg_scroll = msg_save;
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
330 return FAIL;
3f44e9abe4ec updated for version 7.0015
vimboss
parents: 22
diff changeset
331 }
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
332
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
333 // If the name ends in a path separator, we can't open it. Check here,
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
334 // because reading the file may actually work, but then creating the
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
335 // swap file may destroy it! Reported on MS-DOS and Win 95.
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
336 if (after_pathsep(fname, fname + namelen))
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
337 {
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
338 filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
339 msg_end();
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
340 msg_scroll = msg_save;
25838
15fe946b1a41 patch 8.2.3453: autocmd not executed when editing a directory
Bram Moolenaar <Bram@vim.org>
parents: 25421
diff changeset
341 return NOTDONE;
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
342 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
345 if (!read_stdin && !read_buffer && !read_fifo)
5322
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
346 {
23503
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
347 #if defined(UNIX) || defined(VMS)
5322
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
348 /*
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
349 * On Unix it is possible to read a directory, so we have to
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
350 * check for it before the mch_open().
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
351 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 perm = mch_getperm(fname);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
353 if (perm >= 0 && !S_ISREG(perm) // not a regular file ...
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
354 && !S_ISFIFO(perm) // ... or fifo
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
355 && !S_ISSOCK(perm) // ... or socket
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
356 # ifdef OPEN_CHR_FILES
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
357 && !(S_ISCHR(perm) && is_dev_fd_file(fname))
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
358 // ... or a character special file named /dev/fd/<n>
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
359 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 {
10575
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
362 int retval = FAIL;
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
363
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 if (S_ISDIR(perm))
10575
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
365 {
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
366 filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
10575
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
367 retval = NOTDONE;
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
368 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 msg_scroll = msg_save;
10575
01a5f64a7a20 patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents: 10221
diff changeset
373 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 }
5322
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
375 #endif
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
376 #if defined(MSWIN)
1006
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
377 /*
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
378 * MS-Windows allows opening a device, but we will probably get stuck
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
379 * trying to read it.
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
380 */
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
381 if (!p_odev && mch_nodetype(fname) == NODE_WRITABLE)
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
382 {
1303
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
383 filemess(curbuf, fname, (char_u *)_("is a device (disabled with 'opendevice' option)"), 0);
1006
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
384 msg_end();
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
385 msg_scroll = msg_save;
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
386 return FAIL;
992d5c69d5e9 updated for version 7.0-132
vimboss
parents: 1004
diff changeset
387 }
5322
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
388 #endif
9801d06e7b4c updated for version 7.4.014
Bram Moolenaar <bram@vim.org>
parents: 5312
diff changeset
389 }
1004
09d0e83c29b8 updated for version 7.0-130
vimboss
parents: 978
diff changeset
390
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
391 // Set default or forced 'fileformat' and 'binary'.
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
392 set_file_options(set_options, eap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 * When opening a new file we take the readonly flag from the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 * Default is r/w, can be set to r/o below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 * Don't reset it when in readonly mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 * Only set/reset b_p_ro when BF_CHECK_RO is set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 check_readonly = (newfile && (curbuf->b_flags & BF_CHECK_RO));
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
401 if (check_readonly && !readonlymode)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 curbuf->b_p_ro = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
404 if (newfile && !read_stdin && !read_buffer && !read_fifo)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
406 // Remember time of file.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 if (mch_stat((char *)fname, &st) >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 buf_store_time(curbuf, &st, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 curbuf->b_mtime_read = curbuf->b_mtime;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
411 curbuf->b_mtime_read_ns = curbuf->b_mtime_ns;
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
412 filesize_disk = st.st_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 * Use the protection bits of the original file for the swap file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 * This makes it possible for others to read the name of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 * edited file from the swapfile, but only if they can read the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 * edited file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 * Remove the "write" and "execute" bits for group and others
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 * (they must not write the swapfile).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 * Add the "read" and "write" bits for the user, otherwise we may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 * not be able to write to the file ourselves.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 * Setting the bits is done below, after creating the swap file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 swap_mode = (st.st_mode & 0644) | 0600;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 curbuf->b_fab_rfm = st.st_fab_rfm;
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 18
diff changeset
429 curbuf->b_fab_rat = st.st_fab_rat;
cc049b00ee70 updated for version 7.0014
vimboss
parents: 18
diff changeset
430 curbuf->b_fab_mrs = st.st_fab_mrs;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 curbuf->b_mtime = 0;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
436 curbuf->b_mtime_ns = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 curbuf->b_mtime_read = 0;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
438 curbuf->b_mtime_read_ns = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 curbuf->b_orig_size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 curbuf->b_orig_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
443 // 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
444 // file doesn't exist.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 curbuf->b_flags &= ~(BF_NEW | BF_NEW_W);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 * 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
450 * for Amiga: check readonly by trying to open the file for writing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 file_readonly = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if (read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 {
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
455 #if defined(MSWIN)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
456 // Force binary I/O on stdin to avoid CR-LF -> LF conversion.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 setmode(0, O_BINARY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 else if (!read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 #ifdef USE_MCH_ACCESS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 !(perm & 0222) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 mch_access((char *)fname, W_OK))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 file_readonly = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 if (!newfile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 || readonlymode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 file_readonly = TRUE;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
476 // try to open ro
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
482 if (fd < 0) // cannot open at all
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 #ifndef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 int isdir_f;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 msg_scroll = msg_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 #ifndef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 /*
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
490 * On Amiga we can't open a directory, check here.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 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
493 perm = mch_getperm(fname); // check if the file exists
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 if (isdir_f)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
22490
23a5977d7211 patch 8.2.1793: not consistently giving the "is a directory" warning
Bram Moolenaar <Bram@vim.org>
parents: 22041
diff changeset
496 filemess(curbuf, sfname, (char_u *)_(msg_is_a_directory), 0);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
497 curbuf->b_p_ro = TRUE; // must use "w!" now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 if (newfile)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 {
2147
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
503 if (perm < 0
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
504 #ifdef ENOENT
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
505 && errno == ENOENT
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
506 #endif
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
507 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 * Set the 'new-file' flag, so that when the file has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 * been created by someone else, a ":w" will complain.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 curbuf->b_flags |= BF_NEW;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
515 // 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
516 // 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
517 // "nofile" or "nowrite" buffer type.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 if (!bt_dontwrite(curbuf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 #endif
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
521 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 check_need_swap(newfile);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
523 // SwapExists autocommand may mess things up
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
524 if (curbuf != old_curbuf
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
525 || (using_b_ffname
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
526 && (old_b_ffname != curbuf->b_ffname))
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
527 || (using_b_fname
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
528 && (old_b_fname != curbuf->b_fname)))
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
529 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
530 emsg(_(e_auchangedbuf));
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
531 return FAIL;
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
532 }
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
533 }
592
6a91f35b354d updated for version 7.0168
vimboss
parents: 589
diff changeset
534 if (dir_of_file_exists(fname))
20828
db18625d8134 patch 8.2.0966: 'shortmess' flag "n" not used in two places
Bram Moolenaar <Bram@vim.org>
parents: 20790
diff changeset
535 filemess(curbuf, sfname,
db18625d8134 patch 8.2.0966: 'shortmess' flag "n" not used in two places
Bram Moolenaar <Bram@vim.org>
parents: 20790
diff changeset
536 (char_u *)new_file_message(), 0);
592
6a91f35b354d updated for version 7.0168
vimboss
parents: 589
diff changeset
537 else
6a91f35b354d updated for version 7.0168
vimboss
parents: 589
diff changeset
538 filemess(curbuf, sfname,
6a91f35b354d updated for version 7.0168
vimboss
parents: 589
diff changeset
539 (char_u *)_("[New DIRECTORY]"), 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 #ifdef FEAT_VIMINFO
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
541 // 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
542 // edited before and deleted. Get the old marks.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 check_marks_read();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
545 // Set forced 'fileencoding'.
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
546 if (eap != NULL)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
547 set_forced_fenc(eap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 FALSE, curbuf, eap);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
550 // remember the current fileformat
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 save_file_ff(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
553 #if defined(FEAT_EVAL)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
554 if (aborting()) // autocmds may abort script processing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
557 return OK; // a new file is not an error
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 {
550
74c2ea3c3081 updated for version 7.0156
vimboss
parents: 540
diff changeset
561 filemess(curbuf, sfname, (char_u *)(
74c2ea3c3081 updated for version 7.0156
vimboss
parents: 540
diff changeset
562 # ifdef EFBIG
74c2ea3c3081 updated for version 7.0156
vimboss
parents: 540
diff changeset
563 (errno == EFBIG) ? _("[File too big]") :
74c2ea3c3081 updated for version 7.0156
vimboss
parents: 540
diff changeset
564 # endif
2147
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
565 # ifdef EOVERFLOW
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
566 (errno == EOVERFLOW) ? _("[File too big]") :
2bd29808d1f6 updated for version 7.2.429
Bram Moolenaar <bram@zimbu.org>
parents: 2095
diff changeset
567 # endif
550
74c2ea3c3081 updated for version 7.0156
vimboss
parents: 540
diff changeset
568 _("[Permission Denied]")), 0);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
569 curbuf->b_p_ro = TRUE; // must use "w!" now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 * Only set the 'ro' flag for readonly files the first time they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 * loaded. Help files always get readonly mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 if ((check_readonly && file_readonly) || curbuf->b_help)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 curbuf->b_p_ro = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
583 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
585 // 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
586 // correctly set when reading stdin.
1486
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
587 if (!read_buffer)
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
588 {
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
589 curbuf->b_p_eol = TRUE;
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
590 curbuf->b_start_eol = TRUE;
1f93fbcb4e0c updated for version 7.1-201
vimboss
parents: 1471
diff changeset
591 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 curbuf->b_p_bomb = FALSE;
1352
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
593 curbuf->b_start_bomb = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
596 // 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
597 // editing this file.
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
598 // Don't do this for a "nofile" or "nowrite" buffer type.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 if (!bt_dontwrite(curbuf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 check_need_swap(newfile);
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
604 if (!read_stdin && (curbuf != old_curbuf
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
605 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
606 || (using_b_fname && (old_b_fname != curbuf->b_fname))))
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
607 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
608 emsg(_(e_auchangedbuf));
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
609 if (!read_buffer)
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
610 close(fd);
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
611 return FAIL;
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
612 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 #ifdef UNIX
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
614 // Set swap file protection bits after creating it.
1918
eac2556d4620 updated for version 7.2-215
vimboss
parents: 1913
diff changeset
615 if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL
eac2556d4620 updated for version 7.2-215
vimboss
parents: 1913
diff changeset
616 && 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
617 {
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
618 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
619
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
620 /*
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
621 * 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
622 * 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
623 * 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
624 * 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
625 * 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
626 */
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
627 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
628 {
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
629 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
630
8984342ab09e patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
631 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
632 && 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
633 # 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
634 && 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
635 == -1
13730
7b818f7bb738 patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents: 13610
diff changeset
636 # endif
7b818f7bb738 patch 8.0.1737: fchown() used when it is not supported
Christian Brabandt <cb@256bit.org>
parents: 13610
diff changeset
637 )
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
638 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
639 }
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
640
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
641 (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
642 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645
16453
4e9bea9b8025 patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents: 16451
diff changeset
646 // If "Quit" selected at ATTENTION dialog, don't load the file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 if (swap_exists_action == SEA_QUIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 if (!read_buffer && !read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 close(fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
654 ++no_wait_return; // don't wait for return yet
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 * Set '[ mark to the line above where the lines go (line 1 if zero).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 */
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
659 orig_start = curbuf->b_op_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 curbuf->b_op_start.lnum = ((from == 0) ? 1 : from);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 curbuf->b_op_start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662
10668
6a252c6afd5b patch 8.0.0224: change to 'fileformats' from autocmd does not take effect
Christian Brabandt <cb@256bit.org>
parents: 10575
diff changeset
663 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
664 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
665 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
666
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 if (!read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 int m = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 int n = msg_scrolled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 * The file must be closed again, the autocommands may want to change
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 * the file before reading it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 if (!read_stdin)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
677 close(fd); // ignore errors
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 * The output from the autocommands should not overwrite anything and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 * should not be overwritten: Set msg_scroll, restore its value if no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 * output was done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 msg_scroll = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 if (filtering)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 FALSE, curbuf, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 else if (read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 FALSE, curbuf, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 else if (newfile)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 FALSE, curbuf, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 FALSE, NULL, eap);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
697 // 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
698 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
699 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
700 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
701 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
702
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 if (msg_scrolled == n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 msg_scroll = m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 #ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
707 if (aborting()) // autocmds may abort script processing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 msg_scroll = msg_save;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
711 curbuf->b_p_ro = TRUE; // must use "w!" now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 * Don't allow the autocommands to change the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 * Try to re-open the file.
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
718 *
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
719 * Don't allow the autocommands to change the buffer name either
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
720 * (cd for example) if it invalidates fname or sfname.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 if (!read_stdin && (curbuf != old_curbuf
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
723 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
724 || (using_b_fname && (old_b_fname != curbuf->b_fname))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 || (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 msg_scroll = msg_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 if (fd < 0)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
730 emsg(_("E200: *ReadPre autocommands made the file unreadable"));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
732 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
733 curbuf->b_p_ro = TRUE; // must use "w!" now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
738 // Autocommands may add lines to the file, need to check if it is empty
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 if (!recoverymode && !filtering && !(flags & READ_DUMMY))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 * Show the user that we are busy reading the input. Sometimes this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 * may take a while. When reading from stdin another program may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 * still be running, don't move the cursor to the last line, unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 * always using the GUI.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 if (read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 {
12863
e7ec107f6354 patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents: 12861
diff changeset
751 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
752 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 #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
754 # 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
755 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
756 # 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
757 mch_msg(_("Vim: Reading from stdin...\n"));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 #ifdef FEAT_GUI
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
760 // 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
761 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
762 {
e7ec107f6354 patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents: 12861
diff changeset
763 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
764 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
765 }
e7ec107f6354 patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents: 12861
diff changeset
766 #endif
e7ec107f6354 patch 8.0.1308: the "Reading from stdin" message may be undesired
Christian Brabandt <cb@256bit.org>
parents: 12861
diff changeset
767 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 else if (!read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 filemess(curbuf, sfname, (char_u *)"", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
773 msg_scroll = FALSE; // overwrite the file message
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 * Set linecnt now, before the "retry" caused by a wrong guess for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 * fileformat, and after the autocommands, which may change them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 linecnt = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
781 // "++bad=" argument.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
782 if (eap != NULL && eap->bad_char != 0)
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
783 {
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
784 bad_char_behavior = eap->bad_char;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
785 if (set_options)
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
786 curbuf->b_bad_char = eap->bad_char;
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
787 }
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
788 else
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
789 curbuf->b_bad_char = 0;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
790
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 /*
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
792 * Decide which 'encoding' to use or use first.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 if (eap != NULL && eap->force_enc != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 fenc = enc_canonize(eap->cmd + eap->force_enc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 fenc_alloced = TRUE;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
798 keep_dest_enc = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 else if (curbuf->b_p_bin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
802 fenc = (char_u *)""; // binary: don't convert
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 else if (curbuf->b_help)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 char_u firstline[80];
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
808 int fc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
810 // 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
811 // fails it must be latin1.
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
812 // 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
813 // 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
814 // 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
815 // That is only in *.??x files.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 fenc = (char_u *)"latin1";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 c = enc_utf8;
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
818 if (!c && !read_stdin)
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
819 {
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
820 fc = fname[STRLEN(fname) - 1];
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
821 if (TOLOWER_ASC(fc) == 'x')
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
822 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
823 // 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
824 // the start of the file. If the read() fails "len" is -1.
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
825 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
826 vim_lseek(fd, (off_T)0L, SEEK_SET);
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
827 for (p = firstline; p < firstline + len; ++p)
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
828 if (*p >= 0x80)
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
829 {
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
830 c = TRUE;
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
831 break;
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
832 }
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 297
diff changeset
833 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 if (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 fenc_next = fenc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 fenc = (char_u *)"utf-8";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
841 // 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
842 // '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
843 // doesn't make sense.
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 837
diff changeset
844 if (!enc_utf8)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 837
diff changeset
845 keep_dest_enc = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 else if (*p_fencs == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
851 fenc = curbuf->b_p_fenc; // use format from buffer
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
856 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
857 fenc = next_fenc(&fenc_next, &fenc_alloced);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 * Jump back here to retry reading the file in different ways.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 * Reasons to retry:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 * - encoding conversion failed: try another one from "fenc_next"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 * - BOM detected and fenc was set, need to setup conversion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 * - "fileformat" check failed: try another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 * Variables set for special retry actions:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 * "file_rewind" Rewind the file to start reading it again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 * "advance_fenc" Advance "fenc" using "fenc_next".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 * "skip_read" Re-use already read bytes (BOM detected).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 * "did_iconv" iconv() conversion failed, try 'charconvert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 * "keep_fileformat" Don't reset "fileformat".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 * Other status indicators:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 * "tmpname" When != NULL did conversion with 'charconvert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 * Output file has to be deleted afterwards.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 * "iconv_fd" When != -1 did conversion with iconv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 retry:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 if (file_rewind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 if (read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 read_buf_lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 read_buf_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 }
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
888 else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
890 // Can't rewind the file, give up.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 goto failed;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
894 // Delete the previously read lines.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 while (lnum > from)
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20311
diff changeset
896 ml_delete(lnum--);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 file_rewind = FALSE;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
898 if (set_options)
1352
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
899 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 curbuf->b_p_bomb = FALSE;
1352
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
901 curbuf->b_start_bomb = FALSE;
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
902 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
903 conv_error = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 * When retrying with another "fenc" and the first time "fileformat"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 * will be reset.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 if (keep_fileformat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 keep_fileformat = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 if (eap != NULL && eap->force_ff != 0)
1742
0e4fa55d20e0 updated for version 7.2-040
vimboss
parents: 1735
diff changeset
915 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 fileformat = get_fileformat_force(curbuf, eap);
1742
0e4fa55d20e0 updated for version 7.2-040
vimboss
parents: 1735
diff changeset
917 try_unix = try_dos = try_mac = FALSE;
0e4fa55d20e0 updated for version 7.2-040
vimboss
parents: 1735
diff changeset
918 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 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
920 fileformat = EOL_UNIX; // binary: use Unix format
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 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
922 fileformat = get_fileformat(curbuf);// use format from buffer
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 else
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
924 fileformat = EOL_UNKNOWN; // detect from file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
927 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 if (iconv_fd != (iconv_t)-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
930 // aborted conversion with iconv(), close the descriptor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 iconv_close(iconv_fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 iconv_fd = (iconv_t)-1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 }
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
934 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 if (advance_fenc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 * Try the next entry in 'fileencodings'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 advance_fenc = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 if (eap != NULL && eap->force_enc != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
945 // 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
946 // without conversion.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 notconverted = TRUE;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
948 conv_error = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 if (fenc_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 vim_free(fenc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 fenc = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 if (fenc_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 vim_free(fenc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 if (fenc_next != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 {
17692
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
960 fenc = next_fenc(&fenc_next, &fenc_alloced);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 fenc = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 if (tmpname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
970 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
971 VIM_CLEAR(tmpname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 /*
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
976 * Conversion may be required when the encoding of the file is different
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
977 * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 fio_flags = 0;
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
980 converted = need_conversion(fenc);
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
981 if (converted)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
984 // "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
985 // for a BOM.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 if (STRCMP(fenc, ENC_UCSBOM) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 fio_flags = FIO_UCSBOM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 * Check if UCS-2/4 or Latin1 to UTF-8 conversion needs to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 * done. This is handled below after read(). Prepare the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 * fio_flags to avoid having to parse the string each time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 * Also check for Unicode to Latin1 conversion, because iconv()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 * appears not to handle this correctly. This works just like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 * conversion to UTF-8 except how the resulting character is put in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 * the buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 else if (enc_utf8 || STRCMP(p_enc, "latin1") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 fio_flags = get_fio_flags(fenc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
1001 #ifdef MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 * Conversion from an MS-Windows codepage to UTF-8 or another codepage
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 * is handled with MultiByteToWideChar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 if (fio_flags == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 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
1008 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1009
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1010 #ifdef MACOS_CONVERT
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1011 // Conversion from Apple MacRoman to latin1 or UTF-8
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 if (fio_flags == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 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
1014 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1015
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1016 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 * Try using iconv() if we can't convert internally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 if (fio_flags == 0
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1021 # ifdef FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 && !did_iconv
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1023 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 iconv_fd = (iconv_t)my_iconv_open(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 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
1027 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1028
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1029 #ifdef FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 * Use the 'charconvert' expression when conversion is required
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 * and we can't do it internally or with iconv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 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
1035 && !read_fifo
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1036 # ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 && iconv_fd == (iconv_t)-1
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1038 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 {
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1041 # ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 did_iconv = FALSE;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1043 # endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1044 // 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
1045 // "fileformat").
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 if (tmpname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 tmpname = readfile_charconvert(fname, fenc, &fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 if (tmpname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1051 // Conversion failed. Try another one.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 advance_fenc = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 if (fd < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1055 // 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
1056 emsg(_("E202: Conversion made file unreadable!"));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 goto failed;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 goto retry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 else
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1065 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 if (fio_flags == 0
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1068 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 && iconv_fd == (iconv_t)-1
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1070 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1073 // 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
1074 // Try the next conversion in 'fileencodings'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 advance_fenc = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 goto retry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1081 // 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
1082 // 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
1083 // 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
1084 can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 if (!skip_read)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 linerest = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 filesize = 0;
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1090 filesize_count = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 skip_count = lines_to_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 read_count = lines_to_read;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 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
1094 #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
1095 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
1096 && 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
1097 && 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
1098 && !filtering
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
1099 && !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
1100 && !read_stdin
a3aca345aafa Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents: 2360
diff changeset
1101 && !read_buffer);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1102 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
1103 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
1104 #endif
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1105 #ifdef FEAT_CRYPT
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1106 if (curbuf->b_cryptstate != NULL)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1107 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1108 // 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
1109 // it again.
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1110 crypt_free_state(curbuf->b_cryptstate);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1111 curbuf->b_cryptstate = NULL;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1112 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1113 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 while (!error && !got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 * We allocate as much space for the file as we can get, plus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 * space for the old line plus room for one terminating NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 * 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
1122 * up to max_unsigned characters (and other things).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 */
13804
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1124 if (!skip_read)
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1125 {
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15595
diff changeset
1126 #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
1127 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
1128 #else
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1129 // 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
1130 // 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
1131 // 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
1132 size = 0x10000L + linerest;
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1133 if (size > 0x100000L)
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1134 size = 0x100000L;
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1135 #endif
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1136 }
8a35543f5f97 patch 8.0.1774: reading very long lines can be slow
Christian Brabandt <cb@256bit.org>
parents: 13762
diff changeset
1137
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1138 // 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
1139 if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 ++split;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1142 *ptr = NL; // split line by inserting a NL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 size = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 if (!skip_read)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 {
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
1149 for ( ; size >= 10; size = (long)((long_u)size >> 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 {
16768
695d9ef00b03 patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents: 16766
diff changeset
1151 if ((new_buffer = lalloc(size + linerest + 1,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 FALSE)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 if (new_buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 do_outofmem_msg((long_u)(size * 2 + linerest + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1161 if (linerest) // copy characters from the previous buffer
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 mch_memmove(new_buffer, ptr - linerest, (size_t)linerest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 buffer = new_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 ptr = buffer + linerest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 line_start = buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1168 // 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
1169 // 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
1170 // factor ICONV_MULT.
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1171 // 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
1172 // 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
1173 // 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
1174 // 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
1175 // multiple of 2
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1176 // 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
1177 // multiple of 4
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1178 real_size = (int)size;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1179 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 if (iconv_fd != (iconv_t)-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 size = size / ICONV_MULT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 else
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1183 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 if (fio_flags & FIO_LATIN1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 size = size / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 size = (size * 2 / 3) & ~1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 else if (fio_flags & FIO_UCS4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 size = (size * 2 / 3) & ~3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 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
1191 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
1192 #ifdef MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 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
1194 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
1195 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1196 #ifdef MACOS_CONVERT
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 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
1198 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
1199 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1200
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 if (conv_restlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1203 // Insert unconverted bytes from previous line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 mch_memmove(ptr, conv_rest, conv_restlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 ptr += conv_restlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 size -= conv_restlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 if (read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 * Read bytes from curbuf. Used for converting text read
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 * from stdin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 */
24990
85d1e82ed134 patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents: 24970
diff changeset
1215 eof = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 if (read_buf_lnum > from)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 int n, ni;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 long tlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 tlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 p = ml_get(read_buf_lnum) + read_buf_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 n = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 if ((int)tlen + n + 1 > size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1230 // 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
1231 // 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
1232 // below.
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1233 n = (int)(size - tlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 for (ni = 0; ni < n; ++ni)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 if (p[ni] == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 ptr[tlen++] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 ptr[tlen++] = p[ni];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 read_buf_col += n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1246 // 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
1247 // to NUL to reverse the effect done below.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 for (ni = 0; ni < n; ++ni)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 if (p[ni] == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 ptr[tlen++] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 ptr[tlen++] = p[ni];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 ptr[tlen++] = NL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 read_buf_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 if (++read_buf_lnum > from)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1259 // 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
1260 // end-of-line don't add it now either.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 if (!curbuf->b_p_eol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 --tlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 size = tlen;
24990
85d1e82ed134 patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents: 24970
diff changeset
1264 eof = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 * Read bytes from the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 */
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1276 # ifdef FEAT_SODIUM
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1277 // Let the crypt layer work with a buffer size of 8192
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1278 if (filesize == 0)
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1279 // set size to 8K + Sodium Crypt Metadata
24990
85d1e82ed134 patch 8.2.3032: build problems with MSVC, other crypt issues with libsodium
Bram Moolenaar <Bram@vim.org>
parents: 24970
diff changeset
1280 size = WRITEBUFSIZE + crypt_get_max_header_len()
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1281 + crypto_secretstream_xchacha20poly1305_HEADERBYTES
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1282 + crypto_secretstream_xchacha20poly1305_ABYTES;
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1283
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1284 else if (filesize > 0 && (curbuf->b_cryptstate != NULL &&
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1285 curbuf->b_cryptstate->method_nr == CRYPT_M_SOD))
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1286 size = WRITEBUFSIZE + crypto_secretstream_xchacha20poly1305_ABYTES;
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1287 # endif
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1288 eof = size;
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
1289 size = read_eintr(fd, ptr, size);
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1290 filesize_count += size;
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1291 // hit end of file
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1292 eof = (size < eof || filesize_count == filesize_disk);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1295 #ifdef FEAT_CRYPT
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1296 /*
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1297 * At start of file: Check for magic number of encryption.
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1298 */
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1299 if (filesize == 0 && size > 0)
25052
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1300 {
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1301 cryptkey = check_for_cryptkey(cryptkey, ptr, &size,
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1302 &filesize, newfile, sfname,
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1303 &did_ask_for_key);
25052
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1304 # ifdef CRYPT_NOT_INPLACE
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1305 if (curbuf->b_cryptstate != NULL
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1306 && !crypt_works_inplace(curbuf->b_cryptstate))
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1307 // reading undo file requires crypt_decode_inplace()
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1308 read_undo_file = FALSE;
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1309 # endif
965d97f8208b patch 8.2.3063: crash when switching 'cryptmethod' to xchaha20 with undo file
Bram Moolenaar <Bram@vim.org>
parents: 24990
diff changeset
1310 }
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1311 /*
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1312 * Decrypt the read bytes. This is done before checking for
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1313 * EOF because the crypt layer may be buffering.
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1314 */
12216
e971ef6c0dee patch 8.0.0988: warning from Covscan about using NULL pointer
Christian Brabandt <cb@256bit.org>
parents: 12064
diff changeset
1315 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
1316 && size > 0)
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1317 {
15531
959cf4c63b18 patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
1318 # ifdef CRYPT_NOT_INPLACE
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1319 if (crypt_works_inplace(curbuf->b_cryptstate))
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1320 {
15531
959cf4c63b18 patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
1321 # endif
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1322 crypt_decode_inplace(curbuf->b_cryptstate, ptr,
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1323 size, eof);
15531
959cf4c63b18 patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
1324 # ifdef CRYPT_NOT_INPLACE
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1325 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1326 else
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1327 {
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1328 char_u *newptr = NULL;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1329 int decrypted_size;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1330
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1331 decrypted_size = crypt_decode_alloc(
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1332 curbuf->b_cryptstate, ptr, size,
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1333 &newptr, eof);
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1334
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1335 if (decrypted_size < 0)
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1336 {
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1337 // error message already given
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1338 error = TRUE;
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1339 vim_free(newptr);
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1340 break;
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1341 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1342 // 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
1343 // 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
1344 if (decrypted_size == 0)
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1345 continue;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1346
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1347 if (linerest == 0)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1348 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1349 // 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
1350 // NULL, checked later).
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1351 new_buffer = newptr;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1352 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1353 else
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1354 {
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1355 long_u new_size;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1356
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1357 // Need new buffer to add bytes carried over.
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1358 new_size = (long_u)(decrypted_size + linerest + 1);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1359 new_buffer = lalloc(new_size, FALSE);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1360 if (new_buffer == NULL)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1361 {
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1362 do_outofmem_msg(new_size);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1363 error = TRUE;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1364 break;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1365 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1366
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1367 mch_memmove(new_buffer, buffer, linerest);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1368 if (newptr != NULL)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1369 mch_memmove(new_buffer + linerest, newptr,
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1370 decrypted_size);
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1371 vim_free(newptr);
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1372 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1373
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1374 if (new_buffer != NULL)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1375 {
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1376 vim_free(buffer);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1377 buffer = new_buffer;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1378 new_buffer = NULL;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1379 line_start = buffer;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1380 ptr = buffer + linerest;
24970
7e9e53a0368f patch 8.2.3022: available encryption methods are not strong enough
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1381 real_size = size;
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1382 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1383 size = decrypted_size;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1384 }
15531
959cf4c63b18 patch 8.1.0773: not all crypt code is tested
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
1385 # endif
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1386 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1387 #endif
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1388
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 if (size <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1391 if (size < 0) // read error
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 else if (conv_restlen > 0)
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1394 {
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1395 /*
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1396 * Reached end-of-file but some trailing bytes could
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1397 * not be converted. Truncated file?
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1398 */
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1399
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1400 // When we did a conversion report an error.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1401 if (fio_flags != 0
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1402 #ifdef USE_ICONV
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1403 || iconv_fd != (iconv_t)-1
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1404 #endif
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1405 )
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1406 {
4331
d8053e6bf72a updated for version 7.3.915
Bram Moolenaar <bram@vim.org>
parents: 4287
diff changeset
1407 if (can_retry)
d8053e6bf72a updated for version 7.3.915
Bram Moolenaar <bram@vim.org>
parents: 4287
diff changeset
1408 goto rewind_retry;
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1409 if (conv_error == 0)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1410 conv_error = curbuf->b_ml.ml_line_count
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1411 - linecnt + 1;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1412 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1413 // Remember the first linenr with an illegal byte
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1414 else if (illegal_byte == 0)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1415 illegal_byte = curbuf->b_ml.ml_line_count
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1416 - linecnt + 1;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1417 if (bad_char_behavior == BAD_DROP)
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1418 {
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1419 *(ptr - conv_restlen) = NUL;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1420 conv_restlen = 0;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1421 }
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1422 else
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1423 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1424 // 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
1425 // 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
1426 // 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
1427 // works slightly differently.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1428 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
1429 #ifdef USE_ICONV
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1430 || iconv_fd != (iconv_t)-1
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1431 #endif
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1432 ))
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1433 {
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1434 while (conv_restlen > 0)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1435 {
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1436 *(--ptr) = bad_char_behavior;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1437 --conv_restlen;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1438 }
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1439 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1440 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
1441 #ifdef USE_ICONV
834
5117153003bd updated for version 7.0e
vimboss
parents: 822
diff changeset
1442 if (iconv_fd != (iconv_t)-1)
5117153003bd updated for version 7.0e
vimboss
parents: 822
diff changeset
1443 {
5117153003bd updated for version 7.0e
vimboss
parents: 822
diff changeset
1444 iconv_close(iconv_fd);
5117153003bd updated for version 7.0e
vimboss
parents: 822
diff changeset
1445 iconv_fd = (iconv_t)-1;
5117153003bd updated for version 7.0e
vimboss
parents: 822
diff changeset
1446 }
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1447 #endif
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1448 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1449 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 skip_read = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 * At start of file (or after crypt magic number): Check for BOM.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 * Also check for a BOM for other Unicode encodings, but not after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 * converting with 'charconvert' or when a BOM has already been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 * found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 if ((filesize == 0
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1461 #ifdef FEAT_CRYPT
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1462 || (cryptkey != NULL
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1463 && filesize == crypt_get_header_len(
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
1464 crypt_get_method_nr(curbuf)))
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1465 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 && (fio_flags == FIO_UCSBOM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 || (!curbuf->b_p_bomb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 && tmpname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 && (*fenc == 'u' || (*fenc == NUL && enc_utf8)))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 char_u *ccname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 int blen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1475 // no BOM detection in a short file or in binary mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 if (size < 2 || curbuf->b_p_bin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 ccname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 ccname = check_for_bom(ptr, size, &blen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 if (ccname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1483 // Remove BOM from the text
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 filesize += blen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 size -= blen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 mch_memmove(ptr, ptr + blen, (size_t)size);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
1487 if (set_options)
1352
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
1488 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 curbuf->b_p_bomb = TRUE;
1352
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
1490 curbuf->b_start_bomb = TRUE;
c544a3507e83 updated for version 7.1-066
vimboss
parents: 1313
diff changeset
1491 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 if (fio_flags == FIO_UCSBOM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 if (ccname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1498 // No BOM detected: retry with next encoding.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 advance_fenc = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1503 // BOM detected: set "fenc" and jump back
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 if (fenc_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 vim_free(fenc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 fenc = ccname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 fenc_alloced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1509 // retry reading without getting new bytes or rewinding
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 skip_read = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 goto retry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 }
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1514
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1515 // Include not converted bytes.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1516 ptr -= conv_restlen;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1517 size += conv_restlen;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1518 conv_restlen = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 * Break here for a read error or end-of-file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 if (size <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1525
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1526 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 if (iconv_fd != (iconv_t)-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 * Attempt conversion of the read bytes to 'encoding' using
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 * iconv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 const char *fromp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 char *top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 size_t from_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 size_t to_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 fromp = (char *)ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 from_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 ptr += size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 top = (char *)ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 to_size = real_size - size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 * If there is conversion error or not enough room try using
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
1546 * another conversion. Except for when there is no
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
1547 * alternative (help files).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 */
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1549 while ((iconv(iconv_fd, (void *)&fromp, &from_size,
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1550 &top, &to_size)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 || from_size > CONV_RESTLEN)
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1553 {
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1554 if (can_retry)
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 355
diff changeset
1555 goto rewind_retry;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1556 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1557 conv_error = readfile_linenr(linecnt,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1558 ptr, (char_u *)top);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1559
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1560 // Deal with a bad byte and continue with the next.
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1561 ++fromp;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1562 --from_size;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1563 if (bad_char_behavior == BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1564 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1565 *top++ = *(fromp - 1);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1566 --to_size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1567 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1568 else if (bad_char_behavior != BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1569 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1570 *top++ = bad_char_behavior;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1571 --to_size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1572 }
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1573 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 if (from_size > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1577 // 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
1578 // round.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 mch_memmove(conv_rest, (char_u *)fromp, from_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 conv_restlen = (int)from_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1583 // move the linerest to before the converted characters
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 line_start = ptr - linerest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 mch_memmove(line_start, buffer, (size_t)linerest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 size = (long)((char_u *)top - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 }
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1588 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1589
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
1590 #ifdef MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 if (fio_flags & FIO_CODEPAGE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 {
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1593 char_u *src, *dst;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1594 WCHAR ucs2buf[3];
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1595 int ucs2len;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1596 int codepage = FIO_GET_CP(fio_flags);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1597 int bytelen;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1598 int found_bad;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1599 char replstr[2];
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1600
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 * Conversion from an MS-Windows codepage or UTF-8 to UTF-8 or
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1603 * a codepage, using standard MS-Windows functions. This
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1604 * requires two steps:
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1605 * 1. convert from 'fileencoding' to ucs-2
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1606 * 2. convert from ucs-2 to 'encoding'
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1607 *
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1608 * Because there may be illegal bytes AND an incomplete byte
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1609 * sequence at the end, we may have to do the conversion one
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1610 * character at a time to get it right.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 */
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1612
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1613 // Replacement string for WideCharToMultiByte().
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1614 if (bad_char_behavior > 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1615 replstr[0] = bad_char_behavior;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1616 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1617 replstr[0] = '?';
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1618 replstr[1] = NUL;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1619
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1620 /*
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1621 * Move the bytes to the end of the buffer, so that we have
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1622 * room to put the result at the start.
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1623 */
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1624 src = ptr + real_size - size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1625 mch_memmove(src, ptr, size);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 /*
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1628 * Do the conversion.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 */
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1630 dst = ptr;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1631 size = size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1632 while (size > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 {
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1634 found_bad = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1636 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1637 if (codepage == CP_UTF8)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1639 // 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
1640 // trailing bytes properly.
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1641 // Get one UTF-8 character from src.
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1642 bytelen = (int)utf_ptr2len_len(src, size);
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1643 if (bytelen > size)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1644 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1645 // 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
1646 // 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
1647 // deal with it as if they were illegal bytes.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1648 if (bytelen <= CONV_RESTLEN)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1649 break;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1650
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1651 // weird overlong byte sequence
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1652 bytelen = size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1653 found_bad = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1654 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1655 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1656 {
799
6beb2c667935 updated for version 7.0b
vimboss
parents: 788
diff changeset
1657 int u8c = utf_ptr2char(src);
6beb2c667935 updated for version 7.0b
vimboss
parents: 788
diff changeset
1658
622
4096208d2a50 updated for version 7.0178
vimboss
parents: 617
diff changeset
1659 if (u8c > 0xffff || (*src >= 0x80 && bytelen == 1))
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1660 found_bad = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1661 ucs2buf[0] = u8c;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1662 ucs2len = 1;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1663 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1665 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 # endif
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1667 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1668 // 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
1669 // from one to three bytes.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1670 for (bytelen = 1; bytelen <= size && bytelen <= 3;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1671 ++bytelen)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1672 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1673 ucs2len = MultiByteToWideChar(codepage,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1674 MB_ERR_INVALID_CHARS,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1675 (LPCSTR)src, bytelen,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1676 ucs2buf, 3);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1677 if (ucs2len > 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1678 break;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1679 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1680 if (ucs2len == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1681 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1682 // 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
1683 // incomplete byte sequence. Otherwise discard
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1684 // one byte as a bad character.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1685 if (size == 1)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1686 break;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1687 found_bad = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1688 bytelen = 1;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1689 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1690 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1691
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1692 if (!found_bad)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 {
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1694 int i;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1695
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1696 // Convert "ucs2buf[ucs2len]" to 'enc' in "dst".
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1697 if (enc_utf8)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1698 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1699 // From UCS-2 to UTF-8. Cannot fail.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1700 for (i = 0; i < ucs2len; ++i)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1701 dst += utf_char2bytes(ucs2buf[i], dst);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1702 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1703 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1704 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1705 BOOL bad = FALSE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1706 int dstlen;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1707
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1708 // 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
1709 // conversion uses the default character "?",
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1710 // the data doesn't fit in this encoding.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1711 dstlen = WideCharToMultiByte(enc_codepage, 0,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1712 (LPCWSTR)ucs2buf, ucs2len,
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1713 (LPSTR)dst, (int)(src - dst),
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1714 replstr, &bad);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1715 if (bad)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1716 found_bad = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1717 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1718 dst += dstlen;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1719 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1721
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1722 if (found_bad)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1723 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1724 // Deal with bytes we can't convert.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1725 if (can_retry)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1726 goto rewind_retry;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1727 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1728 conv_error = readfile_linenr(linecnt, ptr, dst);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1729 if (bad_char_behavior != BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1730 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1731 if (bad_char_behavior == BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1732 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1733 mch_memmove(dst, src, bytelen);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1734 dst += bytelen;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1735 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1736 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1737 *dst++ = bad_char_behavior;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1738 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1739 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1740
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1741 src += bytelen;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1742 size -= bytelen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1744
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1745 if (size > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1747 // An incomplete byte sequence remaining.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1748 mch_memmove(conv_rest, src, size);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1749 conv_restlen = size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1751
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1752 // The new size is equal to how much "dst" was advanced.
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1753 size = (long)(dst - ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 else
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1756 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1757 #ifdef MACOS_CONVERT
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 if (fio_flags & FIO_MACROMAN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 * Conversion from Apple MacRoman char encoding to UTF-8 or
18
293621502c4d updated for version 7.0010
vimboss
parents: 17
diff changeset
1762 * latin1. This is in os_mac_conv.c.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 */
18
293621502c4d updated for version 7.0010
vimboss
parents: 17
diff changeset
1764 if (macroman2enc(ptr, &size, real_size) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 goto rewind_retry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 else
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1768 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 if (fio_flags != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 int u8c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 char_u *tail = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 * "enc_utf8" set: Convert Unicode or Latin1 to UTF-8.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 * "enc_utf8" not set: Convert Unicode to Latin1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 * Go from end to start through the buffer, because the number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 * of bytes may increase.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 * "dest" points to after where the UTF-8 bytes go, "p" points
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 * to after the next character to convert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 dest = ptr + real_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 if (fio_flags == FIO_LATIN1 || fio_flags == FIO_UTF8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 p = ptr + size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 if (fio_flags == FIO_UTF8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1789 // Check for a trailing incomplete UTF-8 sequence
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 tail = ptr + size - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 while (tail > ptr && (*tail & 0xc0) == 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 --tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 if (tail + utf_byte2len(*tail) <= ptr + size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 tail = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 p = tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1801 // Check for a trailing byte
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 p = ptr + (size & ~1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 if (size & 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 tail = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 if ((fio_flags & FIO_UTF16) && p > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1807 // Check for a trailing leading word
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 if (fio_flags & FIO_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 u8c = (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 u8c += *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 u8c = *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 u8c += (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 if (u8c >= 0xd800 && u8c <= 0xdbff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 tail = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 p += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1824 else // FIO_UCS4
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1826 // Check for trailing 1, 2 or 3 bytes
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 p = ptr + (size & ~3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 if (size & 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 tail = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1832 // 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
1833 // conv_rest[].
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 if (tail != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 conv_restlen = (int)((ptr + size) - tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 mch_memmove(conv_rest, (char_u *)tail, conv_restlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 size -= conv_restlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 while (p > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 if (fio_flags & FIO_LATIN1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 u8c = *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 if (fio_flags & FIO_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 u8c = (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 u8c += *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 u8c = *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 u8c += (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 if ((fio_flags & FIO_UTF16)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 && u8c >= 0xdc00 && u8c <= 0xdfff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 int u16c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 if (p == ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1865 // Missing leading word.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 if (can_retry)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 goto rewind_retry;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1868 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1869 conv_error = readfile_linenr(linecnt,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1870 ptr, p);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1871 if (bad_char_behavior == BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1872 continue;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1873 if (bad_char_behavior != BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1874 u8c = bad_char_behavior;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1877 // 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
1878 // word and compute the resulting character
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 if (fio_flags & FIO_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 u16c = (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 u16c += *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 u16c = *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 u16c += (*--p << 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 }
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1889 u8c = 0x10000 + ((u16c & 0x3ff) << 10)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1890 + (u8c & 0x3ff);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1891
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1892 // Check if the word is indeed a leading word.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 if (u16c < 0xd800 || u16c > 0xdbff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 if (can_retry)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 goto rewind_retry;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1897 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1898 conv_error = readfile_linenr(linecnt,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1899 ptr, p);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1900 if (bad_char_behavior == BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1901 continue;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1902 if (bad_char_behavior != BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1903 u8c = bad_char_behavior;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 else if (fio_flags & FIO_UCS4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 if (fio_flags & FIO_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 {
12698
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1911 u8c = (unsigned)*--p << 24;
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1912 u8c += (unsigned)*--p << 16;
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1913 u8c += (unsigned)*--p << 8;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 u8c += *--p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1916 else // big endian
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 u8c = *--p;
12698
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1919 u8c += (unsigned)*--p << 8;
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1920 u8c += (unsigned)*--p << 16;
6d3d64be7945 patch 8.0.1227: undefined left shift in readfile()
Christian Brabandt <cb@256bit.org>
parents: 12656
diff changeset
1921 u8c += (unsigned)*--p << 24;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1924 else // UTF-8
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 if (*--p < 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 u8c = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 len = utf_head_off(ptr, p);
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1931 p -= len;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1932 u8c = utf_ptr2char(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1935 // 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
1936 // 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
1937 // report the error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 if (can_retry)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 goto rewind_retry;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1940 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1941 conv_error = readfile_linenr(linecnt,
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1942 ptr, p);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1943 if (bad_char_behavior == BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1944 continue;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1945 if (bad_char_behavior != BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1946 u8c = bad_char_behavior;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1950 if (enc_utf8) // produce UTF-8
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 dest -= utf_char2len(u8c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 (void)utf_char2bytes(u8c, dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1955 else // produce Latin1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 --dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 if (u8c >= 0x100)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1960 // 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
1961 // 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
1962 // report the error.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1963 if (can_retry)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 goto rewind_retry;
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1965 if (conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1966 conv_error = readfile_linenr(linecnt, ptr, p);
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1967 if (bad_char_behavior == BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1968 ++dest;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1969 else if (bad_char_behavior == BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1970 *dest = u8c;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1971 else if (eap != NULL && eap->bad_char != 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1972 *dest = bad_char_behavior;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1973 else
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1974 *dest = 0xBF;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 *dest = u8c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1981 // move the linerest to before the converted characters
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 line_start = dest - linerest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 mch_memmove(line_start, buffer, (size_t)linerest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 size = (long)((ptr + real_size) - dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 ptr = dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 }
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1987 else if (enc_utf8 && !curbuf->b_p_bin)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1988 {
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1989 int incomplete_tail = FALSE;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1990
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
1991 // Reading UTF-8: Check if the bytes are valid UTF-8.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
1992 for (p = ptr; ; ++p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1994 int todo = (int)((ptr + size) - p);
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1995 int l;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1996
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1997 if (todo <= 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
1998 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 if (*p >= 0x80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2001 // 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
2002 // 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
2003 // 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
2004 // then.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2005 l = utf_ptr2len_len(p, todo);
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2006 if (l > todo && !incomplete_tail)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2008 // 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
2009 // 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
2010 // 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
2011 // we have already done so.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2012 if (p > ptr || filesize > 0)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2013 incomplete_tail = TRUE;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2014 // 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
2015 // 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
2016 // already done so.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2017 if (p > ptr)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2018 {
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2019 conv_restlen = todo;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2020 mch_memmove(conv_rest, p, conv_restlen);
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2021 size -= conv_restlen;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2022 break;
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2023 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 }
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2025 if (l == 1 || l > todo)
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2026 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2027 // 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
2028 // 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
2029 // file is more likely than a conversion error.
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2030 if (can_retry && !incomplete_tail)
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2031 break;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2032 #ifdef USE_ICONV
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2033 // When we did a conversion report an error.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2034 if (iconv_fd != (iconv_t)-1 && conv_error == 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2035 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
2036 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2037 // Remember the first linenr with an illegal byte
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2038 if (conv_error == 0 && illegal_byte == 0)
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2039 illegal_byte = readfile_linenr(linecnt, ptr, p);
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2040
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2041 // Drop, keep or replace the bad byte.
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2042 if (bad_char_behavior == BAD_DROP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2043 {
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2044 mch_memmove(p, p + 1, todo - 1);
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2045 --p;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2046 --size;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2047 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2048 else if (bad_char_behavior != BAD_KEEP)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2049 *p = bad_char_behavior;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2050 }
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2051 else
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2052 p += l - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 }
1597
80b9076e9e17 updated for version 7.1-310
vimboss
parents: 1583
diff changeset
2055 if (p < ptr + size && !incomplete_tail)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2057 // Detected a UTF-8 error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 rewind_retry:
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2059 // Retry reading with another conversion.
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2060 #if defined(FEAT_EVAL) && defined(USE_ICONV)
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2061 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
2062 // iconv() failed, try 'charconvert'
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2063 did_iconv = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 else
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2065 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2066 // use next item from 'fileencodings'
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2067 advance_fenc = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2068 file_rewind = TRUE;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2069 goto retry;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2073 // count the number of characters (after conversion!)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 filesize += size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 * when reading the first part of a file: guess EOL type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 if (fileformat == EOL_UNKNOWN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2081 // First try finding a NL, for Dos and Unix
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 if (try_dos || try_unix)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2084 // Reset the carriage return counter.
6635
050e6df85f99 updated for version 7.4.643
Bram Moolenaar <bram@vim.org>
parents: 6623
diff changeset
2085 if (try_mac)
050e6df85f99 updated for version 7.4.643
Bram Moolenaar <bram@vim.org>
parents: 6623
diff changeset
2086 try_mac = 1;
050e6df85f99 updated for version 7.4.643
Bram Moolenaar <bram@vim.org>
parents: 6623
diff changeset
2087
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 for (p = ptr; p < ptr + size; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 if (*p == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 if (!try_unix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 || (try_dos && p > ptr && p[-1] == CAR))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 fileformat = EOL_DOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 fileformat = EOL_UNIX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 }
6618
a871b5070d59 updated for version 7.4.635
Bram Moolenaar <bram@vim.org>
parents: 6608
diff changeset
2099 else if (*p == CAR && try_mac)
a871b5070d59 updated for version 7.4.635
Bram Moolenaar <bram@vim.org>
parents: 6608
diff changeset
2100 try_mac++;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2103 // Don't give in to EOL_UNIX if EOL_MAC is more likely
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 if (fileformat == EOL_UNIX && try_mac)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2106 // Need to reset the counters when retrying fenc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 try_mac = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 try_unix = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 for (; p >= ptr && *p != CAR; p--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 if (p >= ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 for (p = ptr; p < ptr + size; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 if (*p == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 try_unix++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 else if (*p == CAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 try_mac++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 if (try_mac > try_unix)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 fileformat = EOL_MAC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 }
6618
a871b5070d59 updated for version 7.4.635
Bram Moolenaar <bram@vim.org>
parents: 6608
diff changeset
2124 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
2125 // 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
2126 // all: use the default format.
6618
a871b5070d59 updated for version 7.4.635
Bram Moolenaar <bram@vim.org>
parents: 6608
diff changeset
2127 fileformat = default_fileformat();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2130 // No NL found: may use Mac format
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 if (fileformat == EOL_UNKNOWN && try_mac)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 fileformat = EOL_MAC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2134 // Still nothing found? Use first format in 'ffs'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 if (fileformat == EOL_UNKNOWN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 fileformat = default_fileformat();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2138 // if editing a new file: may set p_tx and p_ff
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2139 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 set_fileformat(fileformat, OPT_LOCAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 * This loop is executed once for every character read.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 * Keep it fast!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 if (fileformat == EOL_MAC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 while (++ptr, --size >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2153 // catch most common case first
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 if ((c = *ptr) != NUL && c != CAR && c != NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 if (c == NUL)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2157 *ptr = NL; // NULs are replaced by newlines!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 else if (c == NL)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2159 *ptr = CAR; // NLs are replaced by CRs!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 if (skip_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2164 *ptr = NUL; // end of line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 len = (colnr_T) (ptr - line_start + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 if (ml_append(lnum, line_start, len, newfile) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2171 #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
2172 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
2173 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
2174 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 if (--read_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2178 error = TRUE; // break loop
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2179 line_start = ptr; // nothing left to write
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 --skip_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 line_start = ptr + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 while (++ptr, --size >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2194 if ((c = *ptr) != NUL && c != NL) // catch most common case
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 if (c == NUL)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2197 *ptr = NL; // NULs are replaced by newlines!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 if (skip_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2202 *ptr = NUL; // end of line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 len = (colnr_T)(ptr - line_start + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 if (fileformat == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 {
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
2206 if (ptr > line_start && ptr[-1] == CAR)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2208 // remove CR before NL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 ptr[-1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 * Reading in Dos format, but no CR-LF found!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 * When 'fileformats' includes "unix", delete all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 * the lines read so far and start all over again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 * Otherwise give an error message later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 else if (ff_error != EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 if ( try_unix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 && !read_stdin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 && (read_buffer
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
2223 || 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
2224 == 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 fileformat = EOL_UNIX;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2227 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 set_fileformat(EOL_UNIX, OPT_LOCAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 file_rewind = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 keep_fileformat = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 goto retry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 ff_error = EOL_DOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 if (ml_append(lnum, line_start, len, newfile) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2241 #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
2242 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
2243 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
2244 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 if (--read_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2248 error = TRUE; // break loop
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2249 line_start = ptr; // nothing left to write
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 --skip_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 line_start = ptr + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 linerest = (long)(ptr - line_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 failed:
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2264 // not an error, max. number of lines reached
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 if (error && read_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 * If we get EOF in the middle of a line, note the fact and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 * complete the line ourselves.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 * In Dos format ignore a trailing CTRL-Z, unless 'binary' set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 if (!error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 && !got_int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 && linerest != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 && !(!curbuf->b_p_bin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 && fileformat == EOL_DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 && *line_start == Ctrl_Z
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 && ptr == line_start + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2281 // remember for when writing
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2282 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 curbuf->b_p_eol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 *ptr = NUL;
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2285 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
2286 if (ml_append(lnum, line_start, len, newfile) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 else
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2289 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2290 #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
2291 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
2292 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
2293 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 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
2295 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2298 if (set_options)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2299 save_file_ff(curbuf); // remember the current file format
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 #ifdef FEAT_CRYPT
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2302 if (curbuf->b_cryptstate != NULL)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2303 {
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2304 crypt_free_state(curbuf->b_cryptstate);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2305 curbuf->b_cryptstate = NULL;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2306 }
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2307 if (cryptkey != NULL && cryptkey != curbuf->b_p_key)
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2308 crypt_free_key(cryptkey);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2309 // 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
2310 // encryption was used.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2313 // 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
2314 // Also for ":read ++edit file".
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2315 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 set_string_option_direct((char_u *)"fenc", -1, fenc,
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2317 OPT_FREE|OPT_LOCAL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 if (fenc_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 vim_free(fenc);
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2320 #ifdef USE_ICONV
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 if (iconv_fd != (iconv_t)-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 iconv_close(iconv_fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 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
2326 close(fd); // errors are ignored
2003
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2327 #ifdef HAVE_FD_CLOEXEC
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2328 else
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2329 {
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2330 int fdflags = fcntl(fd, F_GETFD);
23467
826a6406ea7b patch 8.2.2276: list of distributed files is outdated
Bram Moolenaar <Bram@vim.org>
parents: 23017
diff changeset
2331
2003
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2332 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
2333 (void)fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
2003
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2334 }
5d5cad78a838 updated for version 7.2-300
vimboss
parents: 2001
diff changeset
2335 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 #ifdef HAVE_DUP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 if (read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2341 // Use stderr for stdin, makes shell commands work.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 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
2343 vim_ignored = dup(2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 if (tmpname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2349 mch_remove(tmpname); // delete converted file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 vim_free(tmpname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2352 --no_wait_return; // may wait for return now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 * In recovery mode everything but autocommands is skipped.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 if (!recoverymode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2359 // need to delete the last line, which comes from the empty buffer
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 netbeansFireChanges = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 #endif
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20311
diff changeset
2365 ml_delete(curbuf->b_ml.ml_line_count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 netbeansFireChanges = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 --linecnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 linecnt = curbuf->b_ml.ml_line_count - linecnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 if (filesize == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 linecnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 if (newfile || read_buffer)
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2375 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 redraw_curbuf_later(NOT_VALID);
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2377 #ifdef FEAT_DIFF
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2378 // 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
2379 // be updated.
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2380 diff_invalidate(curbuf);
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2381 #endif
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2382 #ifdef FEAT_FOLDING
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2383 // 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
2384 // before triggering autocommands.
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2385 foldUpdateAll(curwin);
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2386 #endif
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
2387 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2388 else if (linecnt) // appended at least one line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 appended_lines_mark(from, linecnt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 #ifndef ALWAYS_USE_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 * If we were reading from the same terminal as where messages go,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 * the screen will have been messed up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 * Switch on raw mode now and clear the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 if (read_stdin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2399 settmode(TMODE_RAW); // set to raw mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 starttermcap();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 screenclear();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 if (!(flags & READ_DUMMY))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 filemess(curbuf, sfname, (char_u *)_(e_interr), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 if (newfile)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2411 curbuf->b_p_ro = TRUE; // must use "w!" now
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 msg_scroll = msg_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 #ifdef FEAT_VIMINFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 check_marks_read();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2417 return OK; // an interrupt isn't really an error
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 if (!filtering && !(flags & READ_DUMMY))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2422 msg_add_fname(curbuf, sfname); // fname in IObuff with quotes
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 c = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 #ifdef UNIX
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2426 if (S_ISFIFO(perm)) // fifo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 STRCAT(IObuff, _("[fifo]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2431 if (S_ISSOCK(perm)) // or socket
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 STRCAT(IObuff, _("[socket]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 }
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2436 # ifdef OPEN_CHR_FILES
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2437 if (S_ISCHR(perm)) // or character special
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2438 {
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2439 STRCAT(IObuff, _("[character special]"));
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2440 c = TRUE;
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2441 }
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2442 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 if (curbuf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 if (read_no_eol_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 msg_add_eol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 if (ff_error == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 STRCAT(IObuff, _("[CR missing]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 if (split)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 STRCAT(IObuff, _("[long lines split]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 if (notconverted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 STRCAT(IObuff, _("[NOT converted]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 else if (converted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 STRCAT(IObuff, _("[converted]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 #ifdef FEAT_CRYPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 if (cryptkey != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 {
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2477 crypt_append_msg(curbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 #endif
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2481 if (conv_error != 0)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2482 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2483 sprintf((char *)IObuff + STRLEN(IObuff),
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2484 _("[CONVERSION ERROR in line %ld]"), (long)conv_error);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 else if (illegal_byte > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 sprintf((char *)IObuff + STRLEN(IObuff),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 _("[ILLEGAL BYTE in line %ld]"), (long)illegal_byte);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 }
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2493 else if (error)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 STRCAT(IObuff, _("[READ ERRORS]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 if (msg_add_fileformat(fileformat))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 c = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 #ifdef FEAT_CRYPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 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
2502 msg_add_lines(c, (long)linecnt, filesize
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2503 - crypt_get_header_len(crypt_get_method_nr(curbuf)));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 msg_add_lines(c, (long)linecnt, filesize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13240
diff changeset
2508 VIM_CLEAR(keep_msg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 msg_scrolled_ign = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 #ifdef ALWAYS_USE_GUI
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2511 // 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
2512 // message box (which might be shown when exiting!)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 if (read_stdin || read_buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 p = msg_may_trunc(FALSE, IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 #endif
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
2517 {
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
2518 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
2519 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
2520 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
2521 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 if (read_stdin || read_buffer || restart_edit != 0
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 532
diff changeset
2523 || (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
2524 // 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
2525 // - 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
2526 // - 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
2527 // before redrawing).
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2528 // - 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
2529 // prompt.
679
e629de7618da updated for version 7.0203
vimboss
parents: 676
diff changeset
2530 set_keep_msg(p, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 msg_scrolled_ign = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2534 // with errors writing the file requires ":w!"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 if (newfile && (error
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2536 || conv_error != 0
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2537 || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 curbuf->b_p_ro = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2540 u_clearline(); // cannot use "U" command after adding lines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 * In Ex mode: cursor at last new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 * Otherwise: cursor at first new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 if (exmode_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 curwin->w_cursor.lnum = from + linecnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 curwin->w_cursor.lnum = from + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 check_cursor_lnum();
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2551 beginline(BL_WHITE | BL_FIX); // on first non-blank
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22568
diff changeset
2553 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
2554 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18199
diff changeset
2555 // 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
2556 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
2557 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
2558 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
2559 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
2560 }
696
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2561
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
2562 #ifdef MSWIN
696
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2563 /*
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2564 * Work around a weird problem: When a file has two links (only
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2565 * possible on NTFS) and we write through one link, then stat() it
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
2566 * through the other link, the timestamp information may be wrong.
696
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2567 * It's correct again after reading the file, thus reset the timestamp
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2568 * here.
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2569 */
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2570 if (newfile && !read_stdin && !read_buffer
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2571 && mch_stat((char *)fname, &st) >= 0)
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2572 {
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2573 buf_store_time(curbuf, &st, fname);
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2574 curbuf->b_mtime_read = curbuf->b_mtime;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
2575 curbuf->b_mtime_read_ns = curbuf->b_mtime_ns;
696
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2576 }
f0a9ef4db025 updated for version 7.0210
vimboss
parents: 694
diff changeset
2577 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 msg_scroll = msg_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 #ifdef FEAT_VIMINFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 * Get the marks before executing autocommands, so they can be used there.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 check_marks_read();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 /*
6933
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6721
diff changeset
2589 * We remember if the last line of the read didn't have
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6721
diff changeset
2590 * an eol even when 'binary' is off, to support turning 'fixeol' off,
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6721
diff changeset
2591 * or writing the read again with 'binary' on. The latter is required
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6721
diff changeset
2592 * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 */
2707
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
2594 curbuf->b_no_eol_lnum = read_no_eol_lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2596 // 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
2597 // different.
2482
88751831fa0a When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents: 2410
diff changeset
2598 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
2599 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
2600
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2601 #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
2602 /*
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2603 * 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
2604 */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2605 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
2606 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2607 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
2608
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2609 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
2610 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
2611 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2612 #endif
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2613
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
2614 if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 int m = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 int n = msg_scrolled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2619 // 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
2620 // modified if the format/encoding was automatically detected.
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2621 if (set_options)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 save_file_ff(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 * The output from the autocommands should not overwrite anything and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 * should not be overwritten: Set msg_scroll, restore its value if no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 * output was done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 msg_scroll = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 if (filtering)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 FALSE, curbuf, eap);
9828
e84e45786691 commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents: 9682
diff changeset
2633 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
2634 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 FALSE, curbuf, eap);
8937
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 8212
diff changeset
2637 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
2638 /*
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 8212
diff changeset
2639 * 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
2640 * 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
2641 */
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 8212
diff changeset
2642 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
2643 TRUE, curbuf);
da4f6e238374 commit https://github.com/vim/vim/commit/c3691332f72169c486066200c0f3935418364900
Christian Brabandt <cb@256bit.org>
parents: 8212
diff changeset
2644 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 apply_autocmds_exarg(EVENT_FILEREADPOST, sfname, sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 FALSE, NULL, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 if (msg_scrolled == n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 msg_scroll = m;
2707
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
2650 # ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2651 if (aborting()) // autocmds may abort script processing
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 return FAIL;
2707
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
2653 # endif
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
2654 }
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
2655
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 if (recoverymode && error)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660
9911
74e345d2878c commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents: 9828
diff changeset
2661 #if defined(OPEN_CHR_FILES) || defined(PROTO)
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2662 /*
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2663 * Returns TRUE if the file name argument is of the form "/dev/fd/\d\+",
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2664 * which is the name of files used for process substitution output by
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2665 * some shells on some operating systems, e.g., bash on SunOS.
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2666 * Do not accept "/dev/fd/[012]", opening these may hang Vim.
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2667 */
9911
74e345d2878c commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents: 9828
diff changeset
2668 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2669 is_dev_fd_file(char_u *fname)
1313
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2670 {
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2671 return (STRNCMP(fname, "/dev/fd/", 8) == 0
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2672 && VIM_ISDIGIT(fname[8])
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2673 && *skipdigits(fname + 9) == NUL
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2674 && (fname[9] != NUL
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2675 || (fname[8] != '0' && fname[8] != '1' && fname[8] != '2')));
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2676 }
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2677 #endif
dbd226be80b1 updated for version 7.1-027
vimboss
parents: 1303
diff changeset
2678
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2679 /*
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2680 * From the current line count and characters read after that, estimate the
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2681 * line number where we are now.
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2682 * Used for error messages that include a line number.
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2683 */
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2684 static linenr_T
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2685 readfile_linenr(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2686 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
2687 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
2688 char_u *endp) // end of more bytes read
595
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2689 {
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2690 char_u *s;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2691 linenr_T lnum;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2692
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2693 lnum = curbuf->b_ml.ml_line_count - linecnt + 1;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2694 for (s = p; s < endp; ++s)
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2695 if (*s == '\n')
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2696 ++lnum;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2697 return lnum;
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2698 }
fea48f63efc8 updated for version 7.0169
vimboss
parents: 592
diff changeset
2699
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 /*
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2701 * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2702 * equal to the buffer "buf". Used for calling readfile().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 * Returns OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2706 prep_exarg(exarg_T *eap, buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 {
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2708 eap->cmd = alloc(15 + (unsigned)STRLEN(buf->b_p_fenc));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 if (eap->cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711
13575
4df23d9bad47 patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents: 13444
diff changeset
2712 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
2713 eap->force_enc = 8;
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2714 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
2715 eap->force_ff = *buf->b_p_ff;
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2716
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2717 eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
2718 eap->read_edit = FALSE;
612
b9370cfb091a updated for version 7.0174
vimboss
parents: 609
diff changeset
2719 eap->forceit = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2723 /*
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2724 * Set default or forced 'fileformat' and 'binary'.
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2725 */
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2726 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2727 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
2728 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2729 // set default 'fileformat'
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2730 if (set_options)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2731 {
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2732 if (eap != NULL && eap->force_ff != 0)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2733 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
2734 else if (*p_ffs != NUL)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2735 set_fileformat(default_fileformat(), OPT_LOCAL);
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2736 }
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2737
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2738 // set or reset 'binary'
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2739 if (eap != NULL && eap->force_bin != 0)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2740 {
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2741 int oldval = curbuf->b_p_bin;
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2742
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2743 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
2744 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
2745 }
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2746 }
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2747
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2748 /*
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2749 * Set forced 'fileencoding'.
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2750 */
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2751 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2752 set_forced_fenc(exarg_T *eap)
5231
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2753 {
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2754 if (eap->force_enc != 0)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2755 {
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2756 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
2757
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2758 if (fenc != NULL)
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2759 set_string_option_direct((char_u *)"fenc", -1,
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2760 fenc, OPT_FREE|OPT_LOCAL, 0);
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2761 vim_free(fenc);
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2762 }
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2763 }
74d2f3188cd0 updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
2764
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 * Find next fileencoding to use from 'fileencodings'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 * "pp" points to fenc_next. It's advanced to the next item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 * When there are no more items, an empty string is returned and *pp is set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 * NULL.
17692
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2770 * 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
2771 * is set to TRUE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 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
2774 next_fenc(char_u **pp, int *alloced)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 char_u *r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778
17692
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2779 *alloced = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 if (**pp == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 *pp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 return (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 p = vim_strchr(*pp, ',');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 r = enc_canonize(*pp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 *pp += STRLEN(*pp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20828
diff changeset
2793 r = vim_strnsave(*pp, p - *pp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 *pp = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 if (r != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 p = enc_canonize(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 vim_free(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 r = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 }
17692
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2802 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
2803 *alloced = TRUE;
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2804 else
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2805 {
1e3ff1eae4c3 patch 8.1.1843: might be freeing memory that was not allocated
Bram Moolenaar <Bram@vim.org>
parents: 17584
diff changeset
2806 // out of memory
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 r = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 *pp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2813 #ifdef FEAT_EVAL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 * Convert a file with the 'charconvert' expression.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 * This closes the file which is to be read, converts it and opens the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 * resulting file for reading.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 * Returns name of the resulting converted file (the caller should delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 * after reading it).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 * Returns NULL if the conversion failed ("*fdp" is not set) .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 static char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2823 readfile_charconvert(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2824 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
2825 char_u *fenc, // converted from
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2826 int *fdp) // in/out: file descriptor of file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 char_u *tmpname;
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15531
diff changeset
2829 char *errmsg = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830
6721
7347229a646a updated for version 7.4.684
Bram Moolenaar <bram@vim.org>
parents: 6635
diff changeset
2831 tmpname = vim_tempname('r', FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 if (tmpname == NULL)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15531
diff changeset
2833 errmsg = _("Can't find temp file for conversion");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2836 close(*fdp); // close the input file, ignore errors
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 *fdp = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 fname, tmpname) == FAIL)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15531
diff changeset
2840 errmsg = _("Conversion with 'charconvert' failed");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 if (errmsg == NULL && (*fdp = mch_open((char *)tmpname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 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
2843 errmsg = _("can't read output of 'charconvert'");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 if (errmsg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2848 // 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
2849 // 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
2850 msg(errmsg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 if (tmpname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2853 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
2854 VIM_CLEAR(tmpname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2858 // If the input file is closed, open it (caller should check for error).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 if (*fdp < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 *fdp = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 return tmpname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 }
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2864 #endif
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2865
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
2866 #if defined(FEAT_CRYPT) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 /*
2180
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents: 2147
diff changeset
2868 * Check for magic number used for encryption. Applies to the current buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 * If found, the magic number is removed from ptr[*sizep] and *sizep and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 * *filesizep are updated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 * Return the (new) encryption key, NULL for no encryption.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 static char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2874 check_for_cryptkey(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2875 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
2876 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
2877 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
2878 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
2879 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
2880 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
2881 int *did_ask) // flag: whether already asked for key
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 {
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2883 int method = crypt_method_nr_from_magic((char *)ptr, *sizep);
5312
8b5d80861c5e updated for version 7.4.009
Bram Moolenaar <bram@vim.org>
parents: 5278
diff changeset
2884 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
2885
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents: 2147
diff changeset
2886 if (method >= 0)
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents: 2147
diff changeset
2887 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2888 // 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
2889 // Avoids accidentally overwriting the file with garbage.
5312
8b5d80861c5e updated for version 7.4.009
Bram Moolenaar <bram@vim.org>
parents: 5278
diff changeset
2890 curbuf->b_p_ro = TRUE;
8b5d80861c5e updated for version 7.4.009
Bram Moolenaar <bram@vim.org>
parents: 5278
diff changeset
2891
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2892 // Set the cryptmethod local to the buffer.
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2893 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
2894 if (cryptkey == NULL && !*did_ask)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 if (*curbuf->b_p_key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 cryptkey = curbuf->b_p_key;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2900 // 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
2901 // 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
2902 // 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
2903 // 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
2904 smsg(_(need_key_msg), fname);
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
2905 msg_scroll = TRUE;
6353
60659773c73b updated for version 7.4.509
Bram Moolenaar <bram@vim.org>
parents: 6320
diff changeset
2906 crypt_check_method(method);
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2907 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
2908 *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
2909
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2910 // check if empty key entered
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 if (cryptkey != NULL && *cryptkey == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 if (cryptkey != curbuf->b_p_key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 vim_free(cryptkey);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 cryptkey = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 if (cryptkey != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 {
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2922 int header_len;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2923
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2924 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
2925 if (*sizep <= header_len)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2926 // 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
2927 return NULL;
25421
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2928
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2929 curbuf->b_cryptstate = crypt_create_from_header(
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2930 method, cryptkey, ptr);
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2931 crypt_set_cm_option(curbuf, method);
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2932
c094a29722bb patch 8.2.3247: using uninitialized memory when checking for crypt method
Bram Moolenaar <Bram@vim.org>
parents: 25417
diff changeset
2933 // Remove cryptmethod specific header from the text.
6122
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2934 *filesizep += header_len;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2935 *sizep -= header_len;
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2936 mch_memmove(ptr, ptr + header_len, (size_t)*sizep);
18ac55444b37 updated for version 7.4.399
Bram Moolenaar <bram@vim.org>
parents: 5958
diff changeset
2937
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2938 // Restore the read-only flag.
5312
8b5d80861c5e updated for version 7.4.009
Bram Moolenaar <bram@vim.org>
parents: 5278
diff changeset
2939 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
2940 }
f60a0c9cbe6c Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents: 2147
diff changeset
2941 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2942 // 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
2943 // 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
2944 else if (newfile && *curbuf->b_p_key != NUL && !starting)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 return cryptkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2949 #endif // FEAT_CRYPT
2265
b7cb69ab616d Added salt to blowfish encryption.
Bram Moolenaar <bram@vim.org>
parents: 2261
diff changeset
2950
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 /*
1303
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2952 * Return TRUE if a file appears to be read-only from the file permissions.
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2953 */
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2954 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
2955 check_file_readonly(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
2956 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
2957 int perm UNUSED) // known permissions on file
1303
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2958 {
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2959 #ifndef USE_MCH_ACCESS
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2960 int fd = 0;
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2961 #endif
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2962
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2963 return (
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2964 #ifdef USE_MCH_ACCESS
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2965 # ifdef UNIX
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2966 (perm & 0222) == 0 ||
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2967 # endif
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2968 mch_access((char *)fname, W_OK)
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2969 #else
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2970 (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2971 ? TRUE : (close(fd), FALSE)
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2972 #endif
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2973 );
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2974 }
da0991871b02 updated for version 7.1-017
vimboss
parents: 1201
diff changeset
2975
15816
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2976 #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
2977 /*
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2978 * 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
2979 * 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
2980 */
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2981 int
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2982 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
2983 {
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2984 int r;
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2985
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2986 # ifdef MACOS_X
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2987 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
2988 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
2989 # endif
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2990 r = fsync(fd);
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2991 return r;
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2992 }
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2993 #endif
40336d427dd2 patch 8.1.0915: fsync() may not work properly on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15794
diff changeset
2994
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 /*
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
2996 * Set the name of the current buffer. Use when the buffer doesn't have a
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
2997 * name and a ":r" or ":w" command with a file name is used.
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
2998 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
2999 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3000 set_rw_fname(char_u *fname, char_u *sfname)
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3001 {
1905
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3002 buf_T *buf = curbuf;
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3003
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3004 // It's like the unnamed buffer is deleted....
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3005 if (curbuf->b_p_bl)
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3006 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3007 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
3008 #ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3009 if (aborting()) // autocmds may abort script processing
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3010 return FAIL;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3011 #endif
1905
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3012 if (curbuf != buf)
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3013 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3014 // 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
3015 emsg(_(e_auchangedbuf));
1905
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3016 return FAIL;
1a00e831244b updated for version 7.2-202
vimboss
parents: 1880
diff changeset
3017 }
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3018
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3019 if (setfname(curbuf, fname, sfname, FALSE) == OK)
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3020 curbuf->b_flags |= BF_NOTEDITED;
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3021
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3022 // ....and a new named one is created
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3023 apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf);
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3024 if (curbuf->b_p_bl)
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3025 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
3026 #ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3027 if (aborting()) // autocmds may abort script processing
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3028 return FAIL;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3029 #endif
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3030
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3031 // Do filetype detection now if 'filetype' is empty.
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3032 if (*curbuf->b_p_ft == NUL)
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3033 {
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 799
diff changeset
3034 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
3035 (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE, NULL);
717
2fa8cb05b861 updated for version 7.0218
vimboss
parents: 715
diff changeset
3036 do_modelines(0);
633
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3037 }
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3038
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3039 return OK;
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3040 }
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3041
7437be625546 updated for version 7.0183
vimboss
parents: 628
diff changeset
3042 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 * Put file name into IObuff with quotes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 */
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 26
diff changeset
3045 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3046 msg_add_fname(buf_T *buf, char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 fname = (char_u *)"-stdin-";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 home_replace(buf, fname, IObuff + 1, IOSIZE - 4, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 IObuff[0] = '"';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 STRCAT(IObuff, "\" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 * Append message for text mode to IObuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 * Return TRUE if something appended.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3059 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3060 msg_add_fileformat(int eol_type)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 #ifndef USE_CRNL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 if (eol_type == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[dos]") : _("[dos format]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 if (eol_type == EOL_MAC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 }
15840
734b1928a5aa patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents: 15816
diff changeset
3074 #ifdef USE_CRNL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 if (eol_type == EOL_UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 * Append line and character count to IObuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 */
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 26
diff changeset
3087 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3088 msg_add_lines(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3089 int insert_space,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3090 long lnum,
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
3091 off_T nchars)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 p = IObuff + STRLEN(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 if (insert_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 *p++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 if (shortmess(SHM_LINES))
9391
4c40631238e4 commit https://github.com/vim/vim/commit/bde9810d6103ffe3a22a9330021cb21db1ed1792
Christian Brabandt <cb@256bit.org>
parents: 9389
diff changeset
3100 vim_snprintf((char *)p, IOSIZE - (p - IObuff),
21154
9f9c26b3ddc5 patch 8.2.1128: the write message mentions characters, but it's bytes
Bram Moolenaar <Bram@vim.org>
parents: 21073
diff changeset
3101 "%ldL, %lldB", lnum, (varnumber_T)nchars);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 {
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14509
diff changeset
3104 sprintf((char *)p, NGETTEXT("%ld line, ", "%ld lines, ", lnum), lnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 p += STRLEN(p);
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14509
diff changeset
3106 vim_snprintf((char *)p, IOSIZE - (p - IObuff),
21154
9f9c26b3ddc5 patch 8.2.1128: the write message mentions characters, but it's bytes
Bram Moolenaar <Bram@vim.org>
parents: 21073
diff changeset
3107 NGETTEXT("%lld byte", "%lld bytes", nchars),
19477
2bb0e80fcd32 patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents: 19301
diff changeset
3108 (varnumber_T)nchars);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 * Append message for missing line separator to IObuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3115 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3116 msg_add_eol(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3121 int
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
3122 time_differs(stat_T *st, long mtime, long mtime_ns UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 {
25963
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3124 return
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3125 #ifdef ST_MTIM_NSEC
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3126 (long)st->ST_MTIM_NSEC != mtime_ns ||
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3127 #endif
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
3128 #if defined(__linux__) || defined(MSWIN)
25963
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3129 // On a FAT filesystem, esp. under Linux, there are only 5 bits to store
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3130 // the seconds. Since the roundoff is done when flushing the inode, the
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3131 // time may change unexpectedly by one second!!!
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3132 (long)st->st_mtime - mtime > 1 || mtime - (long)st->st_mtime > 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 #else
25963
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3134 (long)st->st_mtime != mtime
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 #endif
25963
aaec2028c8fc patch 8.2.3515: nano time test fails on Mac and FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 25953
diff changeset
3136 ;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 /*
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3140 * Return TRUE if file encoding "fenc" requires conversion from or to
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3141 * 'encoding'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3143 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3144 need_conversion(char_u *fenc)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 {
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3146 int same_encoding;
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3147 int enc_flags;
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3148 int fenc_flags;
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3149
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3150 if (*fenc == NUL || STRCMP(p_enc, fenc) == 0)
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
3151 {
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3152 same_encoding = TRUE;
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
3153 fenc_flags = 0;
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
3154 }
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3155 else
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3156 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3157 // 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
3158 // "ucs-4be", etc.
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3159 enc_flags = get_fio_flags(p_enc);
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3160 fenc_flags = get_fio_flags(fenc);
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3161 same_encoding = (enc_flags != 0 && fenc_flags == enc_flags);
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3162 }
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3163 if (same_encoding)
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3164 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3165 // 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
3166 // conversion when 'encoding' is Unicode but not UTF-8.
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3167 return enc_unicode != 0;
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3168 }
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3169
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3170 // 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
3171 // Unicode encoding and the file is UTF-8.
1948
7ff9f75f9c59 updated for version 7.2-245
vimboss
parents: 1947
diff changeset
3172 return !(enc_utf8 && fenc_flags == FIO_UTF8);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 * Check "ptr" for a unicode encoding and return the FIO_ flags needed for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 * internal conversion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 * if "ptr" is an empty string, use 'encoding'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3180 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3181 get_fio_flags(char_u *ptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 int prop;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 if (*ptr == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 ptr = p_enc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 prop = enc_canon_props(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 if (prop & ENC_UNICODE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 if (prop & ENC_2BYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 if (prop & ENC_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 return FIO_UCS2 | FIO_ENDIAN_L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 return FIO_UCS2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 if (prop & ENC_4BYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 if (prop & ENC_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 return FIO_UCS4 | FIO_ENDIAN_L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 return FIO_UCS4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 if (prop & ENC_2WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 if (prop & ENC_ENDIAN_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 return FIO_UTF16 | FIO_ENDIAN_L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 return FIO_UTF16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3208 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3209 return FIO_UTF8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3210 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3211 if (prop & ENC_LATIN1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212 return FIO_LATIN1;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3213 // must be ENC_DBCS, requires iconv()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3214 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3217 #if defined(MSWIN) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 * Check "ptr" for a MS-Windows codepage name and return the FIO_ flags needed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220 * for the conversion MS-Windows can do for us. Also accept "utf-8".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 * Used for conversion between 'encoding' and 'fileencoding'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3223 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3224 get_win_fio_flags(char_u *ptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 int cp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3228 // Cannot do this when 'encoding' is not utf-8 and not a codepage.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 if (!enc_utf8 && enc_codepage <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 cp = encname2codepage(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 if (cp == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3235 # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 if (STRCMP(ptr, "utf-8") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 cp = CP_UTF8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 return FIO_PUT_CP(cp) | FIO_CODEPAGE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3246 #if defined(MACOS_CONVERT) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 * Check "ptr" for a Carbon supported encoding and return the FIO_ flags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 * needed for the internal conversion to/from utf-8 or latin1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 */
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3251 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3252 get_mac_fio_flags(char_u *ptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 if ((enc_utf8 || STRCMP(p_enc, "latin1") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3255 && (enc_canon_props(ptr) & ENC_MACROMAN))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 return FIO_MACROMAN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3258 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 * Check for a Unicode BOM (Byte Order Mark) at the start of p[size].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 * "size" must be at least 2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264 * Return the name of the encoding and set "*lenp" to the length.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 * Returns NULL when no BOM found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 static char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3268 check_for_bom(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3269 char_u *p,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3270 long size,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3271 int *lenp,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3272 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274 char *name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275 int len = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf
1688
17526daaf79d updated for version 7.2b-021
vimboss
parents: 1665
diff changeset
3278 && (flags == FIO_ALL || flags == FIO_UTF8 || flags == 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3280 name = "utf-8"; // EF BB BF
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 len = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 else if (p[0] == 0xff && p[1] == 0xfe)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 if (size >= 4 && p[2] == 0 && p[3] == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 && (flags == FIO_ALL || flags == (FIO_UCS4 | FIO_ENDIAN_L)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3288 name = "ucs-4le"; // FF FE 00 00
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3289 len = 4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3290 }
1735
35abb7026415 updated for version 7.2-033
vimboss
parents: 1733
diff changeset
3291 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
3292 name = "ucs-2le"; // FF FE
1735
35abb7026415 updated for version 7.2-033
vimboss
parents: 1733
diff changeset
3293 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
3294 // 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
3295 name = "utf-16le"; // FF FE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 else if (p[0] == 0xfe && p[1] == 0xff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 && (flags == FIO_ALL || flags == FIO_UCS2 || flags == FIO_UTF16))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3299 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3300 // Default to utf-16, it works also for ucs-2 text.
1547
e72e30c69d58 updated for version 7.1-261
vimboss
parents: 1486
diff changeset
3301 if (flags == FIO_UCS2)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3302 name = "ucs-2"; // FE FF
1547
e72e30c69d58 updated for version 7.1-261
vimboss
parents: 1486
diff changeset
3303 else
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3304 name = "utf-16"; // FE FF
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 else if (size >= 4 && p[0] == 0 && p[1] == 0 && p[2] == 0xfe
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 && p[3] == 0xff && (flags == FIO_ALL || flags == FIO_UCS4))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3309 name = "ucs-4"; // 00 00 FE FF
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 len = 4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 *lenp = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 return (char_u *)name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 * Try to find a shortname by comparing the fullname with the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 * directory.
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3320 * Returns "full_path" or pointer into "full_path" if shortened.
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3321 */
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3322 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3323 shorten_fname1(char_u *full_path)
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3324 {
2770
25672ad7f377 updated for version 7.3.161
Bram Moolenaar <bram@vim.org>
parents: 2717
diff changeset
3325 char_u *dirname;
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3326 char_u *p = full_path;
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3327
2770
25672ad7f377 updated for version 7.3.161
Bram Moolenaar <bram@vim.org>
parents: 2717
diff changeset
3328 dirname = alloc(MAXPATHL);
25672ad7f377 updated for version 7.3.161
Bram Moolenaar <bram@vim.org>
parents: 2717
diff changeset
3329 if (dirname == NULL)
25672ad7f377 updated for version 7.3.161
Bram Moolenaar <bram@vim.org>
parents: 2717
diff changeset
3330 return full_path;
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3331 if (mch_dirname(dirname, MAXPATHL) == OK)
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3332 {
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3333 p = shorten_fname(full_path, dirname);
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3334 if (p == NULL || *p == NUL)
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3335 p = full_path;
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3336 }
2770
25672ad7f377 updated for version 7.3.161
Bram Moolenaar <bram@vim.org>
parents: 2717
diff changeset
3337 vim_free(dirname);
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3338 return p;
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3339 }
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3340
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3341 /*
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3342 * Try to find a shortname by comparing the fullname with the current
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1410
diff changeset
3343 * directory.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 * Returns NULL if not shorter name possible, pointer into "full_path"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 * otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3348 shorten_fname(char_u *full_path, char_u *dir_name)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 if (full_path == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3354 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 len = (int)STRLEN(dir_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356 if (fnamencmp(dir_name, full_path, len) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3358 p = full_path + len;
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
3359 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 /*
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
3361 * 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
3362 * 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
3363 * this case p may already be correct. <negri>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 if (!((len > 2) && (*(p - 2) == ':')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 if (vim_ispathsep(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 ++p;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3370 #ifndef VMS // the path separator is always part of the path
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 }
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
3376 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 * When using a file in the current drive, remove the drive name:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 * "A:\dir\file" -> "\dir\file". This helps when moving a session file on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 * a floppy from "A:\dir" to "B:\dir".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 else if (len > 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 && TOUPPER_LOC(full_path[0]) == TOUPPER_LOC(dir_name[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 && full_path[1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 && vim_ispathsep(full_path[2]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 p = full_path + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 /*
13819
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3394 * Shorten filename of a buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 * When "force" is TRUE: Use full path from now on for files currently being
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 * edited, both for file name and swap file name. Try to shorten the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 * names a bit, if safe to do so.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 * When "force" is FALSE: Only try to shorten absolute file names.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 * For buffers that have buftype "nofile" or "scratch": never change the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 * name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3402 void
13819
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3403 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
3404 {
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3405 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
3406
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3407 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
3408 #ifdef FEAT_QUICKFIX
17095
10e0d7d96cb0 patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents: 16996
diff changeset
3409 && !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
3410 #endif
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3411 && !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
3412 && (force
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3413 || buf->b_sfname == NULL
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3414 || 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
3415 {
14917
6f2ce3b311de patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
3416 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
3417 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
3418 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
3419 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
3420 {
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3421 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
3422 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
3423 }
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3424 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
3425 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
3426 }
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3427 }
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3428
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3429 /*
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3430 * 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
3431 */
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3432 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3433 shorten_fnames(int force)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 char_u dirname[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 mch_dirname(dirname, MAXPATHL);
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9599
diff changeset
3439 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 {
13819
31bb8e1f7625 patch 8.0.1781: file names in quickfix window are not shortened
Christian Brabandt <cb@256bit.org>
parents: 13810
diff changeset
3441 shorten_buf_fname(buf, dirname, force);
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 8
diff changeset
3442
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3443 // 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
3444 // also have a swap file.
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 8
diff changeset
3445 mf_fullname(buf->b_ml.ml_mfp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 status_redraw_all();
672
db58b9066b21 updated for version 7.0200
vimboss
parents: 661
diff changeset
3448 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
3449 #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
3450 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
3451 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 || defined(FEAT_GUI_MSWIN) \
19526
22f0dda71638 patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
3456 || defined(FEAT_GUI_HAIKU) \
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 * Shorten all filenames in "fnames[count]" by current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3462 shorten_filenames(char_u **fnames, int count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 char_u dirname[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 if (fnames == NULL || count < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 mch_dirname(dirname, sizeof(dirname));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 for (i = 0; i < count; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 if ((p = shorten_fname(fnames[i], dirname)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3475 // 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
3476 // "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
3477 // "p" first then free fnames[i].
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 p = vim_strsave(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 vim_free(fnames[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 fnames[i] = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 /*
14475
dddba3937532 patch 8.1.0251: using full path is not supported for 'backupdir'
Christian Brabandt <cb@256bit.org>
parents: 14433
diff changeset
3487 * Add extension to file name - change path/fo.o.h to path/fo.o.h.ext or
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 * fo_o_h.ext for MSDOS or when shortname option set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 * Assumed that fname is a valid name found in the filesystem we assure that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 * the return value is a different name and ends in 'ext'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 * "ext" MUST be at most 4 characters long if it starts with a dot, 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 * characters otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 * Space for the returned name is allocated, must be freed later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495 * Returns NULL when out of memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3498 modname(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3499 char_u *fname,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3500 char_u *ext,
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3501 int prepend_dot) // may prepend a '.' to file name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502 {
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8080
diff changeset
3503 return buf_modname((curbuf->b_p_sn || curbuf->b_shortname),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 fname, ext, prepend_dot);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3508 buf_modname(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3509 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
3510 char_u *fname,
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3511 char_u *ext,
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3512 int prepend_dot) // may prepend a '.' to file name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 char_u *e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 int fnamelen, extlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 extlen = (int)STRLEN(ext);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 * If there is no file name we must get the name of the current directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 * (we need the full path in case :cd is used).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 if (fname == NULL || *fname == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16754
diff changeset
3528 retval = alloc(MAXPATHL + extlen + 3);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 if (retval == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 if (mch_dirname(retval, MAXPATHL) == FAIL ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 (fnamelen = (int)STRLEN(retval)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 vim_free(retval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 }
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3537 if (!after_pathsep(retval, retval + fnamelen))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 retval[fnamelen++] = PATHSEP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 retval[fnamelen] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3542 prepend_dot = FALSE; // nothing to prepend a dot to
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 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
3547 retval = alloc(fnamelen + extlen + 3);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 if (retval == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 STRCPY(retval, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551 #ifdef VMS
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3552 vms_remove_version(retval); // we do not need versions here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 * search backwards until we hit a '/', '\' or ':' replacing all '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 * by '_' for MSDOS or when shortname option set and ext starts with a dot.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 * Then truncate what is after the '/', '\' or ':' to 8 characters for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 * MSDOS and 26 characters for AMIGA, a lot more for UNIX.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 */
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
3562 for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563 {
15794
0d8291665b59 patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents: 15776
diff changeset
3564 if (*ext == '.' && shortname)
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3565 if (*ptr == '.') // replace '.' by '_'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 *ptr = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 if (vim_ispathsep(*ptr))
391
289b19a6f2ed updated for version 7.0103
vimboss
parents: 375
diff changeset
3568 {
289b19a6f2ed updated for version 7.0103
vimboss
parents: 375
diff changeset
3569 ++ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 break;
391
289b19a6f2ed updated for version 7.0103
vimboss
parents: 375
diff changeset
3571 }
289b19a6f2ed updated for version 7.0103
vimboss
parents: 375
diff changeset
3572 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3574 // the file name has at most BASENAMELEN characters.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 if (STRLEN(ptr) > (unsigned)BASENAMELEN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 ptr[BASENAMELEN] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 s = ptr + STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581 * For 8.3 file names we may have to reduce the length.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 if (shortname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 * If there is no file name, or the file name ends in '/', and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 * extension starts with '.', put a '_' before the dot, because just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 * ".ext" is invalid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 if (fname == NULL || *fname == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 || vim_ispathsep(fname[STRLEN(fname) - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 if (*ext == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 *s++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 * If the extension starts with '.', truncate the base name at 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 * characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 else if (*ext == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 {
1877
b5c1cb6f8d56 updated for version 7.2-174
vimboss
parents: 1873
diff changeset
3602 if ((size_t)(s - ptr) > (size_t)8)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 s = ptr + 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 *s = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 * If the extension doesn't start with '.', and the file name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 * doesn't have an extension yet, append a '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612 else if ((e = vim_strchr(ptr, '.')) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 *s++ = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 * If the extension doesn't start with '.', and there already is an
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
3616 * extension, it may need to be truncated
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 else if ((int)STRLEN(e) + extlen > 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 s = e + 4 - extlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 }
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
3621 #ifdef MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 * If there is no file name, and the extension starts with '.', put a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 * '_' before the dot, because just ".ext" may be invalid if it's on a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 * FAT partition, and on HPFS it doesn't matter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 else if ((fname == NULL || *fname == NUL) && *ext == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 *s++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 /*
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3632 * Append the extension.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 * ext can start with '.' and cannot exceed 3 more characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 STRCPY(s, ext);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 * Prepend the dot.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 */
15794
0d8291665b59 patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents: 15776
diff changeset
3640 if (prepend_dot && !shortname && *(e = gettail(retval)) != '.')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 {
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1597
diff changeset
3642 STRMOVE(e + 1, e);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 *e = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 * Check that, after appending the extension, the file name is really
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 * different.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 if (fname != NULL && STRCMP(fname, retval) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3652 // we search for a character that can be replaced by '_'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 while (--s >= ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 if (*s != '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 *s = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3661 if (s < ptr) // fname was "________.<ext>", how tricky!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3662 *ptr = 'v';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 * Like fgets(), but if the file line is too long, it is truncated and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 * 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
3670 * If the line is truncated then buf[size - 2] will not be NUL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3673 vim_fgets(char_u *buf, int size, FILE *fp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 char *eof;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 #define FGETS_SIZE 200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677 char tbuf[FGETS_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 buf[size - 2] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 eof = fgets((char *)buf, size, fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 if (buf[size - 2] != NUL && buf[size - 2] != '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3683 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
3684
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3685 // Now throw away the rest of the line:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 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
3689 vim_ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 return (eof == NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 * rename() only works if both files are on the same file system, this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 * function will (attempts to?) copy the file across if rename fails -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 * Return -1 for failure, 0 for success.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3701 vim_rename(char_u *from, char_u *to)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 int fd_in;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 int fd_out;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 char *errmsg = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707 char *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 #ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 BPTR flock;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 #endif
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
3711 stat_T st;
194
5f7701639303 updated for version 7.0058
vimboss
parents: 188
diff changeset
3712 long perm;
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3713 #ifdef HAVE_ACL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3714 vim_acl_T acl; // ACL from original file
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3715 #endif
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3716 int use_tmp_file = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 /*
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3719 * When the names are identical, there is nothing to do. When they refer
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3720 * to the same file (ignoring case and slash/backslash differences) but
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3721 * the file name differs we need to go through a temp file.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 if (fnamecmp(from, to) == 0)
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3724 {
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4232
diff changeset
3725 if (p_fic && STRCMP(gettail(from), gettail(to)) != 0)
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3726 use_tmp_file = TRUE;
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3727 else
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3728 return 0;
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3729 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 * Fail if the "from" file doesn't exist. Avoids that "to" is deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 if (mch_stat((char *)from, &st) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3737 #ifdef UNIX
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3738 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
3739 stat_T st_to;
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3740
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3741 // 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
3742 // 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
3743 // filesystem. In that case go through a temp file name.
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3744 if (mch_stat((char *)to, &st_to) >= 0
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3745 && st.st_dev == st_to.st_dev
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3746 && st.st_ino == st_to.st_ino)
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3747 use_tmp_file = TRUE;
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3748 }
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3749 #endif
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
3750 #ifdef MSWIN
2793
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3751 {
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3752 BY_HANDLE_FILE_INFORMATION info1, info2;
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3753
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3754 // 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
3755 // 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
3756 // "./foo") a no-op (in a complicated way).
2793
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3757 if (win32_fileinfo(from, &info1) == FILEINFO_OK
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3758 && win32_fileinfo(to, &info2) == FILEINFO_OK
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3759 && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3760 && info1.nFileIndexHigh == info2.nFileIndexHigh
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3761 && info1.nFileIndexLow == info2.nFileIndexLow)
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3762 use_tmp_file = TRUE;
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3763 }
ee48b3da9d53 updated for version 7.3.172
Bram Moolenaar <bram@vim.org>
parents: 2770
diff changeset
3764 #endif
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3765
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3766 if (use_tmp_file)
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3767 {
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3768 char tempname[MAXPATHL + 1];
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3769
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3770 /*
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3771 * Find a name that doesn't exist and is in the same directory.
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3772 * Rename "from" to "tempname" and then rename "tempname" to "to".
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3773 */
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3774 if (STRLEN(from) >= MAXPATHL - 5)
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3775 return -1;
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3776 STRCPY(tempname, from);
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3777 for (n = 123; n < 99999; ++n)
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3778 {
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3779 sprintf((char *)gettail((char_u *)tempname), "%d", n);
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3780 if (mch_stat(tempname, &st) < 0)
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3781 {
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3782 if (mch_rename((char *)from, tempname) == 0)
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3783 {
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3784 if (mch_rename(tempname, (char *)to) == 0)
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3785 return 0;
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3786 // 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
3787 // file back and return failure.
24578
096f2b8d9cf4 patch 8.2.2828: Coverity complains about not checking rename() return value
Bram Moolenaar <Bram@vim.org>
parents: 23503
diff changeset
3788 (void)mch_rename(tempname, (char *)from);
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3789 return -1;
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3790 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3791 // 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
3792 // for any temp name, give up.
1779
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3793 return -1;
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3794 }
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3795 }
28e9eb0f2d84 updated for version 7.2-077
vimboss
parents: 1778
diff changeset
3796 return -1;
1778
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3797 }
0b42546f036b updated for version 7.2-076
vimboss
parents: 1757
diff changeset
3798
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 * Delete the "to" file, this is required on some systems to make the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 * mch_rename() work, on other systems it makes sure that we don't have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 * two files when the mch_rename() fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 #ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 * With MSDOS-compatible filesystems (crossdos, messydos) it is possible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 * that the name of the "to" file is the same as the "from" file, even
1201
4d2585cf5950 updated for version 7.1b
vimboss
parents: 1142
diff changeset
3809 * though the names are different. To avoid the chance of accidentally
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810 * deleting the "from" file (horror!) we lock it during the remove.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812 * When used for making a backup before writing the file: This should not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813 * happen with ":w", because startscript() should detect this problem and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 * set buf->b_shortname, causing modname() to return a correct ".bak" file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 * name. This problem does exist with ":w filename", but then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 * original file will be somewhere else so the backup isn't really
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 * important. If autoscripting is off the rename may fail.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 flock = Lock((UBYTE *)from, (long)ACCESS_READ);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 mch_remove(to);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 #ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 if (flock)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 UnLock(flock);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 * First try a normal rename, return if it works.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 if (mch_rename((char *)from, (char *)to) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 * Rename() failed, try copying the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 */
194
5f7701639303 updated for version 7.0058
vimboss
parents: 188
diff changeset
3836 perm = mch_getperm(from);
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3837 #ifdef HAVE_ACL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3838 // For systems that support ACL: get the ACL from the original file.
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3839 acl = mch_get_acl(from);
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3840 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 if (fd_in == -1)
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3843 {
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3844 #ifdef HAVE_ACL
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3845 mch_free_acl(acl);
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3846 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 return -1;
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3848 }
194
5f7701639303 updated for version 7.0058
vimboss
parents: 188
diff changeset
3849
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3850 // Create the new file with same permissions as the original.
557
862863033fdd updated for version 7.0158
vimboss
parents: 550
diff changeset
3851 fd_out = mch_open((char *)to,
862863033fdd updated for version 7.0158
vimboss
parents: 550
diff changeset
3852 O_CREAT|O_EXCL|O_WRONLY|O_EXTRA|O_NOFOLLOW, (int)perm);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3853 if (fd_out == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 close(fd_in);
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3856 #ifdef HAVE_ACL
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3857 mch_free_acl(acl);
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3858 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3861
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3862 buffer = alloc(WRITEBUFSIZE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 {
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3865 close(fd_out);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3866 close(fd_in);
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3867 #ifdef HAVE_ACL
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3868 mch_free_acl(acl);
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3869 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872
18199
e2be5a6485f5 patch 8.1.2094: the fileio.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18139
diff changeset
3873 while ((n = read_eintr(fd_in, buffer, WRITEBUFSIZE)) > 0)
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
3874 if (write_eintr(fd_out, buffer, n) != n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 errmsg = _("E208: Error writing to \"%s\"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 close(fd_in);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 if (close(fd_out) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 errmsg = _("E209: Error closing \"%s\"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 if (n < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 errmsg = _("E210: Error reading \"%s\"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 to = from;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3889 #ifndef UNIX // for Unix mch_open() already set the permission
194
5f7701639303 updated for version 7.0058
vimboss
parents: 188
diff changeset
3890 mch_setperm(to, perm);
570
27d1ec742f17 updated for version 7.0162
vimboss
parents: 567
diff changeset
3891 #endif
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3892 #ifdef HAVE_ACL
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3893 mch_set_acl(to, acl);
1651
9c5a9e4356f8 updated for version 7.2a-003
vimboss
parents: 1620
diff changeset
3894 mch_free_acl(acl);
199
3b32f6b507fa updated for version 7.0059
vimboss
parents: 194
diff changeset
3895 #endif
5788
410ef4f1a3d2 updated for version 7.4.238
Bram Moolenaar <bram@vim.org>
parents: 5704
diff changeset
3896 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK)
5483
9502d1caf90b updated for version 7.4.091
Bram Moolenaar <bram@vim.org>
parents: 5479
diff changeset
3897 mch_copy_sec(from, to);
5479
6707c44cec61 updated for version 7.4.089
Bram Moolenaar <bram@vim.org>
parents: 5322
diff changeset
3898 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899 if (errmsg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3900 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
3901 semsg(errmsg, to);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 mch_remove(from);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 static int already_warned = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3911 * Check if any not hidden buffer has been changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3912 * Postpone the check if there are characters in the stuff buffer, a global
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3913 * command is being executed, a mapping is being executed or an autocommand is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 * busy.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 * Returns TRUE if some message was written (screen should be redrawn and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 * cursor positioned).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3919 check_timestamps(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3920 int focus) // called for GUI focus event
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 int didit = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3926 // 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
3927 // cause us to lose and gain focus.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 if (no_check_timestamps > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3931 // 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
3932 // 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
3933 // Do check again after typing something.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 if (focus && did_check_timestamps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 need_check_timestamps = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 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
3941 || 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
3942 need_check_timestamps = TRUE; // check later
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 ++no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 did_check_timestamps = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 already_warned = FALSE;
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9599
diff changeset
3948 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3950 // Only check buffers in a window.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 if (buf->b_nwindows > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 {
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
3953 bufref_T bufref;
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
3954
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
3955 set_bufref(&bufref, buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 n = buf_check_timestamp(buf, focus);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 if (didit < n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 didit = n;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
3959 if (n > 0 && !bufref_valid(&bufref))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3961 // 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
3962 // first one again.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 buf = firstbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 need_check_timestamps = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 if (need_wait_return && didit == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3972 // 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
3973 msg_puts("\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 return didit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 * Move all the lines from buffer "frombuf" to buffer "tobuf".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 * Return OK or FAIL. When FAIL "tobuf" is incomplete and/or "frombuf" is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 * empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 static int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
3986 move_lines(buf_T *frombuf, buf_T *tobuf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 buf_T *tbuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 int retval = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
3993 // Copy the lines in "frombuf" to "tobuf".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 curbuf = tobuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 if (p == NULL || ml_append(lnum - 1, p, 0, FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4007 // Delete all the lines in "frombuf".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 if (retval != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 curbuf = frombuf;
1055
ef6b11bee7d0 updated for version 7.0-181
vimboss
parents: 1006
diff changeset
4011 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum)
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20311
diff changeset
4012 if (ml_delete(lnum) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4014 // 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
4015 // might fail again...
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 curbuf = tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 * Check if buffer "buf" has been changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 * Also check if the file for a new buffer unexpectedly appeared.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 * return 1 if a changed buffer was found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 * return 2 if a message has been displayed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 * return 0 otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
4033 buf_check_timestamp(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
4034 buf_T *buf,
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4035 int focus UNUSED) // called for GUI focus event
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
4037 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 int stat_res;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 int retval = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 char_u *path;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
4041 char *tbuf;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 char *mesg = NULL;
188
041a413d626d updated for version 7.0057
vimboss
parents: 179
diff changeset
4043 char *mesg2 = "";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 int helpmesg = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 int reload = FALSE;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4046 char *reason;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 int can_reload = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 #endif
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
4050 off_T orig_size = buf->b_orig_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 int orig_mode = buf->b_orig_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 int save_mouse_correct = need_mouse_correct;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 static int busy = FALSE;
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4056 int n;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4057 #ifdef FEAT_EVAL
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4058 char_u *s;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4059 #endif
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4060 bufref_T bufref;
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4061
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4062 set_bufref(&bufref, buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4064 // 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
4065 // 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
4066 // this buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 if (buf->b_ffname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 || 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
4069 || !bt_normal(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 || buf->b_saving
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 || busy
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 26
diff changeset
4072 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 26
diff changeset
4073 || isNetbeansBuffer(buf)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 26
diff changeset
4074 #endif
12064
407a475c67fd patch 8.0.0912: cannot run a job in a hidden terminal
Christian Brabandt <cb@256bit.org>
parents: 11757
diff changeset
4075 #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
4076 || 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
4077 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 if ( !(buf->b_flags & BF_NOTEDITED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 && buf->b_mtime != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 && ((stat_res = mch_stat((char *)buf->b_ffname, &st)) < 0
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4084 || time_differs(&st, buf->b_mtime, buf->b_mtime_ns)
5863
1ee3fc5b40ae updated for version 7.4.274
Bram Moolenaar <bram@vim.org>
parents: 5816
diff changeset
4085 || st.st_size != buf->b_orig_size
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 #ifdef HAVE_ST_MODE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 || (int)st.st_mode != buf->b_orig_mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 || mch_getperm(buf->b_ffname) != buf->b_orig_mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 {
17565
0026ea34a8d5 patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents: 17476
diff changeset
4093 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
4094
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 retval = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096
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
4097 // 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
4098 // FileChangedShell autocmd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 if (stat_res < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 {
16754
8b92f3fea477 patch 8.1.1379: filechanged test hangs
Bram Moolenaar <Bram@vim.org>
parents: 16752
diff changeset
4101 // 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
4102 buf->b_mtime = -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 buf->b_orig_size = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 buf->b_orig_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 buf_store_time(buf, &st, buf->b_ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4109 // 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
4110 // explorer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 if (mch_isdir(buf->b_fname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 * If 'autoread' is set, the buffer has no changes and the file still
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 * exists, reload the buffer. Use the buffer-local option value if it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 * was set, the global option value otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 && !bufIsChanged(buf) && stat_res >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 reload = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 {
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4124 if (stat_res < 0)
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4125 reason = "deleted";
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4126 else if (bufIsChanged(buf))
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4127 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
4128 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
4129 * 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
4130 * 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
4131 * 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
4132 */
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4133 else if (orig_size != buf->b_orig_size || buf_contents_changed(buf))
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4134 reason = "changed";
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4135 else if (orig_mode != buf->b_orig_mode)
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4136 reason = "mode";
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4137 else
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4138 reason = "time";
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4139
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 * Only give the warning if there are no FileChangedShell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 * autocommands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 * Avoid being called recursively by setting "busy".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 busy = TRUE;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4146 #ifdef FEAT_EVAL
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4147 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1);
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4148 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
4149 #endif
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
4150 ++allbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 n = apply_autocmds(EVENT_FILECHANGEDSHELL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 buf->b_fname, buf->b_fname, FALSE, buf);
1834
ccbd8177e1f4 updated for version 7.2-132
vimboss
parents: 1779
diff changeset
4153 --allbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 busy = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 if (n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 {
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4157 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
4158 emsg(_("E246: FileChangedShell autocommand deleted buffer"));
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4159 #ifdef FEAT_EVAL
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4160 s = get_vim_var_str(VV_FCS_CHOICE);
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4161 if (STRCMP(s, "reload") == 0 && *reason != 'd')
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4162 reload = TRUE;
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4163 else if (STRCMP(s, "ask") == 0)
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4164 n = FALSE;
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4165 else
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4166 #endif
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4167 return 2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 }
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4169 if (!n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 {
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4171 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
4172 {
0026ea34a8d5 patch 8.1.1780: warning for file no longer available is repeated
Bram Moolenaar <Bram@vim.org>
parents: 17476
diff changeset
4173 // 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
4174 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
4175 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
4176 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 helpmesg = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 can_reload = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 #endif
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4183 if (reason[2] == 'n')
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4184 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 mesg = _("W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well");
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4186 mesg2 = _("See \":help W12\" for more info.");
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4187 }
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4188 else if (reason[1] == 'h')
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4189 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 mesg = _("W11: Warning: File \"%s\" has changed since editing started");
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4191 mesg2 = _("See \":help W11\" for more info.");
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4192 }
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4193 else if (*reason == 'm')
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4194 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 mesg = _("W16: Warning: Mode of file \"%s\" has changed since editing started");
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4196 mesg2 = _("See \":help W16\" for more info.");
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4197 }
1913
bddda5d8caa1 updated for version 7.2-210
vimboss
parents: 1906
diff changeset
4198 else
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4199 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4200 // 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
4201 // in check_mtime() later.
1913
bddda5d8caa1 updated for version 7.2-210
vimboss
parents: 1906
diff changeset
4202 buf->b_mtime_read = buf->b_mtime;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4203 buf->b_mtime_read_ns = buf->b_mtime_ns;
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4204 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 else if ((buf->b_flags & BF_NEW) && !(buf->b_flags & BF_NEW_W)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 && vim_fexists(buf->b_ffname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 retval = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 mesg = _("W13: Warning: File \"%s\" has been created after editing started");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 buf->b_flags |= BF_NEW_W;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 can_reload = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 if (mesg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 path = home_replace_save(buf, buf->b_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 if (path != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 {
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 177
diff changeset
4226 if (!helpmesg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 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
4228 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
4229 sprintf(tbuf, mesg, path);
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1836
diff changeset
4230 #ifdef FEAT_EVAL
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4231 // 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
4232 // 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
4233 set_vim_var_string(VV_WARNINGMSG, (char_u *)tbuf, -1);
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1836
diff changeset
4234 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 if (can_reload)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 if (*mesg2 != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 STRCAT(tbuf, "\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 STRCAT(tbuf, mesg2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 }
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
4243 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
4244 (char_u *)tbuf,
2684
951641b8784d updated for version 7.3.102
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
4245 (char_u *)_("&OK\n&Load File"), 1, NULL, TRUE) == 2)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 reload = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 if (State > NORMAL_BUSY || (State & CMDLINE) || already_warned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 if (*mesg2 != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 STRCAT(tbuf, "; ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 STRCAT(tbuf, mesg2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256 }
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
4257 emsg(tbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 retval = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 if (!autocmd_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 msg_start();
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15531
diff changeset
4265 msg_puts_attr(tbuf, HL_ATTR(HLF_E) + MSG_HIST);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 if (*mesg2 != NUL)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15531
diff changeset
4267 msg_puts_attr(mesg2, HL_ATTR(HLF_W) + MSG_HIST);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 (void)msg_end();
22742
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
4270 if (emsg_silent == 0 && !in_assert_fails)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 out_flush();
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4273 #ifdef FEAT_GUI
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 if (!focus)
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4275 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4276 // 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
4277 ui_delay(1004L, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4279 // don't redraw and erase the message
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 redraw_cmdline = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283 already_warned = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 vim_free(path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 vim_free(tbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 if (reload)
3776
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4292 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4293 // Reload the buffer.
628
efb7557aea10 updated for version 7.0181
vimboss
parents: 625
diff changeset
4294 buf_reload(buf, orig_mode);
3776
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4295 #ifdef FEAT_PERSISTENT_UNDO
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4296 if (buf->b_p_udf && buf->b_ffname != NULL)
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4297 {
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4298 char_u hash[UNDO_HASH_SIZE];
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4299 buf_T *save_curbuf = curbuf;
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4300
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4301 // Any existing undo file is unusable, write it now.
3776
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4302 curbuf = buf;
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4303 u_compute_hash(hash);
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4304 u_write_undo(NULL, FALSE, buf, hash);
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4305 curbuf = save_curbuf;
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4306 }
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4307 #endif
e70485d3f81d updated for version 7.3.646
Bram Moolenaar <bram@vim.org>
parents: 3676
diff changeset
4308 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4310 // 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
4311 if (bufref_valid(&bufref) && retval != 0)
765
335444c09581 updated for version 7.0225
vimboss
parents: 723
diff changeset
4312 (void)apply_autocmds(EVENT_FILECHANGEDSHELLPOST,
335444c09581 updated for version 7.0225
vimboss
parents: 723
diff changeset
4313 buf->b_fname, buf->b_fname, FALSE, buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314 #ifdef FEAT_GUI
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4315 // 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
4316 // 'mousefocus'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 need_mouse_correct = save_mouse_correct;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4323 /*
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4324 * Reload a buffer that is already loaded.
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4325 * Used when the file was changed outside of Vim.
628
efb7557aea10 updated for version 7.0181
vimboss
parents: 625
diff changeset
4326 * "orig_mode" is buf->b_orig_mode before the need for reloading was detected.
efb7557aea10 updated for version 7.0181
vimboss
parents: 625
diff changeset
4327 * buf->b_orig_mode may have been reset already.
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4328 */
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4329 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
4330 buf_reload(buf_T *buf, int orig_mode)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4331 {
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4332 exarg_T ea;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4333 pos_T old_cursor;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4334 linenr_T old_topline;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4335 int old_ro = buf->b_p_ro;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4336 buf_T *savebuf;
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4337 bufref_T bufref;
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4338 int saved = OK;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4339 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
4340 int flags = READ_NEW;
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4341
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4342 // set curwin/curbuf for "buf" and save some things
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4343 aucmd_prepbuf(&aco, buf);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4344
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4345 // 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
4346 // 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
4347 // and encoding to be the same.
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4348 if (prep_exarg(&ea, buf) == OK)
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4349 {
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4350 old_cursor = curwin->w_cursor;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4351 old_topline = curwin->w_topline;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4352
2482
88751831fa0a When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents: 2410
diff changeset
4353 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
4354 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4355 // 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
4356 // 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
4357 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
4358 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
4359 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
4360 }
a3aca345aafa Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents: 2360
diff changeset
4361
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4362 /*
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4363 * To behave like when a new file is edited (matters for
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4364 * BufReadPost autocommands) we first need to delete the current
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4365 * buffer contents. But if reading the file fails we should keep
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4366 * the old contents. Can't use memory only, the file might be
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4367 * too big. Use a hidden buffer to move the buffer contents to.
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4368 */
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
4369 if (BUFEMPTY() || saved == FAIL)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4370 savebuf = NULL;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4371 else
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4372 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4373 // Allocate a buffer without putting it in the buffer list.
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4374 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
4375 set_bufref(&bufref, savebuf);
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
4376 if (savebuf != NULL && buf == curbuf)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4377 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4378 // Open the memline.
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4379 curbuf = savebuf;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4380 curwin->w_buffer = savebuf;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 622
diff changeset
4381 saved = ml_open(curbuf);
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4382 curbuf = buf;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4383 curwin->w_buffer = buf;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4384 }
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
4385 if (savebuf == NULL || saved == FAIL || buf != curbuf
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4386 || move_lines(buf, savebuf) == FAIL)
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4387 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
4388 semsg(_("E462: Could not prepare for reloading \"%s\""),
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4389 buf->b_fname);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4390 saved = FAIL;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4391 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4392 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4393
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4394 if (saved == OK)
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4395 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4396 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
4397 keep_filetype = TRUE; // don't detect 'filetype'
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4398 if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0,
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4399 (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
4400 (linenr_T)MAXLNUM, &ea, flags) != OK)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4401 {
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
4402 #if defined(FEAT_EVAL)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4403 if (!aborting())
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4404 #endif
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
4405 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
4406 if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4407 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4408 // 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
4409 // 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
4410 while (!BUFEMPTY())
20599
d571231175b4 patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents: 20311
diff changeset
4411 if (ml_delete(buf->b_ml.ml_line_count) == FAIL)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4412 break;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4413 (void)move_lines(savebuf, buf);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4414 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4415 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4416 else if (buf == curbuf) // "buf" still valid
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4417 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4418 // 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
4419 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
4420 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
4421 {
a3aca345aafa Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents: 2360
diff changeset
4422 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
4423 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
4424 }
a3aca345aafa Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents: 2360
diff changeset
4425 else
2482
88751831fa0a When undoing a reload, move the cursor to the first changed line.
Bram Moolenaar <bram@vim.org>
parents: 2410
diff changeset
4426 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4427 // 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
4428 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
4429 }
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4430 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4431 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4432 vim_free(ea.cmd);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4433
9487
69ed2c9d34a6 commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents: 9391
diff changeset
4434 if (savebuf != NULL && bufref_valid(&bufref))
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4435 wipe_buffer(savebuf, FALSE);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4436
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4437 #ifdef FEAT_DIFF
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4438 // Invalidate diff info if necessary.
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
4439 diff_invalidate(curbuf);
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4440 #endif
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4441
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4442 // 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
4443 // have been removed).
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4444 if (old_topline > curbuf->b_ml.ml_line_count)
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4445 curwin->w_topline = curbuf->b_ml.ml_line_count;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4446 else
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4447 curwin->w_topline = old_topline;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4448 curwin->w_cursor = old_cursor;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4449 check_cursor();
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4450 update_topline();
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4451 keep_filetype = FALSE;
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4452 #ifdef FEAT_FOLDING
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4453 {
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
4454 win_T *wp;
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
4455 tabpage_T *tp;
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4456
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4457 // Update folds unless they are defined manually.
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
4458 FOR_ALL_TAB_WINDOWS(tp, wp)
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4459 if (wp->w_buffer == curwin->w_buffer
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4460 && !foldmethodIsManual(wp))
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4461 foldUpdateAll(wp);
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4462 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4463 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4464 // 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
4465 // 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
4466 // reset it, might have had a read error.
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4467 if (orig_mode == curbuf->b_orig_mode)
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4468 curbuf->b_p_ro |= old_ro;
4071
8819ea6dcb72 updated for version 7.3.790
Bram Moolenaar <bram@vim.org>
parents: 3997
diff changeset
4469
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4470 // Modelines must override settings done by autocommands.
4071
8819ea6dcb72 updated for version 7.3.790
Bram Moolenaar <bram@vim.org>
parents: 3997
diff changeset
4471 do_modelines(0);
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4472 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4473
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4474 // restore curwin/curbuf and a few other things
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4475 aucmd_restbuf(&aco);
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4476 // Careful: autocommands may have made "buf" invalid!
311
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4477 }
33c6fb10dd66 updated for version 7.0082
vimboss
parents: 301
diff changeset
4478
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 void
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
4480 buf_store_time(buf_T *buf, stat_T *st, char_u *fname UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 buf->b_mtime = (long)st->st_mtime;
25953
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4483 #ifdef ST_MTIM_NSEC
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4484 buf->b_mtime_ns = (long)st->ST_MTIM_NSEC;
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4485 #else
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4486 buf->b_mtime_ns = 0;
d7e1cf30728c patch 8.2.3510: changes are only detected with one second accuracy
Bram Moolenaar <Bram@vim.org>
parents: 25838
diff changeset
4487 #endif
2241
60da25e3aab7 Correct use of long instead of off_t for file size. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
4488 buf->b_orig_size = st->st_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 #ifdef HAVE_ST_MODE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 buf->b_orig_mode = (int)st->st_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 buf->b_orig_mode = mch_getperm(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 * Adjust the line with missing eol, used for the next write.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 * Used for do_filter(), when the input lines for the filter are deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
4501 write_lnum_adjust(linenr_T offset)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
4503 if (curbuf->b_no_eol_lnum != 0) // only if there is a missing eol
2707
cd3f52531f6c updated for version 7.3.124
Bram Moolenaar <bram@vim.org>
parents: 2697
diff changeset
4504 curbuf->b_no_eol_lnum += offset;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4507 // Subfuncions for readdirex()
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4508 #ifdef FEAT_EVAL
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4509 # ifdef MSWIN
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4510 static char_u *
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4511 getfpermwfd(WIN32_FIND_DATAW *wfd, char_u *perm)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4512 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4513 stat_T st;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4514 unsigned short st_mode;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4515 DWORD flag = wfd->dwFileAttributes;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4516 WCHAR *wp;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4517
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4518 st_mode = (flag & FILE_ATTRIBUTE_DIRECTORY)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4519 ? (_S_IFDIR | _S_IEXEC) : _S_IFREG;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4520 st_mode |= (flag & FILE_ATTRIBUTE_READONLY)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4521 ? _S_IREAD : (_S_IREAD | _S_IWRITE);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4522
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4523 wp = wcsrchr(wfd->cFileName, L'.');
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4524 if (wp != NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4525 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4526 if (_wcsicmp(wp, L".exe") == 0 ||
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4527 _wcsicmp(wp, L".com") == 0 ||
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4528 _wcsicmp(wp, L".cmd") == 0 ||
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4529 _wcsicmp(wp, L".bat") == 0)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4530 st_mode |= _S_IEXEC;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4531 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4532
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4533 // Copy user bits to group/other.
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4534 st_mode |= (st_mode & 0700) >> 3;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4535 st_mode |= (st_mode & 0700) >> 6;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4536
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4537 st.st_mode = st_mode;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4538 return getfpermst(&st, perm);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4539 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4540
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4541 static char_u *
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4542 getftypewfd(WIN32_FIND_DATAW *wfd)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4543 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4544 DWORD flag = wfd->dwFileAttributes;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4545 DWORD tag = wfd->dwReserved0;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4546
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4547 if (flag & FILE_ATTRIBUTE_REPARSE_POINT)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4548 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4549 if (tag == IO_REPARSE_TAG_MOUNT_POINT)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4550 return (char_u*)"junction";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4551 else if (tag == IO_REPARSE_TAG_SYMLINK)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4552 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4553 if (flag & FILE_ATTRIBUTE_DIRECTORY)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4554 return (char_u*)"linkd";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4555 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4556 return (char_u*)"link";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4557 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4558 return (char_u*)"reparse"; // unknown reparse point type
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4559 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4560 if (flag & FILE_ATTRIBUTE_DIRECTORY)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4561 return (char_u*)"dir";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4562 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4563 return (char_u*)"file";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4564 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4565
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4566 static dict_T *
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4567 create_readdirex_item(WIN32_FIND_DATAW *wfd)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4568 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4569 dict_T *item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4570 char_u *p;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4571 varnumber_T size, time;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4572 char_u permbuf[] = "---------";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4573
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4574 item = dict_alloc();
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4575 if (item == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4576 return NULL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4577 item->dv_refcount++;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4578
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4579 p = utf16_to_enc(wfd->cFileName, NULL);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4580 if (p == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4581 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4582 if (dict_add_string(item, "name", p) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4583 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4584 vim_free(p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4585 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4586 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4587 vim_free(p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4588
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4589 size = (((varnumber_T)wfd->nFileSizeHigh) << 32) | wfd->nFileSizeLow;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4590 if (dict_add_number(item, "size", size) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4591 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4592
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4593 // Convert FILETIME to unix time.
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4594 time = (((((varnumber_T)wfd->ftLastWriteTime.dwHighDateTime) << 32) |
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4595 wfd->ftLastWriteTime.dwLowDateTime)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4596 - 116444736000000000) / 10000000;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4597 if (dict_add_number(item, "time", time) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4598 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4599
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4600 if (dict_add_string(item, "type", getftypewfd(wfd)) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4601 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4602 if (dict_add_string(item, "perm", getfpermwfd(wfd, permbuf)) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4603 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4604
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4605 if (dict_add_string(item, "user", (char_u*)"") == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4606 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4607 if (dict_add_string(item, "group", (char_u*)"") == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4608 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4609
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4610 return item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4611
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4612 theend:
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4613 dict_unref(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4614 return NULL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4615 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4616 # else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4617 static dict_T *
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4618 create_readdirex_item(char_u *path, char_u *name)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4619 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4620 dict_T *item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4621 char *p;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4622 size_t len;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4623 stat_T st;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4624 int ret, link = FALSE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4625 varnumber_T size;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4626 char_u permbuf[] = "---------";
20790
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4627 char_u *q = NULL;
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4628 struct passwd *pw;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4629 struct group *gr;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4630
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4631 item = dict_alloc();
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4632 if (item == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4633 return NULL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4634 item->dv_refcount++;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4635
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4636 len = STRLEN(path) + 1 + STRLEN(name) + 1;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4637 p = alloc(len);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4638 if (p == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4639 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4640 vim_snprintf(p, len, "%s/%s", path, name);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4641 ret = mch_lstat(p, &st);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4642 if (ret >= 0 && S_ISLNK(st.st_mode))
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4643 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4644 link = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4645 ret = mch_stat(p, &st);
20790
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4646 if (ret < 0)
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4647 q = (char_u*)"link";
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4648
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4649 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4650 vim_free(p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4651
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4652 if (dict_add_string(item, "name", name) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4653 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4654
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4655 if (ret >= 0)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4656 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4657 size = (varnumber_T)st.st_size;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4658 if (S_ISDIR(st.st_mode))
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4659 size = 0;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4660 // non-perfect check for overflow
20669
2407ffaefc02 patch 8.2.0888: readdirex() returns size -2 for a directory
Bram Moolenaar <Bram@vim.org>
parents: 20643
diff changeset
4661 else if ((off_T)size != (off_T)st.st_size)
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4662 size = -2;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4663 if (dict_add_number(item, "size", size) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4664 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4665 if (dict_add_number(item, "time", (varnumber_T)st.st_mtime) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4666 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4667
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4668 if (link)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4669 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4670 if (S_ISDIR(st.st_mode))
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4671 q = (char_u*)"linkd";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4672 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4673 q = (char_u*)"link";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4674 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4675 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4676 q = getftypest(&st);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4677 if (dict_add_string(item, "type", q) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4678 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4679 if (dict_add_string(item, "perm", getfpermst(&st, permbuf)) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4680 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4681
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4682 pw = getpwuid(st.st_uid);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4683 if (pw == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4684 q = (char_u*)"";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4685 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4686 q = (char_u*)pw->pw_name;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4687 if (dict_add_string(item, "user", q) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4688 goto theend;
23503
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
4689 # if !defined(VMS) || (defined(VMS) && defined(HAVE_XOS_R_H))
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4690 gr = getgrgid(st.st_gid);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4691 if (gr == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4692 q = (char_u*)"";
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4693 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4694 q = (char_u*)gr->gr_name;
23503
49d866e9b439 patch 8.2.2294: VMS: a few remaining problems
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
4695 # endif
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4696 if (dict_add_string(item, "group", q) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4697 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4698 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4699 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4700 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4701 if (dict_add_number(item, "size", -1) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4702 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4703 if (dict_add_number(item, "time", -1) == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4704 goto theend;
20790
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4705 if (dict_add_string(item, "type", q == NULL ? (char_u*)"" : q) == FAIL)
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4706 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4707 if (dict_add_string(item, "perm", (char_u*)"") == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4708 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4709 if (dict_add_string(item, "user", (char_u*)"") == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4710 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4711 if (dict_add_string(item, "group", (char_u*)"") == FAIL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4712 goto theend;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4713 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4714 return item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4715
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4716 theend:
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4717 dict_unref(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4718 return NULL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4719 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4720 # endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4721
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4722 static int
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4723 compare_readdirex_item(const void *p1, const void *p2)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4724 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4725 char_u *name1, *name2;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4726
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4727 name1 = dict_get_string(*(dict_T**)p1, (char_u*)"name", FALSE);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4728 name2 = dict_get_string(*(dict_T**)p2, (char_u*)"name", FALSE);
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4729 if (readdirex_sort == READDIR_SORT_BYTE)
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4730 return STRCMP(name1, name2);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4731 else if (readdirex_sort == READDIR_SORT_IC)
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4732 return STRICMP(name1, name2);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4733 else
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4734 return STRCOLL(name1, name2);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4735 }
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4736
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4737 static int
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4738 compare_readdir_item(const void *s1, const void *s2)
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4739 {
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4740 if (readdirex_sort == READDIR_SORT_BYTE)
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4741 return STRCMP(*(char **)s1, *(char **)s2);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4742 else if (readdirex_sort == READDIR_SORT_IC)
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4743 return STRICMP(*(char **)s1, *(char **)s2);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4744 else
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4745 return STRCOLL(*(char **)s1, *(char **)s2);
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4746 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4747 #endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4748
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4749 #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
4750 /*
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4751 * Core part of "readdir()" and "readdirex()" function.
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4752 * Retrieve the list of files/directories of "path" into "gap".
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4753 * If "withattr" is TRUE, retrieve the names and their attributes.
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4754 * If "withattr" is FALSE, retrieve the names only.
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4755 * 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
4756 */
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
4757 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
4758 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
4759 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
4760 char_u *path,
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4761 int withattr UNUSED,
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4762 void *context,
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4763 int (*checkitem)(void *context, void *item),
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4764 int sort)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4765 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4766 int failed = FALSE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4767 char_u *p;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4768 # ifdef MSWIN
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4769 char_u *buf;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4770 int ok;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4771 HANDLE hFind = INVALID_HANDLE_VALUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4772 WIN32_FIND_DATAW wfd;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4773 WCHAR *wn = NULL; // UTF-16 name, NULL when not used.
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4774 # else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4775 DIR *dirp;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4776 struct dirent *dp;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4777 # endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4778
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4779 ga_init2(gap, (int)sizeof(void *), 20);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4780
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4781 # ifdef FEAT_EVAL
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4782 # define FREE_ITEM(item) do { \
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4783 if (withattr) \
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4784 dict_unref((dict_T*)item); \
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4785 else \
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4786 vim_free(item); \
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4787 } while (0)
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4788
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4789 readdirex_sort = READDIR_SORT_BYTE;
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4790 # else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4791 # define FREE_ITEM(item) vim_free(item)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4792 # endif
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4793
19301
80baa37506d0 patch 8.2.0209: function a bit far away from where it's used
Bram Moolenaar <Bram@vim.org>
parents: 18896
diff changeset
4794 # ifdef MSWIN
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4795 buf = alloc(MAXPATHL);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4796 if (buf == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4797 return FAIL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4798 STRNCPY(buf, path, MAXPATHL-5);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4799 p = buf + STRLEN(buf);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4800 MB_PTR_BACK(buf, p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4801 if (*p == '\\' || *p == '/')
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4802 *p = NUL;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4803 STRCAT(p, "\\*");
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4804
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4805 wn = enc_to_utf16(buf, NULL);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4806 if (wn != NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4807 hFind = FindFirstFileW(wn, &wfd);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4808 ok = (hFind != INVALID_HANDLE_VALUE);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4809 if (!ok)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4810 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4811 failed = TRUE;
22568
fdc72bf4de35 patch 8.2.1832: readdirex() error is displayed as a message
Bram Moolenaar <Bram@vim.org>
parents: 22490
diff changeset
4812 semsg(_(e_notopen), path);
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4813 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4814 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4815 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4816 while (ok)
19526
22f0dda71638 patch 8.2.0320: no Haiku support
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
4817 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4818 int ignore;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4819 void *item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4820 WCHAR *wp;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4821
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4822 wp = wfd.cFileName;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4823 ignore = wp[0] == L'.' &&
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4824 (wp[1] == NUL ||
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4825 (wp[1] == L'.' && wp[2] == NUL));
20790
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4826 if (ignore)
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4827 {
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4828 ok = FindNextFileW(hFind, &wfd);
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4829 continue;
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4830 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4831 # ifdef FEAT_EVAL
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4832 if (withattr)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4833 item = (void*)create_readdirex_item(&wfd);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4834 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4835 # endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4836 item = (void*)utf16_to_enc(wfd.cFileName, NULL);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4837 if (item == NULL)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4838 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4839 failed = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4840 break;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4841 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4842
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4843 if (!ignore && checkitem != NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4844 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4845 int r = checkitem(context, item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4846
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4847 if (r < 0)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4848 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4849 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4850 break;
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4851 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4852 if (r == 0)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4853 ignore = TRUE;
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4854 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4855
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4856 if (!ignore)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4857 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4858 if (ga_grow(gap, 1) == OK)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4859 ((void**)gap->ga_data)[gap->ga_len++] = item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4860 else
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4861 {
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4862 failed = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4863 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4864 break;
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4865 }
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
4866 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4867 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4868 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4869
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4870 ok = FindNextFileW(hFind, &wfd);
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4871 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4872 FindClose(hFind);
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4873 }
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4874
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4875 vim_free(buf);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4876 vim_free(wn);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4877 # else // MSWIN
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4878 dirp = opendir((char *)path);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4879 if (dirp == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4880 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4881 failed = TRUE;
22568
fdc72bf4de35 patch 8.2.1832: readdirex() error is displayed as a message
Bram Moolenaar <Bram@vim.org>
parents: 22490
diff changeset
4882 semsg(_(e_notopen), path);
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4883 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4884 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4885 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4886 for (;;)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4887 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4888 int ignore;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4889 void *item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4890
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4891 dp = readdir(dirp);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4892 if (dp == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4893 break;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4894 p = (char_u *)dp->d_name;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4895
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4896 ignore = p[0] == '.' &&
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4897 (p[1] == NUL ||
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4898 (p[1] == '.' && p[2] == NUL));
20790
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4899 if (ignore)
5a9c42c6a69e patch 8.2.0947: readdirex() doesn't handle broken link properly
Bram Moolenaar <Bram@vim.org>
parents: 20669
diff changeset
4900 continue;
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4901 # ifdef FEAT_EVAL
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4902 if (withattr)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4903 item = (void*)create_readdirex_item(path, p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4904 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4905 # endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4906 item = (void*)vim_strsave(p);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4907 if (item == NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4908 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4909 failed = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4910 break;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4911 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4912
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4913 if (!ignore && checkitem != NULL)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4914 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4915 int r = checkitem(context, item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4916
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4917 if (r < 0)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4918 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4919 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4920 break;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4921 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4922 if (r == 0)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4923 ignore = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4924 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4925
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4926 if (!ignore)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4927 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4928 if (ga_grow(gap, 1) == OK)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4929 ((void**)gap->ga_data)[gap->ga_len++] = item;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4930 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4931 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4932 failed = TRUE;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4933 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4934 break;
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4935 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4936 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4937 else
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4938 FREE_ITEM(item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4939 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4940
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4941 closedir(dirp);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4942 }
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4943 # endif // MSWIN
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4944
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4945 # undef FREE_ITEM
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4946
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4947 if (!failed && gap->ga_len > 0 && sort > READDIR_SORT_NONE)
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4948 {
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4949 # ifdef FEAT_EVAL
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4950 readdirex_sort = sort;
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4951 if (withattr)
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4952 qsort((void*)gap->ga_data, (size_t)gap->ga_len, sizeof(dict_T*),
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4953 compare_readdirex_item);
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4954 else
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4955 qsort((void*)gap->ga_data, (size_t)gap->ga_len, sizeof(char_u *),
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4956 compare_readdir_item);
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4957 # else
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4958 sort_strings((char_u **)gap->ga_data, gap->ga_len);
20643
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4959 # endif
c2beb6baa42c patch 8.2.0875: getting attributes for directory entries is slow
Bram Moolenaar <Bram@vim.org>
parents: 20599
diff changeset
4960 }
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
4961
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
4962 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
4963 }
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
4964
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
4965 /*
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4966 * 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
4967 * 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
4968 */
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4969 int
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4970 delete_recursive(char_u *name)
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4971 {
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4972 int result = 0;
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4973 int i;
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4974 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
4975 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
4976
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4977 // 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
4978 // points to.
7629
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
4979 if (
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
4980 # if defined(UNIX) || defined(MSWIN)
7657
9c5e8254ea6b commit https://github.com/vim/vim/commit/203258c3ad2966cc9d08b3805b103333988b30b7
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
4981 mch_isrealdir(name)
7629
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
4982 # else
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
4983 mch_isdir(name)
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
4984 # endif
befbed72da87 commit https://github.com/vim/vim/commit/43a34f9f74fdce462fa250baab620264c28b6165
Christian Brabandt <cb@256bit.org>
parents: 7615
diff changeset
4985 )
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4986 {
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
4987 exp = vim_strsave(name);
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4988 if (exp == NULL)
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4989 return -1;
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
4990 if (readdir_core(&ga, exp, FALSE, NULL, NULL, READDIR_SORT_NONE) == OK)
16752
e2d8d83e6721 patch 8.1.1378: delete() can not handle a file name that looks like a pattern
Bram Moolenaar <Bram@vim.org>
parents: 16744
diff changeset
4991 {
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
4992 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
4993 {
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
4994 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
4995 ((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
4996 if (delete_recursive(NameBuff) != 0)
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
4997 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
4998 }
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
4999 ga_clear_strings(&ga);
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5000 }
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5001 else
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5002 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
5003 (void)mch_rmdir(exp);
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5004 vim_free(exp);
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5005 }
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5006 else
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5007 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
5008
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5009 return result;
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5010 }
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5011 #endif
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5012
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 #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
5014 static long temp_count = 0; // Temp filename counter.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015
20311
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5016 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5017 /*
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5018 * Open temporary directory and take file lock to prevent
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5019 * to be auto-cleaned.
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5020 */
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5021 static void
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5022 vim_opentempdir(void)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5023 {
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5024 DIR *dp = NULL;
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5025
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5026 if (vim_tempdir_dp != NULL)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5027 return;
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5028
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5029 dp = opendir((const char*)vim_tempdir);
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5030
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5031 if (dp != NULL)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5032 {
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5033 vim_tempdir_dp = dp;
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5034 flock(dirfd(vim_tempdir_dp), LOCK_SH);
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5035 }
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5036 }
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5037
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5038 /*
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5039 * Close temporary directory - it automatically release file lock.
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5040 */
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5041 static void
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5042 vim_closetempdir(void)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5043 {
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5044 if (vim_tempdir_dp != NULL)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5045 {
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5046 closedir(vim_tempdir_dp);
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5047 vim_tempdir_dp = NULL;
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5048 }
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5049 }
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5050 # endif
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5051
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053 * Delete the temp directory and all files it contains.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5056 vim_deltempdir(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 if (vim_tempdir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 {
20311
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5060 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5061 vim_closetempdir();
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5062 # endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5063 // remove the trailing path separator
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5064 gettail(vim_tempdir)[-1] = NUL;
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5065 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
5066 VIM_CLEAR(vim_tempdir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 }
7615
228ff048db20 commit https://github.com/vim/vim/commit/da440d21a6b94d7f525fa7be9b1417c78dd9aa4c
Christian Brabandt <cb@256bit.org>
parents: 7410
diff changeset
5069
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 /*
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5071 * Directory "tempdir" was created. Expand this name to a full path and put
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5072 * it in "vim_tempdir". This avoids that using ":cd" would confuse us.
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5073 * "tempdir" must be no longer than MAXPATHL.
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5074 */
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5075 static void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5076 vim_settempdir(char_u *tempdir)
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5077 {
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5078 char_u *buf;
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5079
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16754
diff changeset
5080 buf = alloc(MAXPATHL + 2);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5081 if (buf != NULL)
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5082 {
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5083 if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL)
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5084 STRCPY(buf, tempdir);
9536
b2aada04d84e commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents: 9509
diff changeset
5085 add_pathsep(buf);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5086 vim_tempdir = vim_strsave(buf);
20311
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5087 # if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5088 vim_opentempdir();
05b4efb062a7 patch 8.2.0711: temp directory might be cleared
Bram Moolenaar <Bram@vim.org>
parents: 19836
diff changeset
5089 # endif
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5090 vim_free(buf);
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5091 }
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5092 }
2006
78e032bb3260 updated for version 7.2-303
vimboss
parents: 2003
diff changeset
5093 #endif
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5094
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5095 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 * vim_tempname(): Return a unique name that can be used for a temp file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 *
9291
bff3cd5cf922 commit https://github.com/vim/vim/commit/76ae22fef3cb224ca7fbf97517f881e825d4d0c2
Christian Brabandt <cb@256bit.org>
parents: 9260
diff changeset
5098 * 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
5099 * guaranteed to NOT be created.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 * The returned pointer is to allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 * The returned pointer is NULL if no valid name was found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5105 vim_tempname(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5106 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
5107 int keep UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 #ifdef USE_TMPNAM
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5110 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
5111 #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
5112 WCHAR itmp[TEMPNAMELEN];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 char_u itmp[TEMPNAMELEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 #ifdef TEMPDIRNAMES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5118 static char *(tempdirs[]) = {TEMPDIRNAMES};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 # ifndef EEXIST
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9291
diff changeset
5121 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 * This will create a directory for private use by this instance of Vim.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 * This is done once, and the same directory is used for all temp files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 * This method avoids security problems because of symlink attacks et al.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128 * It's also a bit faster, because we only need to check for an existing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 * file when creating the directory and not for each temp file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131 if (vim_tempdir == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 * Try the entries in TEMPDIRNAMES to create the temp directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 */
24768
7334bf933510 patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents: 24578
diff changeset
5136 for (i = 0; i < (int)ARRAY_LENGTH(tempdirs); ++i)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 {
2047
85da03763130 updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents: 2028
diff changeset
5138 # ifndef HAVE_MKDTEMP
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5139 size_t itmplen;
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5140 long nr;
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5141 long off;
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5142 # endif
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5143
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5144 // 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
5145 // Skip the directory check if the expansion fails.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 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
5147 if (itmp[0] != '$' && mch_isdir(itmp))
372c785c04b6 commit https://github.com/vim/vim/commit/e1a61991d9b6fd5f65636d17583f93118268cda5
Christian Brabandt <cb@256bit.org>
parents: 7285
diff changeset
5148 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5149 // directory exists
9536
b2aada04d84e commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents: 9509
diff changeset
5150 add_pathsep(itmp);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5151
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5152 # ifdef HAVE_MKDTEMP
9211
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5153 {
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5154 # 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
5155 // 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
5156 // "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
5157 mode_t umask_save = umask(077);
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5158 # endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5159 // Leave room for filename
9211
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5160 STRCAT(itmp, "vXXXXXX");
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5161 if (mkdtemp((char *)itmp) != NULL)
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5162 vim_settempdir(itmp);
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5163 # if defined(UNIX) || defined(VMS)
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5164 (void)umask(umask_save);
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5165 # endif
d2b9e454c73d commit https://github.com/vim/vim/commit/35d88f4e2ff5dcd9904f04612d5febede996137c
Christian Brabandt <cb@256bit.org>
parents: 9068
diff changeset
5166 }
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5167 # else
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5168 // 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
5169 // 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
5170 // 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
5171 // security problems because of the predictable number.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172 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
5173 itmplen = STRLEN(itmp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5175 // 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
5176 // doesn't exist.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 for (off = 0; off < 10000L; ++off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5179 int r;
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5180 # if defined(UNIX) || defined(VMS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 mode_t umask_save;
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5182 # endif
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5183
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5184 sprintf((char *)itmp + itmplen, "v%ld", nr + off);
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5185 # ifndef EEXIST
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5186 // 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
5187 // 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
5188 // although it's fail-safe.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 if (mch_stat((char *)itmp, &st) >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 continue;
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5191 # endif
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5192 # 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
5193 // 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
5194 // "repl" has been reported to use "177".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 umask_save = umask(077);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5196 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 r = vim_mkdir(itmp, 0700);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5198 # if defined(UNIX) || defined(VMS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 (void)umask(umask_save);
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5200 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 if (r == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 {
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5203 vim_settempdir(itmp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 }
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5206 # ifdef EEXIST
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5207 // 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
5208 // 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
5209 // place.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 if (errno != EEXIST)
1997
1f53050b3868 updated for version 7.2-294
vimboss
parents: 1962
diff changeset
5211 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 }
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5214 # endif // HAVE_MKDTEMP
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 if (vim_tempdir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 if (vim_tempdir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5223 // 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
5224 // directory and nobody else creates a file in it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 return vim_strsave(itmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5231 #else // TEMPDIRNAMES
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
5233 # 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
5234 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
5235 WCHAR buf4[4];
23017
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5236 WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 char_u *p;
25084
beff72446e2e patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents: 25068
diff changeset
5239 char_u *shname;
23017
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5240 long i;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241
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
5242 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
5243 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
5244 {
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5245 wszTempFile[0] = L'.'; // GetTempPathW() failed, use current dir
23017
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5246 wszTempFile[1] = L'\\';
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5247 wszTempFile[2] = NUL;
15776
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5248 }
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5249 wcscpy(buf4, L"VIM");
23017
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5250
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5251 // randomize the name to avoid collisions
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5252 i = mch_get_pid() + extra_char;
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5253 buf4[1] = chartab[i % 36];
d80faed40bec patch 8.2.2055: MS-Windows: two Vim instances may use the same temp file
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
5254 buf4[2] = chartab[101 * i % 36];
15776
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5255 if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 return NULL;
6721
7347229a646a updated for version 7.4.684
Bram Moolenaar <bram@vim.org>
parents: 6635
diff changeset
5257 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
5258 // 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
5259 (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
5260
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5261 // 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
5262 // "sh". NOTE: This also checks 'shellcmdflag' to help those people who
25068
0ce24f734615 patch 8.2.3071: shell options are not set properly for PowerShell
Bram Moolenaar <Bram@vim.org>
parents: 25052
diff changeset
5263 // didn't set 'shellslash' but only if not using PowerShell.
15776
7f91de3f5e35 patch 8.1.0895: MS-Windows: dealing with temp name encoding not quite right
Bram Moolenaar <Bram@vim.org>
parents: 15750
diff changeset
5264 retval = utf16_to_enc(itmp, NULL);
25084
beff72446e2e patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents: 25068
diff changeset
5265 shname = gettail(p_sh);
beff72446e2e patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents: 25068
diff changeset
5266 if ((*p_shcf == '-' && !(strstr((char *)shname, "powershell") != NULL
beff72446e2e patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents: 25068
diff changeset
5267 || strstr((char *)shname, "pwsh") != NULL ))
beff72446e2e patch 8.2.3079: Powershell core not supported by default
Bram Moolenaar <Bram@vim.org>
parents: 25068
diff changeset
5268 || p_ssl)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 for (p = retval; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 if (*p == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271 *p = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273
15868
7fad90423bd2 patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15840
diff changeset
5274 # else // MSWIN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 # ifdef USE_TMPNAM
2697
6cc8a093e4a9 updated for version 7.3.115
Bram Moolenaar <bram@vim.org>
parents: 2695
diff changeset
5277 char_u *p;
6cc8a093e4a9 updated for version 7.3.115
Bram Moolenaar <bram@vim.org>
parents: 2695
diff changeset
5278
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5279 // tmpnam() will make its own name
2697
6cc8a093e4a9 updated for version 7.3.115
Bram Moolenaar <bram@vim.org>
parents: 2695
diff changeset
5280 p = tmpnam((char *)itmp);
6cc8a093e4a9 updated for version 7.3.115
Bram Moolenaar <bram@vim.org>
parents: 2695
diff changeset
5281 if (p == NULL || *p == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 # ifdef VMS_TEMPNAM
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5287 // 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
5288 // a do-nothing function. Therefore we use tempnam().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 sprintf((char *)itmp, "VIM%c", extra_char);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 p = (char_u *)tempnam("tmp:", (char *)itmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5293 // 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
5294 // and VIM will then be unable to find the file later
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 STRCPY(itmp, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 STRCAT(itmp, ".txt");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 STRCPY(itmp, TEMPNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 if ((p = vim_strchr(itmp, '?')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 *p = extra_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 if (mktemp((char *)itmp) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 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
5311 # endif // MSWIN
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5312 #endif // TEMPDIRNAMES
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 /*
7170
beb67ef38f88 commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents: 7005
diff changeset
5317 * 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
5318 * it looks like a URL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 void
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5321 forward_slash(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324
7170
beb67ef38f88 commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents: 7005
diff changeset
5325 if (path_with_url(fname))
beb67ef38f88 commit https://github.com/vim/vim/commit/b4f6a46b01ed00b642a2271e9d1559e51ab0f2c4
Christian Brabandt <cb@256bit.org>
parents: 7005
diff changeset
5326 return;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327 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
5328 // The Big5 encoding can have '\' in the trail byte.
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 461
diff changeset
5329 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 ++p;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
5331 else if (*p == '\\')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 *p = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 /*
153
19670b05ee32 updated for version 7.0047
vimboss
parents: 123
diff changeset
5337 * Try matching a filename with a "pattern" ("prog" is NULL), or use the
19670b05ee32 updated for version 7.0047
vimboss
parents: 123
diff changeset
5338 * precompiled regprog "prog" ("pattern" is NULL). That avoids calling
19670b05ee32 updated for version 7.0047
vimboss
parents: 123
diff changeset
5339 * vim_regcomp() often.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 * Used for autocommands and 'wildignore'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 * Returns TRUE if there is a match, FALSE otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 */
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
5343 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5344 match_file_pat(
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5345 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
5346 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
5347 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
5348 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
5349 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
5350 int allow_dirs) // allow matching with dir
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 int result = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5355 regmatch.rm_ic = p_fic; // ignore case if 'fileignorecase' is set
6470
9657929ee562 updated for version 7.4.564
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
5356 if (prog != NULL)
9657929ee562 updated for version 7.4.564
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
5357 regmatch.regprog = *prog;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 else
6470
9657929ee562 updated for version 7.4.564
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
5359 regmatch.regprog = vim_regcomp(pattern, RE_MAGIC);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 * Try for a match with the pattern with:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 * 1. the full file name, when the pattern has a '/'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 * 2. the short file name, when the pattern has a '/'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 * 3. the tail of the file name, when the pattern has no '/'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 */
6470
9657929ee562 updated for version 7.4.564
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
5367 if (regmatch.regprog != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 && ((allow_dirs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 && (vim_regexec(&regmatch, fname, (colnr_T)0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 || (sfname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 && vim_regexec(&regmatch, sfname, (colnr_T)0))))
6470
9657929ee562 updated for version 7.4.564
Bram Moolenaar <bram@vim.org>
parents: 6375
diff changeset
5372 || (!allow_dirs && vim_regexec(&regmatch, tail, (colnr_T)0))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 result = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6353
diff changeset
5375 if (prog != NULL)
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6353
diff changeset
5376 *prog = regmatch.regprog;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6353
diff changeset
5377 else
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4354
diff changeset
5378 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 return result;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 #if defined(FEAT_WILDIGN) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 * Return TRUE if a file matches with a pattern in "list".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 * "list" is a comma-separated list of patterns, like 'wildignore'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 * "sfname" is the short file name or NULL, "ffname" the long file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 int
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5389 match_file_list(char_u *list, char_u *sfname, char_u *ffname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 char_u buf[100];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 char_u *regpat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 char allow_dirs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395 int match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 tail = gettail(sfname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5400 // try all patterns in 'wildignore'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 p = list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 copy_option_part(&p, buf, 100, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 regpat = file_pat_to_reg_pat(buf, NULL, &allow_dirs, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 if (regpat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 break;
153
19670b05ee32 updated for version 7.0047
vimboss
parents: 123
diff changeset
5408 match = match_file_pat(regpat, NULL, ffname, sfname,
19670b05ee32 updated for version 7.0047
vimboss
parents: 123
diff changeset
5409 tail, (int)allow_dirs);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 vim_free(regpat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 if (match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 * Convert the given pattern "pat" which has shell style wildcards in it, into
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 * a regular expression, and return the result in allocated memory. If there
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 * is a directory path separator to be matched, then TRUE is put in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 * allow_dirs, otherwise FALSE is put there -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 * Handle backslashes before special characters, like "\*" and "\ ".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 * Returns NULL when out of memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 char_u *
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5428 file_pat_to_reg_pat(
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5429 char_u *pat,
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5430 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
5431 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
5432 int no_bslash UNUSED) // Don't use a backward slash as pathsep
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5434 int size = 2; // '^' at start, '$' at end
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 char_u *endp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 char_u *reg_pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439 int nested = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 int add_dollar = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 if (allow_dirs != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 *allow_dirs = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 if (pat_end == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 pat_end = pat + STRLEN(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 for (p = pat; p < pat_end; p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 switch (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 case ',':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 case '{':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455 case '}':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 case '~':
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5457 size += 2; // extra backslash
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 case '/':
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5462 size += 4; // could become "[\/]"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 size++;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 461
diff changeset
5467 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 ++size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 reg_pat = alloc(size + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 if (reg_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 if (pat[0] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 while (pat[0] == '*' && pat < pat_end - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 pat++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 reg_pat[i++] = '^';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 endp = pat_end - 1;
7005
bb44542231dc patch 7.4.820
Bram Moolenaar <bram@vim.org>
parents: 6999
diff changeset
5487 if (endp >= pat && *endp == '*')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 while (endp - pat > 0 && *endp == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 endp--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 add_dollar = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 for (p = pat; *p && nested >= 0 && p <= endp; p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 switch (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 reg_pat[i++] = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 reg_pat[i++] = '*';
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5500 while (p[1] == '*') // "**" matches like "*"
444
d0d15b184c56 updated for version 7.0116
vimboss
parents: 434
diff changeset
5501 ++p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 reg_pat[i++] = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 case '?':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 reg_pat[i++] = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 if (p[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 if (!no_bslash)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 {
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5517 // translate:
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5518 // "\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
5519 // "\*" to "\\.*" e.g., "dir\*.c"
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5520 // "\?" to "\\." e.g., "dir\??.c"
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5521 // "\+" to "\+" e.g., "fileX\+.c"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 && p[1] != '+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 reg_pat[i++] = '[';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 reg_pat[i++] = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 reg_pat[i++] = ']';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 if (allow_dirs != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 *allow_dirs = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 #endif
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5535 // Undo escaping from ExpandEscape():
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5536 // foo\?bar -> foo?bar
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5537 // foo\%bar -> foo%bar
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5538 // foo\,bar -> foo,bar
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5539 // foo\ bar -> foo bar
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5540 // 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
5541 // regexp.
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5542 // 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
5543 // verymagic. Use "\\\{n,m\}"" to get "\{n,m}".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 if (*++p == '?'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546 && no_bslash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 reg_pat[i++] = '?';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550 else
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 5008
diff changeset
5551 if (*p == ',' || *p == '%' || *p == '#'
6999
dc1b678f0e4e patch 7.4.817
Bram Moolenaar <bram@vim.org>
parents: 6963
diff changeset
5552 || vim_isspace(*p) || *p == '{' || *p == '}')
2243
03a5f2897db3 Fix completion of file names with '%' and '*'.
Bram Moolenaar <bram@vim.org>
parents: 2241
diff changeset
5553 reg_pat[i++] = *p;
5259
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5554 else if (*p == '\\' && p[1] == '\\' && p[2] == '{')
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5555 {
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5556 reg_pat[i++] = '\\';
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5557 reg_pat[i++] = '{';
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5558 p += 2;
6b7ab6a4f31a updated for version 7.4b.006
Bram Moolenaar <bram@vim.org>
parents: 5231
diff changeset
5559 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 if (allow_dirs != NULL && vim_ispathsep(*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 && (!no_bslash || *p != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 *allow_dirs = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 reg_pat[i++] = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 case '/':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 reg_pat[i++] = '[';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 reg_pat[i++] = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 reg_pat[i++] = ']';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 if (allow_dirs != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 *allow_dirs = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 case '{':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 reg_pat[i++] = '(';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 nested++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 case '}':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 reg_pat[i++] = ')';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 --nested;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 case ',':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 if (nested)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 reg_pat[i++] = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 reg_pat[i++] = '|';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 reg_pat[i++] = ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 default:
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 461
diff changeset
5602 if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 reg_pat[i++] = *p++;
15595
1ec942f1b648 patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
5604 else if (allow_dirs != NULL && vim_ispathsep(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 *allow_dirs = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606 reg_pat[i++] = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 if (add_dollar)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 reg_pat[i++] = '$';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 reg_pat[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 if (nested != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 if (nested < 0)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
5616 emsg(_("E219: Missing {."));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
5618 emsg(_("E220: Missing }."));
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13240
diff changeset
5619 VIM_CLEAR(reg_pat);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 return reg_pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 }
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5623
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5624 #if defined(EINTR) || defined(PROTO)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5625 /*
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5626 * Version of read() that retries when interrupted by EINTR (possibly
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5627 * by a SIGWINCH).
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5628 */
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5629 long
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5630 read_eintr(int fd, void *buf, size_t bufsize)
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5631 {
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5632 long ret;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5633
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5634 for (;;)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5635 {
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5636 ret = vim_read(fd, buf, bufsize);
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5637 if (ret >= 0 || errno != EINTR)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5638 break;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5639 }
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5640 return ret;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5641 }
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5642
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5643 /*
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5644 * Version of write() that retries when interrupted by EINTR (possibly
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5645 * by a SIGWINCH).
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5646 */
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5647 long
7819
f86adafb28d4 commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents: 7801
diff changeset
5648 write_eintr(int fd, void *buf, size_t bufsize)
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5649 {
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5650 long ret = 0;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5651 long wlen;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5652
18779
8f05b3cf8557 patch 8.1.2379: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18767
diff changeset
5653 // 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
5654 // by a signal.
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5655 while (ret < (long)bufsize)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5656 {
2666
1a0d346695fa updated for version 7.3.085
Bram Moolenaar <bram@vim.org>
parents: 2664
diff changeset
5657 wlen = vim_write(fd, (char *)buf + ret, bufsize - ret);
2664
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5658 if (wlen < 0)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5659 {
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5660 if (errno != EINTR)
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5661 break;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5662 }
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5663 else
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5664 ret += wlen;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5665 }
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5666 return ret;
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5667 }
033e7b49356c updated for version 7.3.083
Bram Moolenaar <bram@vim.org>
parents: 2563
diff changeset
5668 #endif