annotate src/undo.c @ 2271:2b33a7678e7b vim73

Fix compiler warnings for shadowed variables. Make 'conceal' a long instead of int.
author Bram Moolenaar <bram@vim.org>
date Tue, 22 Jun 2010 06:28:58 +0200
parents c08f91142c41
children 941ff1cd317a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
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 * undo.c: multi level undo facility
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * The saved lines are stored in a list of lists (one for each buffer):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * b_u_oldhead------------------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 * V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * +--------------+ +--------------+ +--------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * b_u_newhead--->| u_header | | u_header | | u_header |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * | uh_next------>| uh_next------>| uh_next---->NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * NULL<--------uh_prev |<---------uh_prev |<---------uh_prev |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 * | uh_entry | | uh_entry | | uh_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * +--------|-----+ +--------|-----+ +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * | | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 * V V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 * +--------------+ +--------------+ +--------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 * | u_entry | | u_entry | | u_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 * | ue_next | | ue_next | | ue_next |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * +--------|-----+ +--------|-----+ +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * | | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 * V V V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * +--------------+ NULL NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 * | u_entry |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 * | ue_next |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 * +--------|-----+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 * |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 * V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 * etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 * Each u_entry list contains the information for one undo or redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 * curbuf->b_u_curhead points to the header of the last undo (the next redo),
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
42 * or is NULL if nothing has been undone (end of the branch).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 *
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
44 * For keeping alternate undo/redo branches the uh_alt field is used. Thus at
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
45 * each point in the list a branch may appear for an alternate to redo. The
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
46 * uh_seq field is numbered sequentially to be able to find a newer or older
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
47 * branch.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
48 *
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
49 * +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
50 * b_u_oldhead --->| u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
51 * | uh_alt_next ---->| uh_alt_next ----> NULL
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
52 * NULL <----- uh_alt_prev |<------ uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
53 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
54 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
55 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
56 * V V
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
57 * +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
58 * | u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
59 * | uh_alt_next | | uh_alt_next |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
60 * b_u_newhead --->| uh_alt_prev | | uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
61 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
62 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
63 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
64 * V V
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
65 * NULL +---------------+ +---------------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
66 * | u_header | | u_header |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
67 * | uh_alt_next ---->| uh_alt_next |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
68 * | uh_alt_prev |<------ uh_alt_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
69 * | uh_prev | | uh_prev |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
70 * +-----|---------+ +-----|---------+
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
71 * | |
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
72 * etc. etc.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
73 *
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
74 *
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
75 * All data is allocated and will all be freed when the buffer is unloaded.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
78 /* Uncomment the next line for including the u_check() function. This warns
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
79 * for errors in the debug information. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
80 /* #define U_DEBUG 1 */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
81 #define UH_MAGIC 0x18dade /* value for uh_magic when in use */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
82 #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
83
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
84 #if defined(MSDOS) || defined(WIN16) || defined(WIN32) || defined(_WIN64)
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
85 # include "vimio.h" /* for vim_read(), must be before vim.h */
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
86 #endif
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
87
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
90 static void u_unch_branch __ARGS((u_header_T *uhp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static u_entry_T *u_get_headentry __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static void u_getbot __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 static void u_doit __ARGS((int count));
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
95 static void u_undoredo __ARGS((int undo));
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
96 static void u_undo_end __ARGS((int did_undo, int absolute));
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
97 static void u_add_time __ARGS((char_u *buf, size_t buflen, time_t tt));
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
98 static void u_freeheader __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
99 static void u_freebranch __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
100 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 static void u_freeentry __ARGS((u_entry_T *, long));
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
102 #ifdef FEAT_PERSISTENT_UNDO
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
103 static void corruption_error __ARGS((char *mesg, char_u *file_name));
2223
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
104 static void u_free_uhp __ARGS((u_header_T *uhp));
2266
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
105 static size_t fwrite_crypt __ARGS((buf_T *buf UNUSED, char_u *ptr, size_t len, FILE *fp));
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
106 static char_u *read_string_decrypt __ARGS((buf_T *buf UNUSED, FILE *fd, int len));
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
107 static int serialize_header __ARGS((FILE *fp, buf_T *buf, char_u *hash));
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
108 static int serialize_uhp __ARGS((FILE *fp, buf_T *buf, u_header_T *uhp));
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
109 static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name));
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
110 static int serialize_uep __ARGS((FILE *fp, buf_T *buf, u_entry_T *uep));
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
111 static u_entry_T *unserialize_uep __ARGS((FILE *fp, int *error, char_u *file_name));
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
112 static void serialize_pos __ARGS((pos_T pos, FILE *fp));
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
113 static void unserialize_pos __ARGS((pos_T *pos, FILE *fp));
2229
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
114 static void serialize_visualinfo __ARGS((visualinfo_T *info, FILE *fp));
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
115 static void unserialize_visualinfo __ARGS((visualinfo_T *info, FILE *fp));
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
116 static void put_header_ptr __ARGS((FILE *fp, u_header_T *uhp));
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
117 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
119 #define U_ALLOC_LINE(size) lalloc((long_u)(size), FALSE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 static char_u *u_save_line __ARGS((linenr_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 static long u_newcount, u_oldcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 * When 'u' flag included in 'cpoptions', we behave like vi. Need to remember
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 * the action that "u" should do.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 static int undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
130 static int lastmark = 0;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
131
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
132 #if defined(U_DEBUG) || defined(PROTO)
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
133 /*
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
134 * Check the undo structures for being valid. Print a warning when something
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
135 * looks wrong.
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
136 */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
137 static int seen_b_u_curhead;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
138 static int seen_b_u_newhead;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
139 static int header_count;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
140
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
141 static void
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
142 u_check_tree(u_header_T *uhp,
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
143 u_header_T *exp_uh_next,
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
144 u_header_T *exp_uh_alt_prev)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
145 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
146 u_entry_T *uep;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
147
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
148 if (uhp == NULL)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
149 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
150 ++header_count;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
151 if (uhp == curbuf->b_u_curhead && ++seen_b_u_curhead > 1)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
152 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
153 EMSG("b_u_curhead found twice (looping?)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
154 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
155 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
156 if (uhp == curbuf->b_u_newhead && ++seen_b_u_newhead > 1)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
157 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
158 EMSG("b_u_newhead found twice (looping?)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
159 return;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
160 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
161
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
162 if (uhp->uh_magic != UH_MAGIC)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
163 EMSG("uh_magic wrong (may be using freed memory)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
164 else
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
165 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
166 /* Check pointers back are correct. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
167 if (uhp->uh_next.ptr != exp_uh_next)
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
168 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
169 EMSG("uh_next wrong");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
170 smsg((char_u *)"expected: 0x%x, actual: 0x%x",
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
171 exp_uh_next, uhp->uh_next.ptr);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
172 }
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
173 if (uhp->uh_alt_prev.ptr != exp_uh_alt_prev)
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
174 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
175 EMSG("uh_alt_prev wrong");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
176 smsg((char_u *)"expected: 0x%x, actual: 0x%x",
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
177 exp_uh_alt_prev, uhp->uh_alt_prev.ptr);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
178 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
179
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
180 /* Check the undo tree at this header. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
181 for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
182 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
183 if (uep->ue_magic != UE_MAGIC)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
184 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
185 EMSG("ue_magic wrong (may be using freed memory)");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
186 break;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
187 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
188 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
189
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
190 /* Check the next alt tree. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
191 u_check_tree(uhp->uh_alt_next.ptr, uhp->uh_next.ptr, uhp);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
192
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
193 /* Check the next header in this branch. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
194 u_check_tree(uhp->uh_prev.ptr, uhp, NULL);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
195 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
196 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
197
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
198 void
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
199 u_check(int newhead_may_be_NULL)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
200 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
201 seen_b_u_newhead = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
202 seen_b_u_curhead = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
203 header_count = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
204
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
205 u_check_tree(curbuf->b_u_oldhead, NULL, NULL);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
206
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
207 if (seen_b_u_newhead == 0 && curbuf->b_u_oldhead != NULL
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
208 && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL))
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
209 EMSGN("b_u_newhead invalid: 0x%x", curbuf->b_u_newhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
210 if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
211 EMSGN("b_u_curhead invalid: 0x%x", curbuf->b_u_curhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
212 if (header_count != curbuf->b_u_numhead)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
213 {
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
214 EMSG("b_u_numhead invalid");
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
215 smsg((char_u *)"expected: %ld, actual: %ld",
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
216 (long)header_count, (long)curbuf->b_u_numhead);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
217 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
218 }
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
219 #endif
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
220
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 /*
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 179
diff changeset
222 * Save the current line for both the "u" and "U" command.
7033303ea0c0 updated for version 7.0089
vimboss
parents: 179
diff changeset
223 * Returns OK or FAIL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 u_save_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 return (u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 (linenr_T)(curwin->w_cursor.lnum + 1)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 * Save the lines between "top" and "bot" for both the "u" and "U" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 * "top" may be 0 and bot may be curbuf->b_ml.ml_line_count + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 * Returns FAIL when lines could not be saved, OK otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 u_save(top, bot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 if (top > curbuf->b_ml.ml_line_count ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 top >= bot || bot > curbuf->b_ml.ml_line_count + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 return FALSE; /* rely on caller to do error messages */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 if (top + 2 == bot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 u_saveline((linenr_T)(top + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 return (u_savecommon(top, bot, (linenr_T)0));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 /*
2154
7c8c7c95a865 First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents: 1534
diff changeset
255 * Save the line "lnum" (used by ":s" and "~" command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 * The line is replaced, so the new bottom line is lnum + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 u_savesub(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 return (u_savecommon(lnum - 1, lnum + 1, lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 /*
2154
7c8c7c95a865 First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents: 1534
diff changeset
269 * A new line is inserted before line "lnum" (used by :s command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 * The line is inserted, so the new bottom line is lnum + 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 u_inssub(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 return (u_savecommon(lnum - 1, lnum, lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 /*
2154
7c8c7c95a865 First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents: 1534
diff changeset
283 * Save the lines "lnum" - "lnum" + nlines (used by delete command).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 * The lines are deleted, so the new bottom line is lnum, unless the buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 * becomes empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 u_savedel(lnum, nlines)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 long nlines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 return (u_savecommon(lnum - 1, lnum + nlines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 nlines == curbuf->b_ml.ml_line_count ? 2 : lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
299 /*
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
300 * Return TRUE when undo is allowed. Otherwise give an error message and
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
301 * return FALSE.
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
302 */
912
adf6a9dcaded updated for version 7.0-038
vimboss
parents: 839
diff changeset
303 int
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
304 undo_allowed()
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
305 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
306 /* Don't allow changes when 'modifiable' is off. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
307 if (!curbuf->b_p_ma)
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
308 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
309 EMSG(_(e_modifiable));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
310 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
311 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
312
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
313 #ifdef HAVE_SANDBOX
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
314 /* In the sandbox it's not allowed to change the text. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
315 if (sandbox != 0)
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
316 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
317 EMSG(_(e_sandbox));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
318 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
319 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
320 #endif
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
321
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
322 /* Don't allow changes in the buffer while editing the cmdline. The
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
323 * caller of getcmdline() may get confused. */
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 632
diff changeset
324 if (textlock != 0)
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
325 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
326 EMSG(_(e_secure));
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
327 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
328 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
329
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
330 return TRUE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
331 }
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
332
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 u_savecommon(top, bot, newbot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 linenr_T newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
338 linenr_T lnum;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
339 long i;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
340 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
341 u_header_T *old_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
342 u_entry_T *uep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
343 u_entry_T *prev_uep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
344 long size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
346 /* When making changes is not allowed return FAIL. It's a crude way to
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
347 * make all change commands fail. */
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
348 if (!undo_allowed())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
351 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
352 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
353 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 * Netbeans defines areas that cannot be modified. Bail out here when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 * trying to change text in a guarded area.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 */
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2154
diff changeset
359 if (netbeans_active())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 {
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
361 if (netbeans_is_guarded(top, bot))
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
362 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
363 EMSG(_(e_guarded));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
364 return FAIL;
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
365 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
366 if (curbuf->b_p_ro)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
367 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
368 EMSG(_(e_nbreadonly));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
369 return FAIL;
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
370 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * Saving text for undo means we are going to make a change. Give a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * warning for a read-only file before making the change, so that the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 * FileChangedRO event can replace the buffer with a read-write version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 * (e.g., obtained from a source control system).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 change_warning(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 size = bot - top - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 * if curbuf->b_u_synced == TRUE make a new header
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 if (curbuf->b_u_synced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 /* Need to create new entry in b_changelist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 curbuf->b_new_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
396 if (p_ul >= 0)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
397 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
398 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
399 * Make a new header entry. Do this first so that we don't mess
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
400 * up the undo info when out of memory.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
401 */
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
402 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T));
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
403 if (uhp == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
404 goto nomem;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
405 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
406 uhp->uh_magic = UH_MAGIC;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
407 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
408 }
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
409 else
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
410 uhp = NULL;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
411
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
413 * If we undid more than we redid, move the entry lists before and
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
414 * including curbuf->b_u_curhead to an alternate branch.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
416 old_curhead = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
417 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
418 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
419 curbuf->b_u_newhead = old_curhead->uh_next.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
420 curbuf->b_u_curhead = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
421 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 * free headers to keep the size right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 while (curbuf->b_u_numhead > p_ul && curbuf->b_u_oldhead != NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
427 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
428 u_header_T *uhfree = curbuf->b_u_oldhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
429
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
430 if (uhfree == old_curhead)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
431 /* Can't reconnect the branch, delete all of it. */
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
432 u_freebranch(curbuf, uhfree, &old_curhead);
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
433 else if (uhfree->uh_alt_next.ptr == NULL)
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
434 /* There is no branch, only free one header. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
435 u_freeheader(curbuf, uhfree, &old_curhead);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
436 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
437 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
438 /* Free the oldest alternate branch as a whole. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
439 while (uhfree->uh_alt_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
440 uhfree = uhfree->uh_alt_next.ptr;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
441 u_freebranch(curbuf, uhfree, &old_curhead);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
442 }
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
443 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
444 u_check(TRUE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
445 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
446 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
448 if (uhp == NULL) /* no undo at all */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
450 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
451 u_freebranch(curbuf, old_curhead, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
456 uhp->uh_prev.ptr = NULL;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
457 uhp->uh_next.ptr = curbuf->b_u_newhead;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
458 uhp->uh_alt_next.ptr = old_curhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
459 if (old_curhead != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
460 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
461 uhp->uh_alt_prev.ptr = old_curhead->uh_alt_prev.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
462 if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
463 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = uhp;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
464 old_curhead->uh_alt_prev.ptr = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
465 if (curbuf->b_u_oldhead == old_curhead)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
466 curbuf->b_u_oldhead = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
467 }
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
468 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
469 uhp->uh_alt_prev.ptr = NULL;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
470 if (curbuf->b_u_newhead != NULL)
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
471 curbuf->b_u_newhead->uh_prev.ptr = uhp;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
472
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
473 uhp->uh_seq = ++curbuf->b_u_seq_last;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
474 curbuf->b_u_seq_cur = uhp->uh_seq;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
475 uhp->uh_time = time(NULL);
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
476 curbuf->b_u_seq_time = uhp->uh_time + 1;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
477
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
478 uhp->uh_walk = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 uhp->uh_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 uhp->uh_getbot_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 uhp->uh_cursor = curwin->w_cursor; /* save cursor pos. for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 uhp->uh_cursor_vcol = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 uhp->uh_cursor_vcol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 /* save changed and buffer empty flag for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 uhp->uh_flags = (curbuf->b_changed ? UH_CHANGED : 0) +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
493 /* save named marks and Visual marks for undo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 mch_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
495 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
496 uhp->uh_visual = curbuf->b_visual;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
497 #endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
498
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 curbuf->b_u_newhead = uhp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 if (curbuf->b_u_oldhead == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 curbuf->b_u_oldhead = uhp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 ++curbuf->b_u_numhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 if (p_ul < 0) /* no undo at all */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 return OK;
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 * When saving a single line, and it has been saved just before, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 * doesn't make sense saving it again. Saves a lot of memory when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 * making lots of changes inside the same line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 * This is only possible if the previous change didn't increase or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 * decrease the number of lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 * Check the ten last changes. More doesn't make sense and takes too
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 * long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 if (size == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 uep = u_get_headentry();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 prev_uep = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 for (i = 0; i < 10; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 /* If lines have been inserted/deleted we give up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 * Also when the line was included in a multi-line save. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 if ((curbuf->b_u_newhead->uh_getbot_entry != uep
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 ? (uep->ue_top + uep->ue_size + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 != (uep->ue_bot == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 ? curbuf->b_ml.ml_line_count + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 : uep->ue_bot))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 : uep->ue_lcount != curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 || (uep->ue_size > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 && top >= uep->ue_top
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 && top + 2 <= uep->ue_top + uep->ue_size + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 /* If it's the same line we can skip saving it again. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 if (uep->ue_size == 1 && uep->ue_top == top)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 /* It's not the last entry: get ue_bot for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 * entry now. Following deleted/inserted lines go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 * the re-used entry. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 u_getbot();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 /* Move the found entry to become the last entry. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 * order of undo/redo doesn't matter for the entries
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 * we move it over, since they don't change the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 * count and don't include this line. It does matter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 * for the found entry if the line count is changed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 * the executed command. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 prev_uep->ue_next = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 uep->ue_next = curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 curbuf->b_u_newhead->uh_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 /* The executed command may change the line count. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 if (newbot != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 uep->ue_bot = newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 else if (bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 uep->ue_bot = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 uep->ue_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 curbuf->b_u_newhead->uh_getbot_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 prev_uep = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 uep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 /* find line number for ue_bot for previous u_save() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 u_getbot();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 #if !defined(UNIX) && !defined(DJGPP) && !defined(WIN32) && !defined(__EMX__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 * With Amiga and MSDOS 16 bit we can't handle big undo's, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 * then u_alloc_line would have to allocate a block larger than 32K
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 if (size >= 8000)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 * add lines in front of entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 */
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
595 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 goto nomem;
2215
cccb71c2c5c1 Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents: 2214
diff changeset
598 vim_memset(uep, 0, sizeof(u_entry_T));
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
599 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
600 uep->ue_magic = UE_MAGIC;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
601 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 uep->ue_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 uep->ue_top = top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 if (newbot != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 uep->ue_bot = newbot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 * Use 0 for ue_bot if bot is below last line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 * Otherwise we have to compute ue_bot later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 else if (bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 uep->ue_bot = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 uep->ue_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 curbuf->b_u_newhead->uh_getbot_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
619 if (size > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
621 if ((uep->ue_array = (char_u **)U_ALLOC_LINE(
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
622 sizeof(char_u *) * size)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 u_freeentry(uep, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 for (i = 0, lnum = top + 1; i < size; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 {
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
629 fast_breakcheck();
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
630 if (got_int)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
631 {
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
632 u_freeentry(uep, i);
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
633 return FAIL;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 414
diff changeset
634 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 if ((uep->ue_array[i] = u_save_line(lnum++)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 u_freeentry(uep, i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 goto nomem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 }
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
642 else
6c62b9b939bd updated for version 7.0093
vimboss
parents: 356
diff changeset
643 uep->ue_array = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 uep->ue_next = curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 curbuf->b_u_newhead->uh_entry = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 curbuf->b_u_synced = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
649 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
650 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
651 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 nomem:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 msg_silent = 0; /* must display the prompt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 == 'y')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 undo_off = TRUE; /* will be reset when character typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665
2266
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
666 #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
667
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
668 # define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
669 # define UF_START_MAGIC_LEN 9
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
670 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
671 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
672 # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
673 # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
674 # define UF_VERSION 1 /* 2-byte undofile version number */
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
675 # define UF_VERSION_CRYPT 0x8001 /* idem, encrypted */
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
676
2229
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
677 static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s");
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
678
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
679 /*
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
680 * Compute the hash for the current buffer text into 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
681 */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
682 void
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
683 u_compute_hash(hash)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
684 char_u *hash;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
685 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
686 context_sha256_T ctx;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
687 linenr_T lnum;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
688 char_u *p;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
689
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
690 sha256_start(&ctx);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
691 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
692 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
693 p = ml_get(lnum);
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
694 sha256_update(&ctx, p, (UINT32_T)(STRLEN(p) + 1));
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
695 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
696 sha256_finish(&ctx, hash);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
697 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
698
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
699 /*
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
700 * Return an allocated string of the full path of the target undofile.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
701 * When "reading" is TRUE find the file to read, go over all directories in
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
702 * 'undodir'.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
703 * When "reading" is FALSE use the first name where the directory exists.
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
704 * Returns NULL when there is no place to write or no file to read.
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
705 */
2236
dc2e5ec0500d Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2235
diff changeset
706 char_u *
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
707 u_get_undo_file_name(buf_ffname, reading)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
708 char_u *buf_ffname;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
709 int reading;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
710 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
711 char_u *dirp;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
712 char_u dir_name[IOSIZE + 1];
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
713 char_u *munged_name = NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
714 char_u *undo_file_name = NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
715 int dir_len;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
716 char_u *p;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
717 struct stat st;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
718 char_u *ffname = buf_ffname;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
719 #ifdef HAVE_READLINK
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
720 char_u fname_buf[MAXPATHL];
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
721 #endif
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
722
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
723 if (ffname == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
724 return NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
725
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
726 #ifdef HAVE_READLINK
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
727 /* Expand symlink in the file name, so that we put the undo file with the
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
728 * actual file instead of with the symlink. */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
729 if (resolve_symlink(ffname, fname_buf) == OK)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
730 ffname = fname_buf;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
731 #endif
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
732
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
733 /* Loop over 'undodir'. When reading find the first file that exists.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
734 * When not reading use the first directory that exists or ".". */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
735 dirp = p_udir;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
736 while (*dirp != NUL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
737 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
738 dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ",");
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
739 if (dir_len == 1 && dir_name[0] == '.')
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
740 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
741 /* Use same directory as the ffname,
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
742 * "dir/name" -> "dir/.name.un~" */
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
743 undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5));
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
744 if (undo_file_name == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
745 break;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
746 p = gettail(undo_file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
747 mch_memmove(p + 1, p, STRLEN(p) + 1);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
748 *p = '.';
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
749 STRCAT(p, ".un~");
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
750 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
751 else
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
752 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
753 dir_name[dir_len] = NUL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
754 if (mch_isdir(dir_name))
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
755 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
756 if (munged_name == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
757 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
758 munged_name = vim_strsave(ffname);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
759 if (munged_name == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
760 return NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
761 for (p = munged_name; *p != NUL; mb_ptr_adv(p))
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
762 if (vim_ispathsep(*p))
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
763 *p = '%';
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
764 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
765 undo_file_name = concat_fnames(dir_name, munged_name, TRUE);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
766 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
767 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
768
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
769 /* When reading check if the file exists. */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
770 if (undo_file_name != NULL && (!reading
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
771 || mch_stat((char *)undo_file_name, &st) >= 0))
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
772 break;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
773 vim_free(undo_file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
774 undo_file_name = NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
775 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
776
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
777 vim_free(munged_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
778 return undo_file_name;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
779 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
780
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
781 static void
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
782 corruption_error(mesg, file_name)
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
783 char *mesg;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
784 char_u *file_name;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
785 {
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
786 EMSG3(_("E825: Corrupted undo file (%s): %s"), mesg, file_name);
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
787 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
788
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
789 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
790 u_free_uhp(uhp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
791 u_header_T *uhp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
792 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
793 u_entry_T *nuep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
794 u_entry_T *uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
795
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
796 uep = uhp->uh_entry;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
797 while (uep != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
798 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
799 nuep = uep->ue_next;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
800 u_freeentry(uep, uep->ue_size);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
801 uep = nuep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
802 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
803 vim_free(uhp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
804 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
805
2266
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
806 /*
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
807 * Like fwrite() but crypt the bytes when 'key' is set.
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
808 * Returns 1 if successful.
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
809 */
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
810 static size_t
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
811 fwrite_crypt(buf, ptr, len, fp)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
812 buf_T *buf UNUSED;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
813 char_u *ptr;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
814 size_t len;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
815 FILE *fp;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
816 {
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
817 #ifdef FEAT_CRYPT
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
818 char_u *copy;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
819 char_u small_buf[100];
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
820 size_t i;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
821
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
822 if (*buf->b_p_key == NUL)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
823 return fwrite(ptr, len, (size_t)1, fp);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
824 if (len < 100)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
825 copy = small_buf; /* no malloc()/free() for short strings */
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
826 else
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
827 {
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
828 copy = lalloc(len, FALSE);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
829 if (copy == NULL)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
830 return 0;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
831 }
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
832 crypt_encode(ptr, len, copy);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
833 i = fwrite(copy, len, (size_t)1, fp);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
834 if (copy != small_buf)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
835 vim_free(copy);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
836 return i;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
837 #else
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
838 return fwrite(ptr, len, (size_t)1, fp);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
839 #endif
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
840 }
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
841
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
842 /*
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
843 * Read a string of length "len" from "fd".
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
844 * When 'key' is set decrypt the bytes.
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
845 */
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
846 static char_u *
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
847 read_string_decrypt(buf, fd, len)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
848 buf_T *buf UNUSED;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
849 FILE *fd;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
850 int len;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
851 {
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
852 char_u *ptr;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
853
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
854 ptr = read_string(fd, len);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
855 #ifdef FEAT_CRYPT
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
856 if (ptr != NULL || *buf->b_p_key != NUL)
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
857 crypt_decode(ptr, len);
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
858 #endif
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
859 return ptr;
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
860 }
ae2e615a7320 Fix tiny build, move functions to undo.c.
Bram Moolenaar <bram@vim.org>
parents: 2262
diff changeset
861
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
862 static int
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
863 serialize_header(fp, buf, hash)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
864 FILE *fp;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
865 buf_T *buf;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
866 char_u *hash;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
867 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
868 int len;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
869
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
870 /* Start writing, first the magic marker and undo info version. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
871 if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
872 return FAIL;
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
873
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
874 /* If the buffer is encrypted then all text bytes following will be
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
875 * encrypted. Numbers and other info is not crypted. */
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
876 #ifdef FEAT_CRYPT
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
877 if (*buf->b_p_key)
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
878 {
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
879 char_u *header;
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
880 int header_len;
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
881
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
882 put_bytes(fp, (long_u)UF_VERSION_CRYPT, 2);
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
883 header = prepare_crypt_write(buf, &header_len);
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
884 if (header == NULL)
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
885 return FAIL;
2245
4e0124f5aee2 Optimize the blowfish crypt/decrypt code a bit more.
Bram Moolenaar <bram@vim.org>
parents: 2242
diff changeset
886 len = (int)fwrite(header, (size_t)header_len, (size_t)1, fp);
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
887 vim_free(header);
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
888 if (len != 1)
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
889 {
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
890 crypt_pop_state();
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
891 return FAIL;
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
892 }
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
893 }
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
894 else
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
895 #endif
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
896 put_bytes(fp, (long_u)UF_VERSION, 2);
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
897
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
898
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
899 /* Write a hash of the buffer text, so that we can verify it is still the
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
900 * same when reading the buffer text. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
901 if (fwrite(hash, (size_t)UNDO_HASH_SIZE, (size_t)1, fp) != 1)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
902 return FAIL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
903
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
904 /* buffer-specific data */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
905 put_bytes(fp, (long_u)buf->b_ml.ml_line_count, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
906 len = buf->b_u_line_ptr != NULL ? (int)STRLEN(buf->b_u_line_ptr) : 0;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
907 put_bytes(fp, (long_u)len, 4);
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
908 if (len > 0 && fwrite_crypt(buf, buf->b_u_line_ptr, (size_t)len, fp) != 1)
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
909 return FAIL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
910 put_bytes(fp, (long_u)buf->b_u_line_lnum, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
911 put_bytes(fp, (long_u)buf->b_u_line_colnr, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
912
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
913 /* Undo structures header data */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
914 put_header_ptr(fp, buf->b_u_oldhead);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
915 put_header_ptr(fp, buf->b_u_newhead);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
916 put_header_ptr(fp, buf->b_u_curhead);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
917
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
918 put_bytes(fp, (long_u)buf->b_u_numhead, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
919 put_bytes(fp, (long_u)buf->b_u_seq_last, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
920 put_bytes(fp, (long_u)buf->b_u_seq_cur, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
921 put_time(fp, buf->b_u_seq_time);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
922
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
923 return OK;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
924 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
925
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
926 static int
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
927 serialize_uhp(fp, buf, uhp)
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
928 FILE *fp;
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
929 buf_T *buf;
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
930 u_header_T *uhp;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
931 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
932 int i;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
933 u_entry_T *uep;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
934
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
935 if (put_bytes(fp, (long_u)UF_HEADER_MAGIC, 2) == FAIL)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
936 return FAIL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
937
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
938 put_header_ptr(fp, uhp->uh_next.ptr);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
939 put_header_ptr(fp, uhp->uh_prev.ptr);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
940 put_header_ptr(fp, uhp->uh_alt_next.ptr);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
941 put_header_ptr(fp, uhp->uh_alt_prev.ptr);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
942 put_bytes(fp, uhp->uh_seq, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
943 serialize_pos(uhp->uh_cursor, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
944 #ifdef FEAT_VIRTUALEDIT
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
945 put_bytes(fp, (long_u)uhp->uh_cursor_vcol, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
946 #else
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
947 put_bytes(fp, (long_u)0, 4);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
948 #endif
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
949 put_bytes(fp, (long_u)uhp->uh_flags, 2);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
950 /* Assume NMARKS will stay the same. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
951 for (i = 0; i < NMARKS; ++i)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
952 serialize_pos(uhp->uh_namedm[i], fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
953 #ifdef FEAT_VISUAL
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
954 serialize_visualinfo(&uhp->uh_visual, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
955 #else
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
956 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
957 visualinfo_T info;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
958
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
959 memset(&info, 0, sizeof(visualinfo_T));
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
960 serialize_visualinfo(&info, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
961 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
962 #endif
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
963 put_time(fp, uhp->uh_time);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
964
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
965 /* Write all the entries. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
966 for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
967 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
968 put_bytes(fp, (long_u)UF_ENTRY_MAGIC, 2);
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
969 if (serialize_uep(fp, buf, uep) == FAIL)
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
970 return FAIL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
971 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
972 put_bytes(fp, (long_u)UF_ENTRY_END_MAGIC, 2);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
973 return OK;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
974 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
975
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
976 static u_header_T *
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
977 unserialize_uhp(fp, file_name)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
978 FILE *fp;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
979 char_u *file_name;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
980 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
981 u_header_T *uhp;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
982 int i;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
983 u_entry_T *uep, *last_uep;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
984 int c;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
985 int error;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
986
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
987 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T));
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
988 if (uhp == NULL)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
989 return NULL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
990 vim_memset(uhp, 0, sizeof(u_header_T));
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
991 #ifdef U_DEBUG
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
992 uhp->uh_magic = UH_MAGIC;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
993 #endif
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
994 uhp->uh_next.seq = get4c(fp);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
995 uhp->uh_prev.seq = get4c(fp);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
996 uhp->uh_alt_next.seq = get4c(fp);
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
997 uhp->uh_alt_prev.seq = get4c(fp);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
998 uhp->uh_seq = get4c(fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
999 if (uhp->uh_seq <= 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1000 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1001 corruption_error("uh_seq", file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1002 vim_free(uhp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1003 return NULL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1004 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1005 unserialize_pos(&uhp->uh_cursor, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1006 #ifdef FEAT_VIRTUALEDIT
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1007 uhp->uh_cursor_vcol = get4c(fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1008 #else
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1009 (void)get4c(fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1010 #endif
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1011 uhp->uh_flags = get2c(fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1012 for (i = 0; i < NMARKS; ++i)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1013 unserialize_pos(&uhp->uh_namedm[i], fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1014 #ifdef FEAT_VISUAL
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1015 unserialize_visualinfo(&uhp->uh_visual, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1016 #else
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1017 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1018 visualinfo_T info;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1019 unserialize_visualinfo(&info, fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1020 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1021 #endif
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1022 uhp->uh_time = get8ctime(fp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1023
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1024 /* Unserialize the uep list. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1025 last_uep = NULL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1026 while ((c = get2c(fp)) == UF_ENTRY_MAGIC)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1027 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1028 error = FALSE;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1029 uep = unserialize_uep(fp, &error, file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1030 if (last_uep == NULL)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1031 uhp->uh_entry = uep;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1032 else
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1033 last_uep->ue_next = uep;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1034 last_uep = uep;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1035 if (uep == NULL || error)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1036 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1037 u_free_uhp(uhp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1038 return NULL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1039 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1040 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1041 if (c != UF_ENTRY_END_MAGIC)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1042 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1043 corruption_error("entry end", file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1044 u_free_uhp(uhp);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1045 return NULL;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1046 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1047
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1048 return uhp;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1049 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1050
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1051 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1052 * Serialize "uep" to "fp".
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1053 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1054 static int
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1055 serialize_uep(fp, buf, uep)
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1056 FILE *fp;
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1057 buf_T *buf;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1058 u_entry_T *uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1059 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1060 int i;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1061 size_t len;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1062
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1063 put_bytes(fp, (long_u)uep->ue_top, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1064 put_bytes(fp, (long_u)uep->ue_bot, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1065 put_bytes(fp, (long_u)uep->ue_lcount, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1066 put_bytes(fp, (long_u)uep->ue_size, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1067 for (i = 0; i < uep->ue_size; ++i)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1068 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1069 len = STRLEN(uep->ue_array[i]);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1070 if (put_bytes(fp, (long_u)len, 4) == FAIL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1071 return FAIL;
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1072 if (len > 0 && fwrite_crypt(buf, uep->ue_array[i], len, fp) != 1)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1073 return FAIL;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1074 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1075 return OK;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1076 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1077
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1078 static u_entry_T *
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1079 unserialize_uep(fp, error, file_name)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1080 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1081 int *error;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1082 char_u *file_name;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1083 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1084 int i;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1085 u_entry_T *uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1086 char_u **array;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1087 char_u *line;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1088 int line_len;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1089
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1090 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1091 if (uep == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1092 return NULL;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1093 vim_memset(uep, 0, sizeof(u_entry_T));
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1094 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1095 uep->ue_magic = UE_MAGIC;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1096 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1097 uep->ue_top = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1098 uep->ue_bot = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1099 uep->ue_lcount = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1100 uep->ue_size = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1101 if (uep->ue_size > 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1102 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1103 array = (char_u **)U_ALLOC_LINE(sizeof(char_u *) * uep->ue_size);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1104 if (array == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1105 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1106 *error = TRUE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1107 return uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1108 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1109 vim_memset(array, 0, sizeof(char_u *) * uep->ue_size);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1110 }
2232
2e6906bbc5f4 A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents: 2231
diff changeset
1111 else
2e6906bbc5f4 A few more fixes for undo file. Split test in two parts so that it doesn't
Bram Moolenaar <bram@vim.org>
parents: 2231
diff changeset
1112 array = NULL;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1113 uep->ue_array = array;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1114
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1115 for (i = 0; i < uep->ue_size; ++i)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1116 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1117 line_len = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1118 if (line_len >= 0)
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1119 line = read_string_decrypt(curbuf, fp, line_len);
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1120 else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1121 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1122 line = NULL;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1123 corruption_error("line length", file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1124 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1125 if (line == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1126 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1127 *error = TRUE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1128 return uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1129 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1130 array[i] = line;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1131 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1132 return uep;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1133 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1134
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1135 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1136 * Serialize "pos" to "fp".
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1137 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1138 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1139 serialize_pos(pos, fp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1140 pos_T pos;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1141 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1142 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1143 put_bytes(fp, (long_u)pos.lnum, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1144 put_bytes(fp, (long_u)pos.col, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1145 #ifdef FEAT_VIRTUALEDIT
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1146 put_bytes(fp, (long_u)pos.coladd, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1147 #else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1148 put_bytes(fp, (long_u)0, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1149 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1150 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1151
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1152 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1153 * Unserialize the pos_T at the current position in fp.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1154 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1155 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1156 unserialize_pos(pos, fp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1157 pos_T *pos;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1158 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1159 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1160 pos->lnum = get4c(fp);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1161 if (pos->lnum < 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1162 pos->lnum = 0;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1163 pos->col = get4c(fp);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1164 if (pos->col < 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1165 pos->col = 0;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1166 #ifdef FEAT_VIRTUALEDIT
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1167 pos->coladd = get4c(fp);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1168 if (pos->coladd < 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1169 pos->coladd = 0;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1170 #else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1171 (void)get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1172 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1173 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1174
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1175 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1176 * Serialize "info" to "fp".
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1177 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1178 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1179 serialize_visualinfo(info, fp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1180 visualinfo_T *info;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1181 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1182 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1183 serialize_pos(info->vi_start, fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1184 serialize_pos(info->vi_end, fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1185 put_bytes(fp, (long_u)info->vi_mode, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1186 put_bytes(fp, (long_u)info->vi_curswant, 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1187 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1188
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1189 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1190 * Unserialize the visualinfo_T at the current position in fp.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1191 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1192 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1193 unserialize_visualinfo(info, fp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1194 visualinfo_T *info;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1195 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1196 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1197 unserialize_pos(&info->vi_start, fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1198 unserialize_pos(&info->vi_end, fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1199 info->vi_mode = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1200 info->vi_curswant = get4c(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1201 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1202
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1203 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1204 * Write the pointer to an undo header. Instead of writing the pointer itself
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1205 * we use the sequence number of the header. This is converted back to
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1206 * pointers when reading. */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1207 static void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1208 put_header_ptr(fp, uhp)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1209 FILE *fp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1210 u_header_T *uhp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1211 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1212 put_bytes(fp, (long_u)(uhp != NULL ? uhp->uh_seq : 0), 4);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1213 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1214
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1215 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1216 * Write the undo tree in an undo file.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1217 * When "name" is not NULL, use it as the name of the undo file.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1218 * Otherwise use buf->b_ffname to generate the undo file name.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1219 * "buf" must never be null, buf->b_ffname is used to obtain the original file
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1220 * permissions.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1221 * "forceit" is TRUE for ":wundo!", FALSE otherwise.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1222 * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1223 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1224 void
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1225 u_write_undo(name, forceit, buf, hash)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1226 char_u *name;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1227 int forceit;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1228 buf_T *buf;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1229 char_u *hash;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1230 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1231 u_header_T *uhp;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1232 char_u *file_name;
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1233 int mark;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1234 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1235 int headers_written = 0;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1236 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1237 int fd;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1238 FILE *fp = NULL;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1239 int perm;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1240 int write_ok = FALSE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1241 #ifdef UNIX
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1242 int st_old_valid = FALSE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1243 struct stat st_old;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1244 struct stat st_new;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1245 #endif
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1246 #ifdef FEAT_CRYPT
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1247 int do_crypt = FALSE;
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1248 #endif
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1249
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1250 if (name == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1251 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1252 file_name = u_get_undo_file_name(buf->b_ffname, FALSE);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1253 if (file_name == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1254 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1255 if (p_verbose > 0)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1256 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1257 verbose_enter();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1258 smsg((char_u *)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1259 _("Cannot write undo file in any directory in 'undodir'"));
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1260 verbose_leave();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1261 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1262 return;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1263 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1264 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1265 else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1266 file_name = name;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1267
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1268 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1269 * Decide about the permission to use for the undo file. If the buffer
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1270 * has a name use the permission of the original file. Otherwise only
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1271 * allow the user to access the undo file.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1272 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1273 perm = 0600;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1274 if (buf->b_ffname != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1275 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1276 #ifdef UNIX
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1277 if (mch_stat((char *)buf->b_ffname, &st_old) >= 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1278 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1279 perm = st_old.st_mode;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1280 st_old_valid = TRUE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1281 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1282 #else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1283 perm = mch_getperm(buf->b_ffname);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1284 if (perm < 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1285 perm = 0600;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1286 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1287 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1288
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1289 /* strip any s-bit */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1290 perm = perm & 0777;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1291
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1292 /* If the undo file already exists, verify that it actually is an undo
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1293 * file, and delete it. */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1294 if (mch_getperm(file_name) >= 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1295 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1296 if (name == NULL || !forceit)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1297 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1298 /* Check we can read it and it's an undo file. */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1299 fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1300 if (fd < 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1301 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1302 if (name != NULL || p_verbose > 0)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1303 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1304 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1305 verbose_enter();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1306 smsg((char_u *)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1307 _("Will not overwrite with undo file, cannot read: %s"),
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1308 file_name);
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1309 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1310 verbose_leave();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1311 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1312 goto theend;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1313 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1314 else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1315 {
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
1316 char_u mbuf[UF_START_MAGIC_LEN];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1317 int len;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1318
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
1319 len = vim_read(fd, mbuf, UF_START_MAGIC_LEN);
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1320 close(fd);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1321 if (len < UF_START_MAGIC_LEN
2271
2b33a7678e7b Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents: 2267
diff changeset
1322 || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1323 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1324 if (name != NULL || p_verbose > 0)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1325 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1326 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1327 verbose_enter();
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1328 smsg((char_u *)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1329 _("Will not overwrite, this is not an undo file: %s"),
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1330 file_name);
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1331 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1332 verbose_leave();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1333 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1334 goto theend;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1335 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1336 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1337 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1338 mch_remove(file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1339 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1340
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1341 /* If there is no undo information at all, quit here after deleting any
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1342 * existing undo file. */
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1343 if (buf->b_u_numhead == 0 && buf->b_u_line_ptr == NULL)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1344 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1345 if (p_verbose > 0)
2262
771f21e35ec5 Minor typo and docs update.
Bram Moolenaar <bram@vim.org>
parents: 2251
diff changeset
1346 verb_msg((char_u *)_("Skipping undo file write, nothing to undo"));
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1347 goto theend;
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1348 }
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1349
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1350 fd = mch_open((char *)file_name,
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1351 O_CREAT|O_EXTRA|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1352 if (fd < 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1353 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1354 EMSG2(_(e_not_open), file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1355 goto theend;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1356 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1357 (void)mch_setperm(file_name, perm);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1358 if (p_verbose > 0)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1359 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1360 verbose_enter();
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1361 smsg((char_u *)_("Writing undo file: %s"), file_name);
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1362 verbose_leave();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1363 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1364
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1365 #ifdef U_DEBUG
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1366 /* Check there is no problem in undo info before writing. */
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1367 u_check(FALSE);
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1368 #endif
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1369
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1370 #ifdef UNIX
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1371 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1372 * Try to set the group of the undo file same as the original file. If
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1373 * this fails, set the protection bits for the group same as the
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1374 * protection bits for others.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1375 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1376 if (st_old_valid && (mch_stat((char *)file_name, &st_new) >= 0
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1377 && st_new.st_gid != st_old.st_gid
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1378 # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1379 && fchown(fd, (uid_t)-1, st_old.st_gid) != 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1380 # endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1381 )
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1382 mch_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1383 # ifdef HAVE_SELINUX
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1384 if (buf->b_ffname != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1385 mch_copy_sec(buf->b_ffname, file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1386 # endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1387 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1388
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1389 fp = fdopen(fd, "w");
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1390 if (fp == NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1391 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1392 EMSG2(_(e_not_open), file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1393 close(fd);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1394 mch_remove(file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1395 goto theend;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1396 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1397
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1398 /* Undo must be synced. */
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1399 u_sync(TRUE);
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1400
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1401 /*
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1402 * Write the header.
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1403 */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1404 if (serialize_header(fp, buf, hash) == FAIL)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1405 goto write_error;
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1406 #ifdef FEAT_CRYPT
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1407 if (*buf->b_p_key)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1408 do_crypt = TRUE;
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1409 #endif
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1410
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1411 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1412 * Iteratively serialize UHPs and their UEPs from the top down.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1413 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1414 mark = ++lastmark;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1415 uhp = buf->b_u_oldhead;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1416 while (uhp != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1417 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1418 /* Serialize current UHP if we haven't seen it */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1419 if (uhp->uh_walk != mark)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1420 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1421 uhp->uh_walk = mark;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1422 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1423 ++headers_written;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1424 #endif
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1425 if (serialize_uhp(fp, buf, uhp) == FAIL)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1426 goto write_error;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1427 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1428
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1429 /* Now walk through the tree - algorithm from undo_time(). */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1430 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1431 uhp = uhp->uh_prev.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1432 else if (uhp->uh_alt_next.ptr != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1433 && uhp->uh_alt_next.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1434 uhp = uhp->uh_alt_next.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1435 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1436 && uhp->uh_next.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1437 uhp = uhp->uh_next.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1438 else if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1439 uhp = uhp->uh_alt_prev.ptr;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1440 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1441 uhp = uhp->uh_next.ptr;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1442 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1443
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1444 if (put_bytes(fp, (long_u)UF_HEADER_END_MAGIC, 2) == OK)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1445 write_ok = TRUE;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1446 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1447 if (headers_written != buf->b_u_numhead)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1448 EMSG3("Written %ld headers, but numhead is %ld",
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1449 headers_written, buf->b_u_numhead);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1450 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1451
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1452 write_error:
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1453 fclose(fp);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1454 if (!write_ok)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1455 EMSG2(_("E829: write error in undo file: %s"), file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1456
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1457 #if defined(MACOS_CLASSIC) || defined(WIN3264)
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1458 /* Copy file attributes; for systems where this can only be done after
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1459 * closing the file. */
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1460 if (buf->b_ffname != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1461 (void)mch_copy_file_attribute(buf->b_ffname, file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1462 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1463 #ifdef HAVE_ACL
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1464 if (buf->b_ffname != NULL)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1465 {
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1466 vim_acl_T acl;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1467
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1468 /* For systems that support ACL: get the ACL from the original file. */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1469 acl = mch_get_acl(buf->b_ffname);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1470 mch_set_acl(file_name, acl);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1471 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1472 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1473
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1474 theend:
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1475 #ifdef FEAT_CRYPT
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1476 if (do_crypt)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1477 crypt_pop_state();
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1478 #endif
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1479 if (file_name != name)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1480 vim_free(file_name);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1481 }
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1482
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1483 /*
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1484 * Load the undo tree from an undo file.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1485 * If "name" is not NULL use it as the undo file name. This also means being
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1486 * a bit more verbose.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1487 * Otherwise use curbuf->b_ffname to generate the undo file name.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1488 * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1489 */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1490 void
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1491 u_read_undo(name, hash, orig_name)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1492 char_u *name;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1493 char_u *hash;
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1494 char_u *orig_name;
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1495 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1496 char_u *file_name;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1497 FILE *fp;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1498 long version, str_len;
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1499 char_u *line_ptr = NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1500 linenr_T line_lnum;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1501 colnr_T line_colnr;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1502 linenr_T line_count;
2217
120502692d82 Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
1503 int num_head = 0;
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1504 long old_header_seq, new_header_seq, cur_header_seq;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1505 long seq_last, seq_cur;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1506 short old_idx = -1, new_idx = -1, cur_idx = -1;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1507 long num_read_uhps = 0;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1508 time_t seq_time;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1509 int i, j;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1510 int c;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1511 u_header_T *uhp;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1512 u_header_T **uhp_table = NULL;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1513 char_u read_hash[UNDO_HASH_SIZE];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1514 char_u magic_buf[UF_START_MAGIC_LEN];
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1515 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1516 int *uhp_table_used;
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1517 #endif
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1518 #ifdef UNIX
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1519 struct stat st_orig;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1520 struct stat st_undo;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1521 #endif
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1522 #ifdef FEAT_CRYPT
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1523 int do_decrypt = FALSE;
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1524 #endif
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1525
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1526 if (name == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1527 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1528 file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1529 if (file_name == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1530 return;
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1531
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1532 #ifdef UNIX
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1533 /* For safety we only read an undo file if the owner is equal to the
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1534 * owner of the text file. */
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1535 if (mch_stat((char *)orig_name, &st_orig) >= 0
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1536 && mch_stat((char *)file_name, &st_undo) >= 0
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1537 && st_orig.st_uid != st_undo.st_uid)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1538 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1539 if (p_verbose > 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1540 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1541 verbose_enter();
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1542 smsg((char_u *)_("Not reading undo file, owner differs: %s"),
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1543 file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1544 verbose_leave();
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1545 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1546 return;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1547 }
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1548 #endif
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1549 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1550 else
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1551 file_name = name;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1552
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1553 if (p_verbose > 0)
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1554 {
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1555 verbose_enter();
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1556 smsg((char_u *)_("Reading undo file: %s"), file_name);
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1557 verbose_leave();
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1558 }
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1559
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1560 fp = mch_fopen((char *)file_name, "r");
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1561 if (fp == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1562 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1563 if (name != NULL || p_verbose > 0)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1564 EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1565 goto error;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1566 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1567
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1568 /*
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1569 * Read the undo file header.
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1570 */
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1571 if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1572 || memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1573 {
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1574 EMSG2(_("E823: Not an undo file: %s"), file_name);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1575 goto error;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1576 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1577 version = get2c(fp);
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1578 if (version == UF_VERSION_CRYPT)
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1579 {
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1580 #ifdef FEAT_CRYPT
2251
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1581 if (*curbuf->b_p_key == NUL)
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1582 {
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1583 EMSG2(_("E832: Non-encrypted file has encrypted undo file: %s"),
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1584 file_name);
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1585 goto error;
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1586 }
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1587 if (prepare_crypt_read(fp) == FAIL)
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1588 {
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1589 EMSG2(_("E826: Undo file decryption failed: %s"), file_name);
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1590 goto error;
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1591 }
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1592 do_decrypt = TRUE;
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1593 #else
2251
646d34788036 Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents: 2245
diff changeset
1594 EMSG2(_("E827: Undo file is encrypted: %s"), file_name);
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1595 goto error;
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1596 #endif
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1597 }
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1598 else if (version != UF_VERSION)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1599 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1600 EMSG2(_("E824: Incompatible undo file: %s"), file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1601 goto error;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1602 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1603
2229
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
1604 if (fread(read_hash, UNDO_HASH_SIZE, 1, fp) != 1)
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
1605 {
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1606 corruption_error("hash", file_name);
2229
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
1607 goto error;
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
1608 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1609 line_count = (linenr_T)get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1610 if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1611 || line_count != curbuf->b_ml.ml_line_count)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1612 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1613 if (p_verbose > 0 || name != NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1614 {
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1615 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1616 verbose_enter();
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1617 give_warning((char_u *)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1618 _("File contents changed, cannot use undo info"), TRUE);
2235
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1619 if (name == NULL)
4ba83ae8d505 Do not write an undo file if there is nothing to undo.
Bram Moolenaar <bram@vim.org>
parents: 2234
diff changeset
1620 verbose_leave();
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1621 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1622 goto error;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1623 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1624
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1625 /* Read undo data for "U" command. */
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1626 str_len = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1627 if (str_len < 0)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1628 goto error;
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1629 if (str_len > 0)
2239
732cb7b31956 Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents: 2238
diff changeset
1630 line_ptr = read_string_decrypt(curbuf, fp, str_len);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1631 line_lnum = (linenr_T)get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1632 line_colnr = (colnr_T)get4c(fp);
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1633 if (line_lnum < 0 || line_colnr < 0)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1634 {
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1635 corruption_error("line lnum/col", file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1636 goto error;
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1637 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1638
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1639 /* Begin general undo data */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1640 old_header_seq = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1641 new_header_seq = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1642 cur_header_seq = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1643 num_head = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1644 seq_last = get4c(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1645 seq_cur = get4c(fp);
2229
d45902a5c61c Fix a few more things for persistent undo.
Bram Moolenaar <bram@vim.org>
parents: 2223
diff changeset
1646 seq_time = get8ctime(fp);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1647
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1648 /* uhp_table will store the freshly created undo headers we allocate
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1649 * until we insert them into curbuf. The table remains sorted by the
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1650 * sequence numbers of the headers.
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1651 * When there are no headers uhp_table is NULL. */
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1652 if (num_head > 0)
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1653 {
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1654 uhp_table = (u_header_T **)U_ALLOC_LINE(
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1655 num_head * sizeof(u_header_T *));
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1656 if (uhp_table == NULL)
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1657 goto error;
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1658 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1659
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1660 while ((c = get2c(fp)) == UF_HEADER_MAGIC)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1661 {
2223
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1662 if (num_read_uhps >= num_head)
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1663 {
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1664 corruption_error("num_head too small", file_name);
2223
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1665 goto error;
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1666 }
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1667
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1668 uhp = unserialize_uhp(fp, file_name);
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1669 if (uhp == NULL)
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1670 goto error;
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1671 uhp_table[num_read_uhps++] = uhp;
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1672 }
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1673
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1674 if (num_read_uhps != num_head)
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1675 {
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1676 corruption_error("num_head", file_name);
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1677 goto error;
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1678 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1679 if (c != UF_HEADER_END_MAGIC)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1680 {
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1681 corruption_error("end marker", file_name);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1682 goto error;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1683 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1684
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1685 #ifdef U_DEBUG
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1686 uhp_table_used = (int *)alloc_clear(
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1687 (unsigned)(sizeof(int) * num_head + 1));
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1688 # define SET_FLAG(j) ++uhp_table_used[j]
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1689 #else
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1690 # define SET_FLAG(j)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1691 #endif
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1692
2238
3d0a7beb0d75 Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents: 2236
diff changeset
1693 /* We have put all of the headers into a table. Now we iterate through the
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1694 * table and swizzle each sequence number we have stored in uh_*_seq into
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1695 * a pointer corresponding to the header with that sequence number. */
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1696 for (i = 0; i < num_head; i++)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1697 {
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1698 uhp = uhp_table[i];
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1699 if (uhp == NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1700 continue;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1701 for (j = 0; j < num_head; j++)
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1702 if (uhp_table[j] != NULL && i != j
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1703 && uhp_table[i]->uh_seq == uhp_table[j]->uh_seq)
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1704 {
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1705 corruption_error("duplicate uh_seq", file_name);
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1706 goto error;
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1707 }
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1708 for (j = 0; j < num_head; j++)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1709 if (uhp_table[j] != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1710 && uhp_table[j]->uh_seq == uhp->uh_next.seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1711 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1712 uhp->uh_next.ptr = uhp_table[j];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1713 SET_FLAG(j);
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1714 break;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1715 }
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1716 for (j = 0; j < num_head; j++)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1717 if (uhp_table[j] != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1718 && uhp_table[j]->uh_seq == uhp->uh_prev.seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1719 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1720 uhp->uh_prev.ptr = uhp_table[j];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1721 SET_FLAG(j);
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1722 break;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1723 }
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1724 for (j = 0; j < num_head; j++)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1725 if (uhp_table[j] != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1726 && uhp_table[j]->uh_seq == uhp->uh_alt_next.seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1727 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1728 uhp->uh_alt_next.ptr = uhp_table[j];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1729 SET_FLAG(j);
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1730 break;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1731 }
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1732 for (j = 0; j < num_head; j++)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1733 if (uhp_table[j] != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1734 && uhp_table[j]->uh_seq == uhp->uh_alt_prev.seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1735 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1736 uhp->uh_alt_prev.ptr = uhp_table[j];
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1737 SET_FLAG(j);
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1738 break;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1739 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1740 if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1741 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1742 old_idx = i;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1743 SET_FLAG(i);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1744 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1745 if (new_header_seq > 0 && new_idx < 0 && uhp->uh_seq == new_header_seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1746 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1747 new_idx = i;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1748 SET_FLAG(i);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1749 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1750 if (cur_header_seq > 0 && cur_idx < 0 && uhp->uh_seq == cur_header_seq)
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1751 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1752 cur_idx = i;
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1753 SET_FLAG(i);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1754 }
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1755 }
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1756
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1757 /* Now that we have read the undo info successfully, free the current undo
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1758 * info and use the info from the file. */
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1759 u_blockfree(curbuf);
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1760 curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx];
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1761 curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx];
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1762 curbuf->b_u_curhead = cur_idx < 0 ? NULL : uhp_table[cur_idx];
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1763 curbuf->b_u_line_ptr = line_ptr;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1764 curbuf->b_u_line_lnum = line_lnum;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1765 curbuf->b_u_line_colnr = line_colnr;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1766 curbuf->b_u_numhead = num_head;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1767 curbuf->b_u_seq_last = seq_last;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1768 curbuf->b_u_seq_cur = seq_cur;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1769 curbuf->b_u_seq_time = seq_time;
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1770
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1771 curbuf->b_u_synced = TRUE;
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1772 vim_free(uhp_table);
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1773
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1774 #ifdef U_DEBUG
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1775 for (i = 0; i < num_head; ++i)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1776 if (uhp_table_used[i] == 0)
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1777 EMSGN("uhp_table entry %ld not used, leaking memory", i);
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1778 vim_free(uhp_table_used);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1779 u_check(TRUE);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1780 #endif
2231
aa6412cab544 Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents: 2230
diff changeset
1781
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1782 if (name != NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1783 smsg((char_u *)_("Finished reading undo file %s"), file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1784 goto theend;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1785
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1786 error:
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1787 vim_free(line_ptr);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1788 if (uhp_table != NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1789 {
2233
43cad213cb7f A bit of cleanup and simplification for undofile.
Bram Moolenaar <bram@vim.org>
parents: 2232
diff changeset
1790 for (i = 0; i < num_read_uhps; i++)
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1791 if (uhp_table[i] != NULL)
2223
81b83a19e127 More strict checks for the undo file.
Bram Moolenaar <bram@vim.org>
parents: 2222
diff changeset
1792 u_free_uhp(uhp_table[i]);
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
1793 vim_free(uhp_table);
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1794 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1795
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1796 theend:
2267
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1797 #ifdef FEAT_CRYPT
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1798 if (do_decrypt)
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1799 crypt_pop_state();
c08f91142c41 Crypt the swapfile.
Bram Moolenaar <bram@vim.org>
parents: 2266
diff changeset
1800 #endif
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1801 if (fp != NULL)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1802 fclose(fp);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1803 if (file_name != name)
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1804 vim_free(file_name);
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1805 return;
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1806 }
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1807
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1808 #endif /* FEAT_PERSISTENT_UNDO */
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1809
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
1810
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 * If 'cpoptions' contains 'u': Undo the previous undo or redo (vi compatible).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 * If 'cpoptions' does not contain 'u': Always undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 u_undo(count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 * If we get an undo command while executing a macro, we behave like the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 * original vi. If this happens twice in one macro the result will not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 * be compatible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 if (curbuf->b_u_synced == FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1826 u_sync(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 if (vim_strchr(p_cpo, CPO_UNDO) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 undo_undoes = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 undo_undoes = !undo_undoes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 u_doit(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 * If 'cpoptions' contains 'u': Repeat the previous undo or redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 * If 'cpoptions' does not contain 'u': Always redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 u_redo(count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 if (vim_strchr(p_cpo, CPO_UNDO) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 undo_undoes = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 u_doit(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 * Undo or redo, depending on 'undo_undoes', 'count' times.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 static void
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1854 u_doit(startcount)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1855 int startcount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1857 int count = startcount;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1858
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 481
diff changeset
1859 if (!undo_allowed())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 u_newcount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 u_oldcount = 0;
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
1864 if (curbuf->b_ml.ml_flags & ML_EMPTY)
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
1865 u_oldcount = -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 while (count--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 if (undo_undoes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 if (curbuf->b_u_curhead == NULL) /* first undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 curbuf->b_u_curhead = curbuf->b_u_newhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 else if (p_ul > 0) /* multi level undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 /* get next undo */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1874 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 /* nothing to undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 /* stick curbuf->b_u_curhead at end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 curbuf->b_u_curhead = curbuf->b_u_oldhead;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 beep_flush();
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1881 if (count == startcount - 1)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1882 {
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1883 MSG(_("Already at oldest change"));
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1884 return;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1885 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1889 u_undoredo(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 if (curbuf->b_u_curhead == NULL || p_ul <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 beep_flush(); /* nothing to redo */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1896 if (count == startcount - 1)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1897 {
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1898 MSG(_("Already at newest change"));
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1899 return;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1900 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1904 u_undoredo(FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1905
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1906 /* Advance for next redo. Set "newhead" when at the end of the
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1907 * redoable changes. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1908 if (curbuf->b_u_curhead->uh_prev.ptr == NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1909 curbuf->b_u_newhead = curbuf->b_u_curhead;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
1910 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1913 u_undo_end(undo_undoes, FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1914 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1915
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1916 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1917 * Undo or redo over the timeline.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1918 * When "step" is negative go back in time, otherwise goes forward in time.
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1919 * When "sec" is FALSE make "step" steps, when "sec" is TRUE use "step" as
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1920 * seconds.
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1921 * When "absolute" is TRUE use "step" as the sequence number to jump to.
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1922 * "sec" must be FALSE then.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1923 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1924 void
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1925 undo_time(step, sec, absolute)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1926 long step;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1927 int sec;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1928 int absolute;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1929 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1930 long target;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1931 long closest;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1932 long closest_start;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1933 long closest_seq = 0;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1934 long val;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1935 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1936 u_header_T *last;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1937 int mark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1938 int nomark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1939 int round;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1940 int dosec = sec;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1941 int above = FALSE;
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
1942 int did_undo = TRUE;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1943
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
1944 /* First make sure the current undoable change is synced. */
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
1945 if (curbuf->b_u_synced == FALSE)
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
1946 u_sync(TRUE);
766
f0d0d3d3a1e2 updated for version 7.0225
vimboss
parents: 758
diff changeset
1947
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1948 u_newcount = 0;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1949 u_oldcount = 0;
179
7fd70926e2e1 updated for version 7.0055
vimboss
parents: 168
diff changeset
1950 if (curbuf->b_ml.ml_flags & ML_EMPTY)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1951 u_oldcount = -1;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1952
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1953 /* "target" is the node below which we want to be.
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1954 * Init "closest" to a value we can't reach. */
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1955 if (absolute)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1956 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
1957 target = step;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1958 closest = -1;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1959 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1960 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1961 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1962 /* When doing computations with time_t subtract starttime, because
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1963 * time_t converted to a long may result in a wrong number. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1964 if (sec)
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1965 target = (long)(curbuf->b_u_seq_time - starttime) + step;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1966 else
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1967 target = curbuf->b_u_seq_cur + step;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1968 if (step < 0)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1969 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1970 if (target < 0)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1971 target = 0;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1972 closest = -1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1973 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1974 else
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1975 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1976 if (sec)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
1977 closest = (long)(time(NULL) - starttime + 1);
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1978 else
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1979 closest = curbuf->b_u_seq_last + 2;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1980 if (target >= closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1981 target = closest - 1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1982 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1983 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1984 closest_start = closest;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
1985 closest_seq = curbuf->b_u_seq_cur;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1986
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1987 /*
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1988 * May do this twice:
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1989 * 1. Search for "target", update "closest" to the best match found.
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1990 * 2. If "target" not found search for "closest".
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1991 *
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1992 * When using the closest time we use the sequence number in the second
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1993 * round, because there may be several entries with the same time.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
1994 */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1995 for (round = 1; round <= 2; ++round)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1996 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1997 /* Find the path from the current state to where we want to go. The
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1998 * desired state can be anywhere in the undo tree, need to go all over
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
1999 * it. We put "nomark" in uh_walk where we have been without success,
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2000 * "mark" where it could possibly be. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2001 mark = ++lastmark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2002 nomark = ++lastmark;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2003
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2004 if (curbuf->b_u_curhead == NULL) /* at leaf of the tree */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2005 uhp = curbuf->b_u_newhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2006 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2007 uhp = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2008
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2009 while (uhp != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2010 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2011 uhp->uh_walk = mark;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2012 val = (long)(dosec ? (uhp->uh_time - starttime) : uhp->uh_seq);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2013
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2014 if (round == 1)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2015 {
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2016 /* Remember the header that is closest to the target.
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2017 * It must be at least in the right direction (checked with
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2018 * "b_u_seq_cur"). When the timestamp is equal find the
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2019 * highest/lowest sequence number. */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2020 if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2021 : uhp->uh_seq > curbuf->b_u_seq_cur)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2022 && ((dosec && val == closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2023 ? (step < 0
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2024 ? uhp->uh_seq < closest_seq
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2025 : uhp->uh_seq > closest_seq)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2026 : closest == closest_start
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2027 || (val > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2028 ? (closest > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2029 ? val - target <= closest - target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2030 : val - target <= target - closest)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2031 : (closest > target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2032 ? target - val <= closest - target
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2033 : target - val <= target - closest))))
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2034 {
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2035 closest = val;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2036 closest_seq = uhp->uh_seq;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2037 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2038 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2039
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2040 /* Quit searching when we found a match. But when searching for a
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2041 * time we need to continue looking for the best uh_seq. */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2042 if (target == val && !dosec)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2043 break;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2044
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2045 /* go down in the tree if we haven't been there */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2046 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2047 && uhp->uh_prev.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2048 uhp = uhp->uh_prev.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2049
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2050 /* go to alternate branch if we haven't been there */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2051 else if (uhp->uh_alt_next.ptr != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2052 && uhp->uh_alt_next.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2053 && uhp->uh_alt_next.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2054 uhp = uhp->uh_alt_next.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2055
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2056 /* go up in the tree if we haven't been there and we are at the
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2057 * start of alternate branches */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2058 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2059 && uhp->uh_next.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2060 && uhp->uh_next.ptr->uh_walk != mark)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2061 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2062 /* If still at the start we don't go through this change. */
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2063 if (uhp == curbuf->b_u_curhead)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2064 uhp->uh_walk = nomark;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2065 uhp = uhp->uh_next.ptr;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2066 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2067
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2068 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2069 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2070 /* need to backtrack; mark this node as useless */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2071 uhp->uh_walk = nomark;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2072 if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2073 uhp = uhp->uh_alt_prev.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2074 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2075 uhp = uhp->uh_next.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2076 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2077 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2078
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2079 if (uhp != NULL) /* found it */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2080 break;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2081
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2082 if (absolute)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2083 {
2214
f8222d1f9a73 Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2084 EMSGN(_("E830: Undo number %ld not found"), step);
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2085 return;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2086 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2087
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2088 if (closest == closest_start)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2089 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2090 if (step < 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2091 MSG(_("Already at oldest change"));
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2092 else
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2093 MSG(_("Already at newest change"));
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2094 return;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2095 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2096
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2097 target = closest_seq;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2098 dosec = FALSE;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2099 if (step < 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2100 above = TRUE; /* stop above the header */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2101 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2102
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2103 /* If we found it: Follow the path to go to where we want to be. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2104 if (uhp != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2105 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2106 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2107 * First go up the tree as much as needed.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2108 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2109 for (;;)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2110 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2111 uhp = curbuf->b_u_curhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2112 if (uhp == NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2113 uhp = curbuf->b_u_newhead;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2114 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2115 uhp = uhp->uh_next.ptr;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2116 if (uhp == NULL || uhp->uh_walk != mark
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2117 || (uhp->uh_seq == target && !above))
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2118 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2119 curbuf->b_u_curhead = uhp;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2120 u_undoredo(TRUE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2121 uhp->uh_walk = nomark; /* don't go back down here */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2122 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2123
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2124 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2125 * And now go down the tree (redo), branching off where needed.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2126 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2127 uhp = curbuf->b_u_curhead;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2128 while (uhp != NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2129 {
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
2130 /* Go back to the first branch with a mark. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2131 while (uhp->uh_alt_prev.ptr != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2132 && uhp->uh_alt_prev.ptr->uh_walk == mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2133 uhp = uhp->uh_alt_prev.ptr;
1056
e6d25347de2c updated for version 7.0-182
vimboss
parents: 944
diff changeset
2134
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2135 /* Find the last branch with a mark, that's the one. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2136 last = uhp;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2137 while (last->uh_alt_next.ptr != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2138 && last->uh_alt_next.ptr->uh_walk == mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2139 last = last->uh_alt_next.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2140 if (last != uhp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2141 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2142 /* Make the used branch the first entry in the list of
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2143 * alternatives to make "u" and CTRL-R take this branch. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2144 while (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2145 uhp = uhp->uh_alt_prev.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2146 if (last->uh_alt_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2147 last->uh_alt_next.ptr->uh_alt_prev.ptr =
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2148 last->uh_alt_prev.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2149 last->uh_alt_prev.ptr->uh_alt_next.ptr = last->uh_alt_next.ptr;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2150 last->uh_alt_prev.ptr = NULL;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2151 last->uh_alt_next.ptr = uhp;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2152 uhp->uh_alt_prev.ptr = last;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2153
2234
3b241fd8d7c0 updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2233
diff changeset
2154 if (curbuf->b_u_oldhead == uhp)
3b241fd8d7c0 updated for version 7.2.441
Bram Moolenaar <bram@vim.org>
parents: 2233
diff changeset
2155 curbuf->b_u_oldhead = last;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2156 uhp = last;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2157 if (uhp->uh_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2158 uhp->uh_next.ptr->uh_prev.ptr = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2159 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2160 curbuf->b_u_curhead = uhp;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2161
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2162 if (uhp->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2163 break; /* must have reached the target */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2164
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2165 /* Stop when going backwards in time and didn't find the exact
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2166 * header we were looking for. */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2167 if (uhp->uh_seq == target && above)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2168 {
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2169 curbuf->b_u_seq_cur = target - 1;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2170 break;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2171 }
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2172
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2173 u_undoredo(FALSE);
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2174
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2175 /* Advance "curhead" to below the header we last used. If it
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2176 * becomes NULL then we need to set "newhead" to this leaf. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2177 if (uhp->uh_prev.ptr == NULL)
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2178 curbuf->b_u_newhead = uhp;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2179 curbuf->b_u_curhead = uhp->uh_prev.ptr;
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2180 did_undo = FALSE;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2181
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2182 if (uhp->uh_seq == target) /* found it! */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2183 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2184
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2185 uhp = uhp->uh_prev.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2186 if (uhp == NULL || uhp->uh_walk != mark)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2187 {
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2188 /* Need to redo more but can't find it... */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2189 EMSG2(_(e_intern2), "undo_time()");
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2190 break;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2191 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2192 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2193 }
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2194 u_undo_end(did_undo, absolute);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 * u_undoredo: common code for undo and redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 * The lines in the file are replaced by the lines in the entry list at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 * curbuf->b_u_curhead. The replaced lines in the file are saved in the entry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 * list for the next undo/redo.
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2203 *
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2204 * When "undo" is TRUE we go up in the tree, when FALSE we go down.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 static void
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2207 u_undoredo(undo)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2208 int undo;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 char_u **newarray = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 linenr_T oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 linenr_T newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 linenr_T top, bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 linenr_T newlnum = MAXLNUM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 long i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 u_entry_T *uep, *nuep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 u_entry_T *newlist = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 int old_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 int new_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 pos_T namedm[NMARKS];
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2222 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2223 visualinfo_T visualinfo;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2224 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 int empty_buffer; /* buffer became empty */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2226 u_header_T *curhead = curbuf->b_u_curhead;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2228 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2229 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2230 #endif
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2231 old_flags = curhead->uh_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 new_flags = (curbuf->b_changed ? UH_CHANGED : 0) +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 setpcmark();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 * save marks before undo/redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 mch_memmove(namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2240 #ifdef FEAT_VISUAL
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2241 visualinfo = curbuf->b_visual;
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2242 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 curbuf->b_op_start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 curbuf->b_op_end.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 curbuf->b_op_end.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2248 for (uep = curhead->uh_entry; uep != NULL; uep = nuep)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 top = uep->ue_top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 bot = uep->ue_bot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 if (bot == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 bot = curbuf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 if (top > curbuf->b_ml.ml_line_count || top >= bot
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 || bot > curbuf->b_ml.ml_line_count + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 EMSG(_("E438: u_undo: line numbers wrong"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 changed(); /* don't want UNCHANGED now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 oldsize = bot - top - 1; /* number of lines before undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 newsize = uep->ue_size; /* number of lines after undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 if (top < newlnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 /* If the saved cursor is somewhere in this undo block, move it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 * the remembered position. Makes "gwap" put the cursor back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 * where it was. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2270 lnum = curhead->uh_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 if (lnum >= top && lnum <= top + newsize + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2273 curwin->w_cursor = curhead->uh_cursor;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 newlnum = curwin->w_cursor.lnum - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 /* Use the first line that actually changed. Avoids that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 * undoing auto-formatting puts the cursor in the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 * line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 for (i = 0; i < newsize && i < oldsize; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 newlnum = top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 curwin->w_cursor.lnum = newlnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 else if (i < newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 newlnum = top + i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 curwin->w_cursor.lnum = newlnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 empty_buffer = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 /* delete the lines between top and bot and save them in newarray */
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2300 if (oldsize > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 {
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2302 if ((newarray = (char_u **)U_ALLOC_LINE(
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2303 sizeof(char_u *) * oldsize)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 do_outofmem_msg((long_u)(sizeof(char_u *) * oldsize));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 * We have messed up the entry list, repair is impossible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 * we have to free the rest of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 while (uep != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 nuep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 u_freeentry(uep, uep->ue_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 uep = nuep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 /* delete backwards, it goes faster in most cases */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 /* what can we do when we run out of memory? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 if ((newarray[i] = u_save_line(lnum)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 /* remember we deleted the last line in the buffer, and a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 * dummy empty line will be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 if (curbuf->b_ml.ml_line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 empty_buffer = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 ml_delete(lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 }
414
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
2331 else
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
2332 newarray = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 /* insert the lines in u_array between top and bot */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 if (newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 for (lnum = top, i = 0; i < newsize; ++i, ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 * If the file is empty, there is an empty line 1 that we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 * should get rid of, by replacing it with the new line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 if (empty_buffer && lnum == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 ml_replace((linenr_T)1, uep->ue_array[i], TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE);
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2347 vim_free(uep->ue_array[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 }
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2349 vim_free((char_u *)uep->ue_array);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 /* adjust marks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 if (oldsize != newsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 (long)newsize - (long)oldsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 if (curbuf->b_op_start.lnum > top + oldsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 curbuf->b_op_start.lnum += newsize - oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 if (curbuf->b_op_end.lnum > top + oldsize)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 curbuf->b_op_end.lnum += newsize - oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 changed_lines(top + 1, 0, bot, newsize - oldsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 /* set '[ and '] mark */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 if (top + 1 < curbuf->b_op_start.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 curbuf->b_op_start.lnum = top + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 curbuf->b_op_end.lnum = top + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 else if (top + newsize > curbuf->b_op_end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 curbuf->b_op_end.lnum = top + newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 u_newcount += newsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 u_oldcount += oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 uep->ue_size = oldsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 uep->ue_array = newarray;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 uep->ue_bot = top + newsize + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 * insert this entry in front of the new entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 nuep = uep->ue_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 uep->ue_next = newlist;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 newlist = uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2387 curhead->uh_entry = newlist;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2388 curhead->uh_flags = new_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 if ((old_flags & UH_EMPTYBUF) && bufempty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 curbuf->b_ml.ml_flags |= ML_EMPTY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 if (old_flags & UH_CHANGED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 else
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
2394 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
2395 /* per netbeans undo rules, keep it as modified */
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
2396 if (!isNetbeansModified(curbuf))
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 7
diff changeset
2397 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 unchanged(curbuf, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 * restore marks from before undo/redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 for (i = 0; i < NMARKS; ++i)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2404 if (curhead->uh_namedm[i].lnum != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2406 curbuf->b_namedm[i] = curhead->uh_namedm[i];
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2407 curhead->uh_namedm[i] = namedm[i];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 }
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2409 #ifdef FEAT_VISUAL
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2410 if (curhead->uh_visual.vi_start.lnum != 0)
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2411 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2412 curbuf->b_visual = curhead->uh_visual;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2413 curhead->uh_visual = visualinfo;
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2414 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 634
diff changeset
2415 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 * If the cursor is only off by one line, put it at the same position as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 * before starting the change (for the "o" command).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 * Otherwise the cursor should go to the first undone line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2422 if (curhead->uh_cursor.lnum + 1 == curwin->w_cursor.lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 --curwin->w_cursor.lnum;
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2425 if (curhead->uh_cursor.lnum == curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2427 curwin->w_cursor.col = curhead->uh_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 #ifdef FEAT_VIRTUALEDIT
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2429 if (virtual_active() && curhead->uh_cursor_vcol >= 0)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2430 coladvance((colnr_T)curhead->uh_cursor_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 else if (curwin->w_cursor.lnum <= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 beginline(BL_SOL | BL_FIX);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 /* We get here with the current cursor line being past the end (eg
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 * after adding lines at the end of the file, and then undoing it).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 * check_cursor() will move the cursor to the last line. Move it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 * the first column here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 /* Make sure the cursor is on an existing line and column. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 check_cursor();
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2451
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2452 /* Remember where we are for "g-" and ":earlier 10s". */
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2453 curbuf->b_u_seq_cur = curhead->uh_seq;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2454 if (undo)
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2455 /* We are below the previous undo. However, to make ":earlier 1s"
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2456 * work we compute this as being just above the just undone change. */
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2457 --curbuf->b_u_seq_cur;
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2458
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2459 /* The timestamp can be the same for multiple changes, just use the one of
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2460 * the undone/redone change. */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2461 curbuf->b_u_seq_time = curhead->uh_time;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2462 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2463 u_check(FALSE);
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2464 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 * If we deleted or added lines, report the number of less/more lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 * Otherwise, report the number of changes (this may be incorrect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 * in some cases, but it's better than nothing).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 static void
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2473 u_undo_end(did_undo, absolute)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2474 int did_undo; /* just did an undo */
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2475 int absolute; /* used ":undo N" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 {
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2477 char *msgstr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2478 u_header_T *uhp;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2479 char_u msgbuf[80];
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2480
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 if ((fdo_flags & FDO_UNDO) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 #endif
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2485
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2486 if (global_busy /* no messages now, wait until global is finished */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2487 || !messaging()) /* 'lazyredraw' set, don't do messages now */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2488 return;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2489
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2490 if (curbuf->b_ml.ml_flags & ML_EMPTY)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2491 --u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2492
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2493 u_oldcount -= u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2494 if (u_oldcount == -1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2495 msgstr = N_("more line");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2496 else if (u_oldcount < 0)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2497 msgstr = N_("more lines");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2498 else if (u_oldcount == 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2499 msgstr = N_("line less");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2500 else if (u_oldcount > 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2501 msgstr = N_("fewer lines");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2502 else
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2503 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2504 u_oldcount = u_newcount;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2505 if (u_newcount == 1)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2506 msgstr = N_("change");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2507 else
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2508 msgstr = N_("changes");
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2509 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2510
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2511 if (curbuf->b_u_curhead != NULL)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2512 {
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2513 /* For ":undo N" we prefer a "after #N" message. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2514 if (absolute && curbuf->b_u_curhead->uh_next.ptr != NULL)
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2515 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2516 uhp = curbuf->b_u_curhead->uh_next.ptr;
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2517 did_undo = FALSE;
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2518 }
95dac6af3b3a updated for version 7.0232
vimboss
parents: 794
diff changeset
2519 else if (did_undo)
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2520 uhp = curbuf->b_u_curhead;
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2521 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2522 uhp = curbuf->b_u_curhead->uh_next.ptr;
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2523 }
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2524 else
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2525 uhp = curbuf->b_u_newhead;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2526
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2527 if (uhp == NULL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2528 *msgbuf = NUL;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2529 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2530 u_add_time(msgbuf, sizeof(msgbuf), uhp->uh_time);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2531
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2532 smsg((char_u *)_("%ld %s; %s #%ld %s"),
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2533 u_oldcount < 0 ? -u_oldcount : u_oldcount,
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 912
diff changeset
2534 _(msgstr),
794
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2535 did_undo ? _("before") : _("after"),
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2536 uhp == NULL ? 0L : uhp->uh_seq,
f19994020dad updated for version 7.0231
vimboss
parents: 777
diff changeset
2537 msgbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 * u_sync: stop adding to the current entry list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 void
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
2544 u_sync(force)
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
2545 int force; /* Also sync when no_u_sync is set. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
2547 /* Skip it when already synced or syncing is disabled. */
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
2548 if (curbuf->b_u_synced || (!force && no_u_sync > 0))
6675076019ae updated for version 7.0d
vimboss
parents: 810
diff changeset
2549 return;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 if (im_is_preediting())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 return; /* XIM is busy, don't break an undo sequence */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 if (p_ul < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 curbuf->b_u_synced = TRUE; /* no entries, nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 u_getbot(); /* compute ue_bot of previous u_save */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 curbuf->b_u_curhead = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 /*
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2564 * ":undolist": List the leafs of the undo tree
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2565 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2566 void
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2567 ex_undolist(eap)
2154
7c8c7c95a865 First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents: 1534
diff changeset
2568 exarg_T *eap UNUSED;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2569 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2570 garray_T ga;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2571 u_header_T *uhp;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2572 int mark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2573 int nomark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2574 int changes = 1;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2575 int i;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2576
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2577 /*
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2578 * 1: walk the tree to find all leafs, put the info in "ga".
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2579 * 2: sort the lines
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2580 * 3: display the list
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2581 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2582 mark = ++lastmark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2583 nomark = ++lastmark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2584 ga_init2(&ga, (int)sizeof(char *), 20);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2585
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2586 uhp = curbuf->b_u_oldhead;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2587 while (uhp != NULL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2588 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2589 if (uhp->uh_prev.ptr == NULL && uhp->uh_walk != nomark
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 772
diff changeset
2590 && uhp->uh_walk != mark)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2591 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2592 if (ga_grow(&ga, 1) == FAIL)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2593 break;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2594 vim_snprintf((char *)IObuff, IOSIZE, "%6ld %7ld ",
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2595 uhp->uh_seq, changes);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2596 u_add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff),
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2597 uhp->uh_time);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2598 ((char_u **)(ga.ga_data))[ga.ga_len++] = vim_strsave(IObuff);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2599 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2600
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2601 uhp->uh_walk = mark;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2602
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2603 /* go down in the tree if we haven't been there */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2604 if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2605 && uhp->uh_prev.ptr->uh_walk != mark)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2606 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2607 uhp = uhp->uh_prev.ptr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2608 ++changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2609 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2610
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2611 /* go to alternate branch if we haven't been there */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2612 else if (uhp->uh_alt_next.ptr != NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2613 && uhp->uh_alt_next.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2614 && uhp->uh_alt_next.ptr->uh_walk != mark)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2615 uhp = uhp->uh_alt_next.ptr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2616
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2617 /* go up in the tree if we haven't been there and we are at the
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2618 * start of alternate branches */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2619 else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2620 && uhp->uh_next.ptr->uh_walk != nomark
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2621 && uhp->uh_next.ptr->uh_walk != mark)
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2622 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2623 uhp = uhp->uh_next.ptr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2624 --changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2625 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2626
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2627 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2628 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2629 /* need to backtrack; mark this node as done */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2630 uhp->uh_walk = nomark;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2631 if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2632 uhp = uhp->uh_alt_prev.ptr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2633 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2634 {
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2635 uhp = uhp->uh_next.ptr;
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2636 --changes;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2637 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2638 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2639 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2640
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2641 if (ga.ga_len == 0)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2642 MSG(_("Nothing to undo"));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2643 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2644 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2645 sort_strings((char_u **)ga.ga_data, ga.ga_len);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2646
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2647 msg_start();
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2648 msg_puts_attr((char_u *)_("number changes time"), hl_attr(HLF_T));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2649 for (i = 0; i < ga.ga_len && !got_int; ++i)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2650 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2651 msg_putchar('\n');
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2652 if (got_int)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2653 break;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2654 msg_puts(((char_u **)ga.ga_data)[i]);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2655 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2656 msg_end();
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2657
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2658 ga_clear_strings(&ga);
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2659 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2660 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2661
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2662 /*
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2663 * Put the timestamp of an undo header in "buf[buflen]" in a nice format.
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2664 */
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2665 static void
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2666 u_add_time(buf, buflen, tt)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2667 char_u *buf;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2668 size_t buflen;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2669 time_t tt;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2670 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2671 #ifdef HAVE_STRFTIME
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2672 struct tm *curtime;
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2673
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2674 if (time(NULL) - tt >= 100)
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2675 {
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2676 curtime = localtime(&tt);
810
9f345c48220b updated for version 7.0c
vimboss
parents: 798
diff changeset
2677 (void)strftime((char *)buf, buflen, "%H:%M:%S", curtime);
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2678 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2679 else
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2680 #endif
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
2681 vim_snprintf((char *)buf, buflen, _("%ld seconds ago"),
772
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2682 (long)(time(NULL) - tt));
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2683 }
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2684
aaaca5077255 updated for version 7.0226
vimboss
parents: 766
diff changeset
2685 /*
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2686 * ":undojoin": continue adding to the last entry list
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2687 */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2688 void
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2689 ex_undojoin(eap)
2154
7c8c7c95a865 First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents: 1534
diff changeset
2690 exarg_T *eap UNUSED;
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2691 {
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2692 if (curbuf->b_u_newhead == NULL)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2693 return; /* nothing changed before */
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2694 if (curbuf->b_u_curhead != NULL)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2695 {
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2696 EMSG(_("E790: undojoin is not allowed after undo"));
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2697 return;
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 835
diff changeset
2698 }
697
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2699 if (!curbuf->b_u_synced)
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2700 return; /* already unsynced */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2701 if (p_ul < 0)
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2702 return; /* no entries, nothing to do */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2703 else
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2704 {
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2705 /* Go back to the last entry */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2706 curbuf->b_u_curhead = curbuf->b_u_newhead;
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2707 curbuf->b_u_synced = FALSE; /* no entries, nothing to do */
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2708 }
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2709 }
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2710
f08390485cd3 updated for version 7.0210
vimboss
parents: 692
diff changeset
2711 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 * Called after writing the file and setting b_changed to FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 * Now an undo means that the buffer is modified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 u_unchanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 {
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2719 u_unch_branch(buf->b_u_oldhead);
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2720 buf->b_did_warn = FALSE;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2721 }
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2722
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2723 static void
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2724 u_unch_branch(uhp)
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2725 u_header_T *uhp;
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2726 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2727 u_header_T *uh;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2729 for (uh = uhp; uh != NULL; uh = uh->uh_prev.ptr)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2730 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 uh->uh_flags |= UH_CHANGED;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2732 if (uh->uh_alt_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2733 u_unch_branch(uh->uh_alt_next.ptr); /* recursive */
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2734 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 * Get pointer to last added entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 * If it's not valid, give an error message and return NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 static u_entry_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 u_get_headentry()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 if (curbuf->b_u_newhead == NULL || curbuf->b_u_newhead->uh_entry == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 EMSG(_("E439: undo list corrupt"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 return curbuf->b_u_newhead->uh_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 * u_getbot(): compute the line number of the previous u_save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 * It is called only when b_u_synced is FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 u_getbot()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 u_entry_T *uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 linenr_T extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 uep = u_get_headentry(); /* check for corrupt undo list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 if (uep == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 uep = curbuf->b_u_newhead->uh_getbot_entry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 if (uep != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 * the new ue_bot is computed from the number of lines that has been
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 * inserted (0 - deleted) since calling u_save. This is equal to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 * old line count subtracted from the current line count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 extra = curbuf->b_ml.ml_line_count - uep->ue_lcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 uep->ue_bot = uep->ue_top + uep->ue_size + 1 + extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 if (uep->ue_bot < 1 || uep->ue_bot > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 EMSG(_("E440: undo line missing"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 uep->ue_bot = uep->ue_top + 1; /* assume all lines deleted, will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 * get all the old lines back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 * without deleting the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 * ones */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 curbuf->b_u_newhead->uh_getbot_entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 curbuf->b_u_synced = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 /*
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2792 * Free one header "uhp" and its entry list and adjust the pointers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 static void
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2795 u_freeheader(buf, uhp, uhpp)
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2796 buf_T *buf;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2797 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2798 u_header_T **uhpp; /* if not NULL reset when freeing this header */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 {
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2800 u_header_T *uhap;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2801
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2802 /* When there is an alternate redo list free that branch completely,
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2803 * because we can never go there. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2804 if (uhp->uh_alt_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2805 u_freebranch(buf, uhp->uh_alt_next.ptr, uhpp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2807 if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2808 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2810 /* Update the links in the list to remove the header. */
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2811 if (uhp->uh_next.ptr == NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2812 buf->b_u_oldhead = uhp->uh_prev.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2814 uhp->uh_next.ptr->uh_prev.ptr = uhp->uh_prev.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2816 if (uhp->uh_prev.ptr == NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2817 buf->b_u_newhead = uhp->uh_next.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 else
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2819 for (uhap = uhp->uh_prev.ptr; uhap != NULL;
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2820 uhap = uhap->uh_alt_next.ptr)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2821 uhap->uh_next.ptr = uhp->uh_next.ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2823 u_freeentries(buf, uhp, uhpp);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2824 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2825
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2826 /*
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
2827 * Free an alternate branch and any following alternate branches.
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2828 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2829 static void
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2830 u_freebranch(buf, uhp, uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2831 buf_T *buf;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2832 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2833 u_header_T **uhpp; /* if not NULL reset when freeing this header */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2834 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2835 u_header_T *tofree, *next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2836
1440
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2837 /* If this is the top branch we may need to use u_freeheader() to update
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2838 * all the pointers. */
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2839 if (uhp == buf->b_u_oldhead)
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2840 {
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2841 u_freeheader(buf, uhp, uhpp);
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2842 return;
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2843 }
93ffa40b5320 updated for version 7.1-155
vimboss
parents: 1415
diff changeset
2844
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2845 if (uhp->uh_alt_prev.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2846 uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2847
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2848 next = uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2849 while (next != NULL)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2850 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2851 tofree = next;
2242
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2852 if (tofree->uh_alt_next.ptr != NULL)
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2853 u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); /* recursive */
bc4685345719 Don't use pointers to store numbers, use a union.
Bram Moolenaar <bram@vim.org>
parents: 2239
diff changeset
2854 next = tofree->uh_prev.ptr;
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2855 u_freeentries(buf, tofree, uhpp);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2856 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2857 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2858
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2859 /*
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2860 * Free all the undo entries for one header and the header itself.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2861 * This means that "uhp" is invalid when returning.
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2862 */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2863 static void
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2864 u_freeentries(buf, uhp, uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2865 buf_T *buf;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2866 u_header_T *uhp;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2867 u_header_T **uhpp; /* if not NULL reset when freeing this header */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2868 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2869 u_entry_T *uep, *nuep;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2870
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2871 /* Check for pointers to the header that become invalid now. */
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2872 if (buf->b_u_curhead == uhp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2873 buf->b_u_curhead = NULL;
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2874 if (buf->b_u_newhead == uhp)
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2875 buf->b_u_newhead = NULL; /* freeing the newest entry */
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2876 if (uhpp != NULL && uhp == *uhpp)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2877 *uhpp = NULL;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2878
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2879 for (uep = uhp->uh_entry; uep != NULL; uep = nuep)
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2880 {
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2881 nuep = uep->ue_next;
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2882 u_freeentry(uep, uep->ue_size);
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2883 }
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
2884
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2885 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2886 uhp->uh_magic = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2887 #endif
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2888 vim_free((char_u *)uhp);
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
2889 --buf->b_u_numhead;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 * free entry 'uep' and 'n' lines in uep->ue_array[]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 u_freeentry(uep, n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 u_entry_T *uep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 {
414
8ab9c77240d4 updated for version 7.0108
vimboss
parents: 407
diff changeset
2900 while (n > 0)
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2901 vim_free(uep->ue_array[--n]);
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2902 vim_free((char_u *)uep->ue_array);
1415
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2903 #ifdef U_DEBUG
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2904 uep->ue_magic = 0;
20b52d44daaf updated for version 7.1-130
vimboss
parents: 1210
diff changeset
2905 #endif
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2906 vim_free((char_u *)uep);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 * invalidate the undo buffer; called when storage has already been released
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 u_clearall(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 buf->b_u_newhead = buf->b_u_oldhead = buf->b_u_curhead = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 buf->b_u_synced = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 buf->b_u_numhead = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 buf->b_u_line_ptr = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 buf->b_u_line_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 * save the line "lnum" for the "U" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 u_saveline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 if (lnum == curbuf->b_u_line_lnum) /* line is already saved */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 return;
356
0f2b5d1b8117 updated for version 7.0092
vimboss
parents: 344
diff changeset
2932 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) /* should never happen */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 u_clearline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 curbuf->b_u_line_lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 if (curwin->w_cursor.lnum == lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 curbuf->b_u_line_colnr = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 curbuf->b_u_line_colnr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 if ((curbuf->b_u_line_ptr = u_save_line(lnum)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 * clear the line saved for the "U" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 * (this is used externally for crossing a line while in insert mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 u_clearline()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 if (curbuf->b_u_line_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 {
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2953 vim_free(curbuf->b_u_line_ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 curbuf->b_u_line_ptr = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 curbuf->b_u_line_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 * Implementation of the "U" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 * Differentiation from vi: "U" can be undone with the next "U".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 * We also allow the cursor to be in another line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 u_undoline()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 colnr_T t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 char_u *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 if (undo_off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
2973 if (curbuf->b_u_line_ptr == NULL
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
2974 || curbuf->b_u_line_lnum > curbuf->b_ml.ml_line_count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 }
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
2979
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
2980 /* first save the line for the 'u' command */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 if (u_savecommon(curbuf->b_u_line_lnum - 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 curbuf->b_u_line_lnum + 1, (linenr_T)0) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 oldp = u_save_line(curbuf->b_u_line_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 if (oldp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 do_outofmem_msg((long_u)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 changed_bytes(curbuf->b_u_line_lnum, 0);
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2992 vim_free(curbuf->b_u_line_ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 curbuf->b_u_line_ptr = oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 t = curbuf->b_u_line_colnr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 curbuf->b_u_line_colnr = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 curwin->w_cursor.col = t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 curwin->w_cursor.lnum = curbuf->b_u_line_lnum;
1534
bdfbf8ef447a updated for version 7.1-249
vimboss
parents: 1440
diff changeset
3000 check_cursor_col();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 /*
168
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3004 * Free all allocated memory blocks for the buffer 'buf'.
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3005 */
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3006 void
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3007 u_blockfree(buf)
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3008 buf_T *buf;
4d9eabb1396e updated for version 7.0051
vimboss
parents: 33
diff changeset
3009 {
753
ac005a544e24 updated for version 7.0223
vimboss
parents: 697
diff changeset
3010 while (buf->b_u_oldhead != NULL)
758
d591d4ceeaee updated for version 7.0224
vimboss
parents: 753
diff changeset
3011 u_freeheader(buf, buf->b_u_oldhead, NULL);
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3012 vim_free(buf->b_u_line_ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 /*
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3016 * u_save_line(): allocate memory and copy line 'lnum' into it.
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3017 * Returns NULL when out of memory.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 u_save_line(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 {
2230
290ee42cae85 Remove old and unused method to allocate memory for undo.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
3023 return vim_strsave(ml_get(lnum));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 * Check if the 'modified' flag is set, or 'ff' has changed (only need to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 * check the first character, because it can only be "dos", "unix" or "mac").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 * "nofile" and "scratch" type buffers are considered to always be unchanged.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 bufIsChanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 !bt_dontwrite(buf) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 (buf->b_changed || file_ff_differs(buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 curbufIsChanged()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 !bt_dontwrite(curbuf) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 (curbuf->b_changed || file_ff_differs(curbuf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 }