comparison src/memline.c @ 18800:f41b55f9357c v8.1.2388

patch 8.1.2388: using old C style comments Commit: https://github.com/vim/vim/commit/4ba37b5833de99db9e9afe8928b31c864182405c Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 4 21:57:43 2019 +0100 patch 8.1.2388: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Wed, 04 Dec 2019 22:00:04 +0100
parents 49b78d6465e5
children e40814841406
comparison
equal deleted inserted replaced
18799:d7d0942e231b 18800:f41b55f9357c
5 * Do ":help uganda" in Vim to read copying and usage conditions. 5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed. 6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code. 7 * See README.txt for an overview of the Vim source code.
8 */ 8 */
9 9
10 /* for debugging */ 10 // for debugging
11 /* #define CHECK(c, s) do { if (c) emsg((s)); } while (0) */ 11 // #define CHECK(c, s) do { if (c) emsg((s)); } while (0)
12 #define CHECK(c, s) do { /**/ } while (0) 12 #define CHECK(c, s) do { /**/ } while (0)
13 13
14 /* 14 /*
15 * memline.c: Contains the functions for appending, deleting and changing the 15 * memline.c: Contains the functions for appending, deleting and changing the
16 * text lines. The memfile functions are used to store the information in 16 * text lines. The memfile functions are used to store the information in
42 * mf_get(). 42 * mf_get().
43 */ 43 */
44 44
45 #include "vim.h" 45 #include "vim.h"
46 46
47 #ifndef UNIX /* it's in os_unix.h for Unix */ 47 #ifndef UNIX // it's in os_unix.h for Unix
48 # include <time.h> 48 # include <time.h>
49 #endif 49 #endif
50 50
51 #if defined(SASC) || defined(__amigaos4__) 51 #if defined(SASC) || defined(__amigaos4__)
52 # include <proto/dos.h> /* for Open() and Close() */ 52 # include <proto/dos.h> // for Open() and Close()
53 #endif 53 #endif
54 54
55 typedef struct block0 ZERO_BL; /* contents of the first block */ 55 typedef struct block0 ZERO_BL; // contents of the first block
56 typedef struct pointer_block PTR_BL; /* contents of a pointer block */ 56 typedef struct pointer_block PTR_BL; // contents of a pointer block
57 typedef struct data_block DATA_BL; /* contents of a data block */ 57 typedef struct data_block DATA_BL; // contents of a data block
58 typedef struct pointer_entry PTR_EN; /* block/line-count pair */ 58 typedef struct pointer_entry PTR_EN; // block/line-count pair
59 59
60 #define DATA_ID (('d' << 8) + 'a') /* data block id */ 60 #define DATA_ID (('d' << 8) + 'a') // data block id
61 #define PTR_ID (('p' << 8) + 't') /* pointer block id */ 61 #define PTR_ID (('p' << 8) + 't') // pointer block id
62 #define BLOCK0_ID0 'b' /* block 0 id 0 */ 62 #define BLOCK0_ID0 'b' // block 0 id 0
63 #define BLOCK0_ID1 '0' /* block 0 id 1 */ 63 #define BLOCK0_ID1 '0' // block 0 id 1
64 #define BLOCK0_ID1_C0 'c' /* block 0 id 1 'cm' 0 */ 64 #define BLOCK0_ID1_C0 'c' // block 0 id 1 'cm' 0
65 #define BLOCK0_ID1_C1 'C' /* block 0 id 1 'cm' 1 */ 65 #define BLOCK0_ID1_C1 'C' // block 0 id 1 'cm' 1
66 #define BLOCK0_ID1_C2 'd' /* block 0 id 1 'cm' 2 */ 66 #define BLOCK0_ID1_C2 'd' // block 0 id 1 'cm' 2
67 67
68 #if defined(FEAT_CRYPT) 68 #if defined(FEAT_CRYPT)
69 static int id1_codes[] = { 69 static int id1_codes[] = {
70 BLOCK0_ID1_C0, /* CRYPT_M_ZIP */ 70 BLOCK0_ID1_C0, // CRYPT_M_ZIP
71 BLOCK0_ID1_C1, /* CRYPT_M_BF */ 71 BLOCK0_ID1_C1, // CRYPT_M_BF
72 BLOCK0_ID1_C2, /* CRYPT_M_BF2 */ 72 BLOCK0_ID1_C2, // CRYPT_M_BF2
73 }; 73 };
74 #endif 74 #endif
75 75
76 /* 76 /*
77 * pointer to a block, used in a pointer block 77 * pointer to a block, used in a pointer block
78 */ 78 */
79 struct pointer_entry 79 struct pointer_entry
80 { 80 {
81 blocknr_T pe_bnum; /* block number */ 81 blocknr_T pe_bnum; // block number
82 linenr_T pe_line_count; /* number of lines in this branch */ 82 linenr_T pe_line_count; // number of lines in this branch
83 linenr_T pe_old_lnum; /* lnum for this block (for recovery) */ 83 linenr_T pe_old_lnum; // lnum for this block (for recovery)
84 int pe_page_count; /* number of pages in block pe_bnum */ 84 int pe_page_count; // number of pages in block pe_bnum
85 }; 85 };
86 86
87 /* 87 /*
88 * A pointer block contains a list of branches in the tree. 88 * A pointer block contains a list of branches in the tree.
89 */ 89 */
90 struct pointer_block 90 struct pointer_block
91 { 91 {
92 short_u pb_id; /* ID for pointer block: PTR_ID */ 92 short_u pb_id; // ID for pointer block: PTR_ID
93 short_u pb_count; /* number of pointers in this block */ 93 short_u pb_count; // number of pointers in this block
94 short_u pb_count_max; /* maximum value for pb_count */ 94 short_u pb_count_max; // maximum value for pb_count
95 PTR_EN pb_pointer[1]; /* list of pointers to blocks (actually longer) 95 PTR_EN pb_pointer[1]; // list of pointers to blocks (actually longer)
96 * followed by empty space until end of page */ 96 // followed by empty space until end of page
97 }; 97 };
98 98
99 /* 99 /*
100 * A data block is a leaf in the tree. 100 * A data block is a leaf in the tree.
101 * 101 *
103 * in the block is put at the end, the text of the second line in front of it, 103 * in the block is put at the end, the text of the second line in front of it,
104 * etc. Thus the order of the lines is the opposite of the line number. 104 * etc. Thus the order of the lines is the opposite of the line number.
105 */ 105 */
106 struct data_block 106 struct data_block
107 { 107 {
108 short_u db_id; /* ID for data block: DATA_ID */ 108 short_u db_id; // ID for data block: DATA_ID
109 unsigned db_free; /* free space available */ 109 unsigned db_free; // free space available
110 unsigned db_txt_start; /* byte where text starts */ 110 unsigned db_txt_start; // byte where text starts
111 unsigned db_txt_end; /* byte just after data block */ 111 unsigned db_txt_end; // byte just after data block
112 linenr_T db_line_count; /* number of lines in this block */ 112 linenr_T db_line_count; // number of lines in this block
113 unsigned db_index[1]; /* index for start of line (actually bigger) 113 unsigned db_index[1]; // index for start of line (actually bigger)
114 * followed by empty space upto db_txt_start 114 // followed by empty space upto db_txt_start
115 * followed by the text in the lines until 115 // followed by the text in the lines until
116 * end of page */ 116 // end of page
117 }; 117 };
118 118
119 /* 119 /*
120 * The low bits of db_index hold the actual index. The topmost bit is 120 * The low bits of db_index hold the actual index. The topmost bit is
121 * used for the global command to be able to mark a line. 121 * used for the global command to be able to mark a line.
125 * lines are inserted or deleted. 125 * lines are inserted or deleted.
126 */ 126 */
127 #define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1)) 127 #define DB_MARKED ((unsigned)1 << ((sizeof(unsigned) * 8) - 1))
128 #define DB_INDEX_MASK (~DB_MARKED) 128 #define DB_INDEX_MASK (~DB_MARKED)
129 129
130 #define INDEX_SIZE (sizeof(unsigned)) /* size of one db_index entry */ 130 #define INDEX_SIZE (sizeof(unsigned)) // size of one db_index entry
131 #define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) /* size of data block header */ 131 #define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) // size of data block header
132 132
133 #define B0_FNAME_SIZE_ORG 900 /* what it was in older versions */ 133 #define B0_FNAME_SIZE_ORG 900 // what it was in older versions
134 #define B0_FNAME_SIZE_NOCRYPT 898 /* 2 bytes used for other things */ 134 #define B0_FNAME_SIZE_NOCRYPT 898 // 2 bytes used for other things
135 #define B0_FNAME_SIZE_CRYPT 890 /* 10 bytes used for other things */ 135 #define B0_FNAME_SIZE_CRYPT 890 // 10 bytes used for other things
136 #define B0_UNAME_SIZE 40 136 #define B0_UNAME_SIZE 40
137 #define B0_HNAME_SIZE 40 137 #define B0_HNAME_SIZE 40
138 /* 138 /*
139 * Restrict the numbers to 32 bits, otherwise most compilers will complain. 139 * Restrict the numbers to 32 bits, otherwise most compilers will complain.
140 * This won't detect a 64 bit machine that only swaps a byte in the top 32 140 * This won't detect a 64 bit machine that only swaps a byte in the top 32
157 * different machines. b0_magic_* is used to check the byte order and size of 157 * different machines. b0_magic_* is used to check the byte order and size of
158 * variables, because the rest of the swap file is not portable. 158 * variables, because the rest of the swap file is not portable.
159 */ 159 */
160 struct block0 160 struct block0
161 { 161 {
162 char_u b0_id[2]; /* id for block 0: BLOCK0_ID0 and BLOCK0_ID1, 162 char_u b0_id[2]; // id for block 0: BLOCK0_ID0 and BLOCK0_ID1,
163 * BLOCK0_ID1_C0, BLOCK0_ID1_C1, etc. */ 163 // BLOCK0_ID1_C0, BLOCK0_ID1_C1, etc.
164 char_u b0_version[10]; /* Vim version string */ 164 char_u b0_version[10]; // Vim version string
165 char_u b0_page_size[4];/* number of bytes per page */ 165 char_u b0_page_size[4];// number of bytes per page
166 char_u b0_mtime[4]; /* last modification time of file */ 166 char_u b0_mtime[4]; // last modification time of file
167 char_u b0_ino[4]; /* inode of b0_fname */ 167 char_u b0_ino[4]; // inode of b0_fname
168 char_u b0_pid[4]; /* process id of creator (or 0) */ 168 char_u b0_pid[4]; // process id of creator (or 0)
169 char_u b0_uname[B0_UNAME_SIZE]; /* name of user (uid if no name) */ 169 char_u b0_uname[B0_UNAME_SIZE]; // name of user (uid if no name)
170 char_u b0_hname[B0_HNAME_SIZE]; /* host name (if it has a name) */ 170 char_u b0_hname[B0_HNAME_SIZE]; // host name (if it has a name)
171 char_u b0_fname[B0_FNAME_SIZE_ORG]; /* name of file being edited */ 171 char_u b0_fname[B0_FNAME_SIZE_ORG]; // name of file being edited
172 long b0_magic_long; /* check for byte order of long */ 172 long b0_magic_long; // check for byte order of long
173 int b0_magic_int; /* check for byte order of int */ 173 int b0_magic_int; // check for byte order of int
174 short b0_magic_short; /* check for byte order of short */ 174 short b0_magic_short; // check for byte order of short
175 char_u b0_magic_char; /* check for last char */ 175 char_u b0_magic_char; // check for last char
176 }; 176 };
177 177
178 /* 178 /*
179 * Note: b0_dirty and b0_flags are put at the end of the file name. For very 179 * Note: b0_dirty and b0_flags are put at the end of the file name. For very
180 * long file names in older versions of Vim they are invalid. 180 * long file names in older versions of Vim they are invalid.
193 * Crypt seed goes here, 8 bytes. New in Vim 7.3. 193 * Crypt seed goes here, 8 bytes. New in Vim 7.3.
194 * Without encryption these bytes may be used for 'fenc'. 194 * Without encryption these bytes may be used for 'fenc'.
195 */ 195 */
196 #define b0_seed b0_fname[B0_FNAME_SIZE_ORG - 2 - MF_SEED_LEN] 196 #define b0_seed b0_fname[B0_FNAME_SIZE_ORG - 2 - MF_SEED_LEN]
197 197
198 /* The lowest two bits contain the fileformat. Zero means it's not set 198 // The lowest two bits contain the fileformat. Zero means it's not set
199 * (compatible with Vim 6.x), otherwise it's EOL_UNIX + 1, EOL_DOS + 1 or 199 // (compatible with Vim 6.x), otherwise it's EOL_UNIX + 1, EOL_DOS + 1 or
200 * EOL_MAC + 1. */ 200 // EOL_MAC + 1.
201 #define B0_FF_MASK 3 201 #define B0_FF_MASK 3
202 202
203 /* Swap file is in directory of edited file. Used to find the file from 203 // Swap file is in directory of edited file. Used to find the file from
204 * different mount points. */ 204 // different mount points.
205 #define B0_SAME_DIR 4 205 #define B0_SAME_DIR 4
206 206
207 /* The 'fileencoding' is at the end of b0_fname[], with a NUL in front of it. 207 // The 'fileencoding' is at the end of b0_fname[], with a NUL in front of it.
208 * When empty there is only the NUL. */ 208 // When empty there is only the NUL.
209 #define B0_HAS_FENC 8 209 #define B0_HAS_FENC 8
210 210
211 #define STACK_INCR 5 /* nr of entries added to ml_stack at a time */ 211 #define STACK_INCR 5 // nr of entries added to ml_stack at a time
212 212
213 /* 213 /*
214 * The line number where the first mark may be is remembered. 214 * The line number where the first mark may be is remembered.
215 * If it is 0 there are no marks at all. 215 * If it is 0 there are no marks at all.
216 * (always used for the current buffer only, no buffer change possible while 216 * (always used for the current buffer only, no buffer change possible while
219 static linenr_T lowest_marked = 0; 219 static linenr_T lowest_marked = 0;
220 220
221 /* 221 /*
222 * arguments for ml_find_line() 222 * arguments for ml_find_line()
223 */ 223 */
224 #define ML_DELETE 0x11 /* delete line */ 224 #define ML_DELETE 0x11 // delete line
225 #define ML_INSERT 0x12 /* insert line */ 225 #define ML_INSERT 0x12 // insert line
226 #define ML_FIND 0x13 /* just find the line */ 226 #define ML_FIND 0x13 // just find the line
227 #define ML_FLUSH 0x02 /* flush locked block */ 227 #define ML_FLUSH 0x02 // flush locked block
228 #define ML_SIMPLE(x) (x & 0x10) /* DEL, INS or FIND */ 228 #define ML_SIMPLE(x) (x & 0x10) // DEL, INS or FIND
229 229
230 /* argument for ml_upd_block0() */ 230 // argument for ml_upd_block0()
231 typedef enum { 231 typedef enum {
232 UB_FNAME = 0 /* update timestamp and filename */ 232 UB_FNAME = 0 // update timestamp and filename
233 , UB_SAME_DIR /* update the B0_SAME_DIR flag */ 233 , UB_SAME_DIR // update the B0_SAME_DIR flag
234 , UB_CRYPT /* update crypt key */ 234 , UB_CRYPT // update crypt key
235 } upd_block0_T; 235 } upd_block0_T;
236 236
237 #ifdef FEAT_CRYPT 237 #ifdef FEAT_CRYPT
238 static void ml_set_b0_crypt(buf_T *buf, ZERO_BL *b0p); 238 static void ml_set_b0_crypt(buf_T *buf, ZERO_BL *b0p);
239 #endif 239 #endif
279 DATA_BL *dp; 279 DATA_BL *dp;
280 280
281 /* 281 /*
282 * init fields in memline struct 282 * init fields in memline struct
283 */ 283 */
284 buf->b_ml.ml_stack_size = 0; /* no stack yet */ 284 buf->b_ml.ml_stack_size = 0; // no stack yet
285 buf->b_ml.ml_stack = NULL; /* no stack yet */ 285 buf->b_ml.ml_stack = NULL; // no stack yet
286 buf->b_ml.ml_stack_top = 0; /* nothing in the stack */ 286 buf->b_ml.ml_stack_top = 0; // nothing in the stack
287 buf->b_ml.ml_locked = NULL; /* no cached block */ 287 buf->b_ml.ml_locked = NULL; // no cached block
288 buf->b_ml.ml_line_lnum = 0; /* no cached line */ 288 buf->b_ml.ml_line_lnum = 0; // no cached line
289 #ifdef FEAT_BYTEOFF 289 #ifdef FEAT_BYTEOFF
290 buf->b_ml.ml_chunksize = NULL; 290 buf->b_ml.ml_chunksize = NULL;
291 #endif 291 #endif
292 292
293 if (cmdmod.noswapfile) 293 if (cmdmod.noswapfile)
381 pp = (PTR_BL *)(hp->bh_data); 381 pp = (PTR_BL *)(hp->bh_data);
382 pp->pb_count = 1; 382 pp->pb_count = 1;
383 pp->pb_pointer[0].pe_bnum = 2; 383 pp->pb_pointer[0].pe_bnum = 2;
384 pp->pb_pointer[0].pe_page_count = 1; 384 pp->pb_pointer[0].pe_page_count = 1;
385 pp->pb_pointer[0].pe_old_lnum = 1; 385 pp->pb_pointer[0].pe_old_lnum = 1;
386 pp->pb_pointer[0].pe_line_count = 1; /* line count after insertion */ 386 pp->pb_pointer[0].pe_line_count = 1; // line count after insertion
387 mf_put(mfp, hp, TRUE, FALSE); 387 mf_put(mfp, hp, TRUE, FALSE);
388 388
389 /* 389 /*
390 * Allocate first data block and create an empty line 1. 390 * Allocate first data block and create an empty line 1.
391 */ 391 */
396 iemsg(_("E298: Didn't get block nr 2?")); 396 iemsg(_("E298: Didn't get block nr 2?"));
397 goto error; 397 goto error;
398 } 398 }
399 399
400 dp = (DATA_BL *)(hp->bh_data); 400 dp = (DATA_BL *)(hp->bh_data);
401 dp->db_index[0] = --dp->db_txt_start; /* at end of block */ 401 dp->db_index[0] = --dp->db_txt_start; // at end of block
402 dp->db_free -= 1 + INDEX_SIZE; 402 dp->db_free -= 1 + INDEX_SIZE;
403 dp->db_line_count = 1; 403 dp->db_line_count = 1;
404 *((char_u *)dp + dp->db_txt_start) = NUL; /* empty line */ 404 *((char_u *)dp + dp->db_txt_start) = NUL; // empty line
405 405
406 return OK; 406 return OK;
407 407
408 error: 408 error:
409 if (mfp != NULL) 409 if (mfp != NULL)
410 { 410 {
411 if (hp) 411 if (hp)
412 mf_put(mfp, hp, FALSE, FALSE); 412 mf_put(mfp, hp, FALSE, FALSE);
413 mf_close(mfp, TRUE); /* will also free(mfp->mf_fname) */ 413 mf_close(mfp, TRUE); // will also free(mfp->mf_fname)
414 } 414 }
415 buf->b_ml.ml_mfp = NULL; 415 buf->b_ml.ml_mfp = NULL;
416 return FAIL; 416 return FAIL;
417 } 417 }
418 418
427 { 427 {
428 int method_nr = crypt_get_method_nr(buf); 428 int method_nr = crypt_get_method_nr(buf);
429 429
430 if (method_nr > CRYPT_M_ZIP) 430 if (method_nr > CRYPT_M_ZIP)
431 { 431 {
432 /* Generate a seed and store it in the memfile. */ 432 // Generate a seed and store it in the memfile.
433 sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0); 433 sha2_seed(buf->b_ml.ml_mfp->mf_seed, MF_SEED_LEN, NULL, 0);
434 } 434 }
435 } 435 }
436 } 436 }
437 437
448 int method_nr = crypt_get_method_nr(buf); 448 int method_nr = crypt_get_method_nr(buf);
449 449
450 b0p->b0_id[1] = id1_codes[method_nr]; 450 b0p->b0_id[1] = id1_codes[method_nr];
451 if (method_nr > CRYPT_M_ZIP) 451 if (method_nr > CRYPT_M_ZIP)
452 { 452 {
453 /* Generate a seed and store it in block 0 and in the memfile. */ 453 // Generate a seed and store it in block 0 and in the memfile.
454 sha2_seed(&b0p->b0_seed, MF_SEED_LEN, NULL, 0); 454 sha2_seed(&b0p->b0_seed, MF_SEED_LEN, NULL, 0);
455 mch_memmove(buf->b_ml.ml_mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN); 455 mch_memmove(buf->b_ml.ml_mfp->mf_seed, &b0p->b0_seed, MF_SEED_LEN);
456 } 456 }
457 } 457 }
458 } 458 }
482 blocknr_T bnum; 482 blocknr_T bnum;
483 int top; 483 int top;
484 int old_method; 484 int old_method;
485 485
486 if (mfp == NULL) 486 if (mfp == NULL)
487 return; /* no memfile yet, nothing to do */ 487 return; // no memfile yet, nothing to do
488 old_method = crypt_method_nr_from_name(old_cm); 488 old_method = crypt_method_nr_from_name(old_cm);
489 489
490 /* First make sure the swapfile is in a consistent state, using the old 490 // First make sure the swapfile is in a consistent state, using the old
491 * key and method. */ 491 // key and method.
492 { 492 {
493 char_u *new_key = buf->b_p_key; 493 char_u *new_key = buf->b_p_key;
494 char_u *new_buf_cm = buf->b_p_cm; 494 char_u *new_buf_cm = buf->b_p_cm;
495 495
496 buf->b_p_key = old_key; 496 buf->b_p_key = old_key;
498 ml_preserve(buf, FALSE); 498 ml_preserve(buf, FALSE);
499 buf->b_p_key = new_key; 499 buf->b_p_key = new_key;
500 buf->b_p_cm = new_buf_cm; 500 buf->b_p_cm = new_buf_cm;
501 } 501 }
502 502
503 /* Set the key, method and seed to be used for reading, these must be the 503 // Set the key, method and seed to be used for reading, these must be the
504 * old values. */ 504 // old values.
505 mfp->mf_old_key = old_key; 505 mfp->mf_old_key = old_key;
506 mfp->mf_old_cm = old_method; 506 mfp->mf_old_cm = old_method;
507 if (old_method > 0 && *old_key != NUL) 507 if (old_method > 0 && *old_key != NUL)
508 mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN); 508 mch_memmove(mfp->mf_old_seed, mfp->mf_seed, MF_SEED_LEN);
509 509
510 /* Update block 0 with the crypt flag and may set a new seed. */ 510 // Update block 0 with the crypt flag and may set a new seed.
511 ml_upd_block0(buf, UB_CRYPT); 511 ml_upd_block0(buf, UB_CRYPT);
512 512
513 if (mfp->mf_infile_count > 2) 513 if (mfp->mf_infile_count > 2)
514 { 514 {
515 /* 515 /*
516 * Need to read back all data blocks from disk, decrypt them with the 516 * Need to read back all data blocks from disk, decrypt them with the
517 * old key/method and mark them to be written. The algorithm is 517 * old key/method and mark them to be written. The algorithm is
518 * similar to what happens in ml_recover(), but we skip negative block 518 * similar to what happens in ml_recover(), but we skip negative block
519 * numbers. 519 * numbers.
520 */ 520 */
521 ml_flush_line(buf); /* flush buffered line */ 521 ml_flush_line(buf); // flush buffered line
522 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ 522 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block
523 523
524 hp = NULL; 524 hp = NULL;
525 bnum = 1; /* start with block 1 */ 525 bnum = 1; // start with block 1
526 page_count = 1; /* which is 1 page */ 526 page_count = 1; // which is 1 page
527 idx = 0; /* start with first index in block 1 */ 527 idx = 0; // start with first index in block 1
528 error = 0; 528 error = 0;
529 buf->b_ml.ml_stack_top = 0; 529 buf->b_ml.ml_stack_top = 0;
530 VIM_CLEAR(buf->b_ml.ml_stack); 530 VIM_CLEAR(buf->b_ml.ml_stack);
531 buf->b_ml.ml_stack_size = 0; /* no stack yet */ 531 buf->b_ml.ml_stack_size = 0; // no stack yet
532 532
533 for ( ; !got_int; line_breakcheck()) 533 for ( ; !got_int; line_breakcheck())
534 { 534 {
535 if (hp != NULL) 535 if (hp != NULL)
536 mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ 536 mf_put(mfp, hp, FALSE, FALSE); // release previous block
537 537
538 /* get the block (pointer or data) */ 538 // get the block (pointer or data)
539 if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) 539 if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL)
540 { 540 {
541 if (bnum == 1) 541 if (bnum == 1)
542 break; 542 break;
543 ++error; 543 ++error;
544 } 544 }
545 else 545 else
546 { 546 {
547 pp = (PTR_BL *)(hp->bh_data); 547 pp = (PTR_BL *)(hp->bh_data);
548 if (pp->pb_id == PTR_ID) /* it is a pointer block */ 548 if (pp->pb_id == PTR_ID) // it is a pointer block
549 { 549 {
550 if (pp->pb_count == 0) 550 if (pp->pb_count == 0)
551 { 551 {
552 /* empty block? */ 552 // empty block?
553 ++error; 553 ++error;
554 } 554 }
555 else if (idx < (int)pp->pb_count) /* go a block deeper */ 555 else if (idx < (int)pp->pb_count) // go a block deeper
556 { 556 {
557 if (pp->pb_pointer[idx].pe_bnum < 0) 557 if (pp->pb_pointer[idx].pe_bnum < 0)
558 { 558 {
559 /* Skip data block with negative block number. 559 // Skip data block with negative block number.
560 * Should not happen, because of the ml_preserve() 560 // Should not happen, because of the ml_preserve()
561 * above. Get same block again for next index. */ 561 // above. Get same block again for next index.
562 ++idx; 562 ++idx;
563 continue; 563 continue;
564 } 564 }
565 565
566 /* going one block deeper in the tree, new entry in 566 // going one block deeper in the tree, new entry in
567 * stack */ 567 // stack
568 if ((top = ml_add_stack(buf)) < 0) 568 if ((top = ml_add_stack(buf)) < 0)
569 { 569 {
570 ++error; 570 ++error;
571 break; /* out of memory */ 571 break; // out of memory
572 } 572 }
573 ip = &(buf->b_ml.ml_stack[top]); 573 ip = &(buf->b_ml.ml_stack[top]);
574 ip->ip_bnum = bnum; 574 ip->ip_bnum = bnum;
575 ip->ip_index = idx; 575 ip->ip_index = idx;
576 576
578 page_count = pp->pb_pointer[idx].pe_page_count; 578 page_count = pp->pb_pointer[idx].pe_page_count;
579 idx = 0; 579 idx = 0;
580 continue; 580 continue;
581 } 581 }
582 } 582 }
583 else /* not a pointer block */ 583 else // not a pointer block
584 { 584 {
585 dp = (DATA_BL *)(hp->bh_data); 585 dp = (DATA_BL *)(hp->bh_data);
586 if (dp->db_id != DATA_ID) /* block id wrong */ 586 if (dp->db_id != DATA_ID) // block id wrong
587 ++error; 587 ++error;
588 else 588 else
589 { 589 {
590 /* It is a data block, need to write it back to disk. */ 590 // It is a data block, need to write it back to disk.
591 mf_put(mfp, hp, TRUE, FALSE); 591 mf_put(mfp, hp, TRUE, FALSE);
592 hp = NULL; 592 hp = NULL;
593 } 593 }
594 } 594 }
595 } 595 }
596 596
597 if (buf->b_ml.ml_stack_top == 0) /* finished */ 597 if (buf->b_ml.ml_stack_top == 0) // finished
598 break; 598 break;
599 599
600 /* go one block up in the tree */ 600 // go one block up in the tree
601 ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); 601 ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]);
602 bnum = ip->ip_bnum; 602 bnum = ip->ip_bnum;
603 idx = ip->ip_index + 1; /* go to next index */ 603 idx = ip->ip_index + 1; // go to next index
604 page_count = 1; 604 page_count = 1;
605 } 605 }
606 if (hp != NULL) 606 if (hp != NULL)
607 mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ 607 mf_put(mfp, hp, FALSE, FALSE); // release previous block
608 608
609 if (error > 0) 609 if (error > 0)
610 emsg(_("E843: Error while updating swap file crypt")); 610 emsg(_("E843: Error while updating swap file crypt"));
611 } 611 }
612 612
628 #if defined(MSWIN) 628 #if defined(MSWIN)
629 char_u *p; 629 char_u *p;
630 #endif 630 #endif
631 631
632 mfp = buf->b_ml.ml_mfp; 632 mfp = buf->b_ml.ml_mfp;
633 if (mfp->mf_fd < 0) /* there is no swap file yet */ 633 if (mfp->mf_fd < 0) // there is no swap file yet
634 { 634 {
635 /* 635 /*
636 * When 'updatecount' is 0 and 'noswapfile' there is no swap file. 636 * When 'updatecount' is 0 and 'noswapfile' there is no swap file.
637 * For help files we will make a swap file now. 637 * For help files we will make a swap file now.
638 */ 638 */
639 if (p_uc != 0 && !cmdmod.noswapfile) 639 if (p_uc != 0 && !cmdmod.noswapfile)
640 ml_open_file(buf); /* create a swap file */ 640 ml_open_file(buf); // create a swap file
641 return; 641 return;
642 } 642 }
643 643
644 /* 644 /*
645 * Try all directories in the 'directory' option. 645 * Try all directories in the 'directory' option.
646 */ 646 */
647 dirp = p_dir; 647 dirp = p_dir;
648 for (;;) 648 for (;;)
649 { 649 {
650 if (*dirp == NUL) /* tried all directories, fail */ 650 if (*dirp == NUL) // tried all directories, fail
651 break; 651 break;
652 fname = findswapname(buf, &dirp, mfp->mf_fname); 652 fname = findswapname(buf, &dirp, mfp->mf_fname);
653 /* alloc's fname */ 653 // alloc's fname
654 if (dirp == NULL) /* out of memory */ 654 if (dirp == NULL) // out of memory
655 break; 655 break;
656 if (fname == NULL) /* no file name found for this dir */ 656 if (fname == NULL) // no file name found for this dir
657 continue; 657 continue;
658 658
659 #if defined(MSWIN) 659 #if defined(MSWIN)
660 /* 660 /*
661 * Set full pathname for swap file now, because a ":!cd dir" may 661 * Set full pathname for swap file now, because a ":!cd dir" may
665 vim_free(fname); 665 vim_free(fname);
666 fname = p; 666 fname = p;
667 if (fname == NULL) 667 if (fname == NULL)
668 continue; 668 continue;
669 #endif 669 #endif
670 /* if the file name is the same we don't have to do anything */ 670 // if the file name is the same we don't have to do anything
671 if (fnamecmp(fname, mfp->mf_fname) == 0) 671 if (fnamecmp(fname, mfp->mf_fname) == 0)
672 { 672 {
673 vim_free(fname); 673 vim_free(fname);
674 success = TRUE; 674 success = TRUE;
675 break; 675 break;
676 } 676 }
677 /* need to close the swap file before renaming */ 677 // need to close the swap file before renaming
678 if (mfp->mf_fd >= 0) 678 if (mfp->mf_fd >= 0)
679 { 679 {
680 close(mfp->mf_fd); 680 close(mfp->mf_fd);
681 mfp->mf_fd = -1; 681 mfp->mf_fd = -1;
682 } 682 }
683 683
684 /* try to rename the swap file */ 684 // try to rename the swap file
685 if (vim_rename(mfp->mf_fname, fname) == 0) 685 if (vim_rename(mfp->mf_fname, fname) == 0)
686 { 686 {
687 success = TRUE; 687 success = TRUE;
688 vim_free(mfp->mf_fname); 688 vim_free(mfp->mf_fname);
689 mfp->mf_fname = fname; 689 mfp->mf_fname = fname;
690 vim_free(mfp->mf_ffname); 690 vim_free(mfp->mf_ffname);
691 #if defined(MSWIN) 691 #if defined(MSWIN)
692 mfp->mf_ffname = NULL; /* mf_fname is full pathname already */ 692 mfp->mf_ffname = NULL; // mf_fname is full pathname already
693 #else 693 #else
694 mf_set_ffname(mfp); 694 mf_set_ffname(mfp);
695 #endif 695 #endif
696 ml_upd_block0(buf, UB_SAME_DIR); 696 ml_upd_block0(buf, UB_SAME_DIR);
697 break; 697 break;
698 } 698 }
699 vim_free(fname); /* this fname didn't work, try another */ 699 vim_free(fname); // this fname didn't work, try another
700 } 700 }
701 701
702 if (mfp->mf_fd == -1) /* need to (re)open the swap file */ 702 if (mfp->mf_fd == -1) // need to (re)open the swap file
703 { 703 {
704 mfp->mf_fd = mch_open((char *)mfp->mf_fname, O_RDWR | O_EXTRA, 0); 704 mfp->mf_fd = mch_open((char *)mfp->mf_fname, O_RDWR | O_EXTRA, 0);
705 if (mfp->mf_fd < 0) 705 if (mfp->mf_fd < 0)
706 { 706 {
707 /* could not (re)open the swap file, what can we do???? */ 707 // could not (re)open the swap file, what can we do????
708 emsg(_("E301: Oops, lost the swap file!!!")); 708 emsg(_("E301: Oops, lost the swap file!!!"));
709 return; 709 return;
710 } 710 }
711 #ifdef HAVE_FD_CLOEXEC 711 #ifdef HAVE_FD_CLOEXEC
712 { 712 {
747 char_u *fname; 747 char_u *fname;
748 char_u *dirp; 748 char_u *dirp;
749 749
750 mfp = buf->b_ml.ml_mfp; 750 mfp = buf->b_ml.ml_mfp;
751 if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile) 751 if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile)
752 return; /* nothing to do */ 752 return; // nothing to do
753 753
754 #ifdef FEAT_SPELL 754 #ifdef FEAT_SPELL
755 /* For a spell buffer use a temp file name. */ 755 // For a spell buffer use a temp file name.
756 if (buf->b_spell) 756 if (buf->b_spell)
757 { 757 {
758 fname = vim_tempname('s', FALSE); 758 fname = vim_tempname('s', FALSE);
759 if (fname != NULL) 759 if (fname != NULL)
760 (void)mf_open_file(mfp, fname); /* consumes fname! */ 760 (void)mf_open_file(mfp, fname); // consumes fname!
761 buf->b_may_swap = FALSE; 761 buf->b_may_swap = FALSE;
762 return; 762 return;
763 } 763 }
764 #endif 764 #endif
765 765
769 dirp = p_dir; 769 dirp = p_dir;
770 for (;;) 770 for (;;)
771 { 771 {
772 if (*dirp == NUL) 772 if (*dirp == NUL)
773 break; 773 break;
774 /* There is a small chance that between choosing the swap file name 774 // There is a small chance that between choosing the swap file name
775 * and creating it, another Vim creates the file. In that case the 775 // and creating it, another Vim creates the file. In that case the
776 * creation will fail and we will use another directory. */ 776 // creation will fail and we will use another directory.
777 fname = findswapname(buf, &dirp, NULL); /* allocates fname */ 777 fname = findswapname(buf, &dirp, NULL); // allocates fname
778 if (dirp == NULL) 778 if (dirp == NULL)
779 break; /* out of memory */ 779 break; // out of memory
780 if (fname == NULL) 780 if (fname == NULL)
781 continue; 781 continue;
782 if (mf_open_file(mfp, fname) == OK) /* consumes fname! */ 782 if (mf_open_file(mfp, fname) == OK) // consumes fname!
783 { 783 {
784 #if defined(MSWIN) 784 #if defined(MSWIN)
785 /* 785 /*
786 * set full pathname for swap file now, because a ":!cd dir" may 786 * set full pathname for swap file now, because a ":!cd dir" may
787 * change directory without us knowing it. 787 * change directory without us knowing it.
788 */ 788 */
789 mf_fullname(mfp); 789 mf_fullname(mfp);
790 #endif 790 #endif
791 ml_upd_block0(buf, UB_SAME_DIR); 791 ml_upd_block0(buf, UB_SAME_DIR);
792 792
793 /* Flush block zero, so others can read it */ 793 // Flush block zero, so others can read it
794 if (mf_sync(mfp, MFS_ZERO) == OK) 794 if (mf_sync(mfp, MFS_ZERO) == OK)
795 { 795 {
796 /* Mark all blocks that should be in the swapfile as dirty. 796 // Mark all blocks that should be in the swapfile as dirty.
797 * Needed for when the 'swapfile' option was reset, so that 797 // Needed for when the 'swapfile' option was reset, so that
798 * the swap file was deleted, and then on again. */ 798 // the swap file was deleted, and then on again.
799 mf_set_dirty(mfp); 799 mf_set_dirty(mfp);
800 break; 800 break;
801 } 801 }
802 /* Writing block 0 failed: close the file and try another dir */ 802 // Writing block 0 failed: close the file and try another dir
803 mf_close_file(buf, FALSE); 803 mf_close_file(buf, FALSE);
804 } 804 }
805 } 805 }
806 806
807 if (*p_dir != NUL && mfp->mf_fname == NULL) 807 if (*p_dir != NUL && mfp->mf_fname == NULL)
811 (void)semsg(_("E303: Unable to open swap file for \"%s\", recovery impossible"), 811 (void)semsg(_("E303: Unable to open swap file for \"%s\", recovery impossible"),
812 buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname); 812 buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname);
813 --no_wait_return; 813 --no_wait_return;
814 } 814 }
815 815
816 /* don't try to open a swap file again */ 816 // don't try to open a swap file again
817 buf->b_may_swap = FALSE; 817 buf->b_may_swap = FALSE;
818 } 818 }
819 819
820 /* 820 /*
821 * If still need to create a swap file, and starting to edit a not-readonly 821 * If still need to create a swap file, and starting to edit a not-readonly
837 * If 'del_file' is TRUE, delete the swap file 837 * If 'del_file' is TRUE, delete the swap file
838 */ 838 */
839 void 839 void
840 ml_close(buf_T *buf, int del_file) 840 ml_close(buf_T *buf, int del_file)
841 { 841 {
842 if (buf->b_ml.ml_mfp == NULL) /* not open */ 842 if (buf->b_ml.ml_mfp == NULL) // not open
843 return; 843 return;
844 mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */ 844 mf_close(buf->b_ml.ml_mfp, del_file); // close the .swp file
845 if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) 845 if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY))
846 vim_free(buf->b_ml.ml_line_ptr); 846 vim_free(buf->b_ml.ml_line_ptr);
847 vim_free(buf->b_ml.ml_stack); 847 vim_free(buf->b_ml.ml_stack);
848 #ifdef FEAT_BYTEOFF 848 #ifdef FEAT_BYTEOFF
849 VIM_CLEAR(buf->b_ml.ml_chunksize); 849 VIM_CLEAR(buf->b_ml.ml_chunksize);
850 #endif 850 #endif
851 buf->b_ml.ml_mfp = NULL; 851 buf->b_ml.ml_mfp = NULL;
852 852
853 /* Reset the "recovered" flag, give the ATTENTION prompt the next time 853 // Reset the "recovered" flag, give the ATTENTION prompt the next time
854 * this buffer is loaded. */ 854 // this buffer is loaded.
855 buf->b_flags &= ~BF_RECOVERED; 855 buf->b_flags &= ~BF_RECOVERED;
856 } 856 }
857 857
858 /* 858 /*
859 * Close all existing memlines and memfiles. 859 * Close all existing memlines and memfiles.
868 868
869 FOR_ALL_BUFFERS(buf) 869 FOR_ALL_BUFFERS(buf)
870 ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0 870 ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0
871 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL)); 871 || vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
872 #ifdef FEAT_SPELL 872 #ifdef FEAT_SPELL
873 spell_delete_wordlist(); /* delete the internal wordlist */ 873 spell_delete_wordlist(); // delete the internal wordlist
874 #endif 874 #endif
875 #ifdef TEMPDIRNAMES 875 #ifdef TEMPDIRNAMES
876 vim_deltempdir(); /* delete created temp directory */ 876 vim_deltempdir(); // delete created temp directory
877 #endif 877 #endif
878 } 878 }
879 879
880 /* 880 /*
881 * Close all memfiles for not modified buffers. 881 * Close all memfiles for not modified buffers.
886 { 886 {
887 buf_T *buf; 887 buf_T *buf;
888 888
889 FOR_ALL_BUFFERS(buf) 889 FOR_ALL_BUFFERS(buf)
890 if (!bufIsChanged(buf)) 890 if (!bufIsChanged(buf))
891 ml_close(buf, TRUE); /* close all not-modified buffers */ 891 ml_close(buf, TRUE); // close all not-modified buffers
892 } 892 }
893 893
894 /* 894 /*
895 * Update the timestamp in the .swp file. 895 * Update the timestamp in the .swp file.
896 * Used when the file has been written. 896 * Used when the file has been written.
932 return; 932 return;
933 hp = mf_get(mfp, (blocknr_T)0, 1); 933 hp = mf_get(mfp, (blocknr_T)0, 1);
934 if (hp == NULL) 934 if (hp == NULL)
935 { 935 {
936 #ifdef FEAT_CRYPT 936 #ifdef FEAT_CRYPT
937 /* Possibly update the seed in the memfile before there is a block0. */ 937 // Possibly update the seed in the memfile before there is a block0.
938 if (what == UB_CRYPT) 938 if (what == UB_CRYPT)
939 ml_set_mfp_crypt(buf); 939 ml_set_mfp_crypt(buf);
940 #endif 940 #endif
941 return; 941 return;
942 } 942 }
950 set_b0_fname(b0p, buf); 950 set_b0_fname(b0p, buf);
951 #ifdef FEAT_CRYPT 951 #ifdef FEAT_CRYPT
952 else if (what == UB_CRYPT) 952 else if (what == UB_CRYPT)
953 ml_set_b0_crypt(buf, b0p); 953 ml_set_b0_crypt(buf, b0p);
954 #endif 954 #endif
955 else /* what == UB_SAME_DIR */ 955 else // what == UB_SAME_DIR
956 set_b0_dir_flag(b0p, buf); 956 set_b0_dir_flag(b0p, buf);
957 } 957 }
958 mf_put(mfp, hp, TRUE, FALSE); 958 mf_put(mfp, hp, TRUE, FALSE);
959 } 959 }
960 960
971 if (buf->b_ffname == NULL) 971 if (buf->b_ffname == NULL)
972 b0p->b0_fname[0] = NUL; 972 b0p->b0_fname[0] = NUL;
973 else 973 else
974 { 974 {
975 #if defined(MSWIN) || defined(AMIGA) 975 #if defined(MSWIN) || defined(AMIGA)
976 /* Systems that cannot translate "~user" back into a path: copy the 976 // Systems that cannot translate "~user" back into a path: copy the
977 * file name unmodified. Do use slashes instead of backslashes for 977 // file name unmodified. Do use slashes instead of backslashes for
978 * portability. */ 978 // portability.
979 vim_strncpy(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT - 1); 979 vim_strncpy(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT - 1);
980 # ifdef BACKSLASH_IN_FILENAME 980 # ifdef BACKSLASH_IN_FILENAME
981 forward_slash(b0p->b0_fname); 981 forward_slash(b0p->b0_fname);
982 # endif 982 # endif
983 #else 983 #else
994 home_replace(NULL, buf->b_ffname, b0p->b0_fname, 994 home_replace(NULL, buf->b_ffname, b0p->b0_fname,
995 B0_FNAME_SIZE_CRYPT, TRUE); 995 B0_FNAME_SIZE_CRYPT, TRUE);
996 if (b0p->b0_fname[0] == '~') 996 if (b0p->b0_fname[0] == '~')
997 { 997 {
998 flen = STRLEN(b0p->b0_fname); 998 flen = STRLEN(b0p->b0_fname);
999 /* If there is no user name or it is too long, don't use "~/" */ 999 // If there is no user name or it is too long, don't use "~/"
1000 if (get_user_name(uname, B0_UNAME_SIZE) == FAIL 1000 if (get_user_name(uname, B0_UNAME_SIZE) == FAIL
1001 || (ulen = STRLEN(uname)) + flen > B0_FNAME_SIZE_CRYPT - 1) 1001 || (ulen = STRLEN(uname)) + flen > B0_FNAME_SIZE_CRYPT - 1)
1002 vim_strncpy(b0p->b0_fname, buf->b_ffname, 1002 vim_strncpy(b0p->b0_fname, buf->b_ffname,
1003 B0_FNAME_SIZE_CRYPT - 1); 1003 B0_FNAME_SIZE_CRYPT - 1);
1004 else 1004 else
1028 buf->b_orig_size = 0; 1028 buf->b_orig_size = 0;
1029 buf->b_orig_mode = 0; 1029 buf->b_orig_mode = 0;
1030 } 1030 }
1031 } 1031 }
1032 1032
1033 /* Also add the 'fileencoding' if there is room. */ 1033 // Also add the 'fileencoding' if there is room.
1034 add_b0_fenc(b0p, curbuf); 1034 add_b0_fenc(b0p, curbuf);
1035 } 1035 }
1036 1036
1037 /* 1037 /*
1038 * Update the B0_SAME_DIR flag of the swap file. It's set if the file and the 1038 * Update the B0_SAME_DIR flag of the swap file. It's set if the file and the
1059 { 1059 {
1060 int n; 1060 int n;
1061 int size = B0_FNAME_SIZE_NOCRYPT; 1061 int size = B0_FNAME_SIZE_NOCRYPT;
1062 1062
1063 #ifdef FEAT_CRYPT 1063 #ifdef FEAT_CRYPT
1064 /* Without encryption use the same offset as in Vim 7.2 to be compatible. 1064 // Without encryption use the same offset as in Vim 7.2 to be compatible.
1065 * With encryption it's OK to move elsewhere, the swap file is not 1065 // With encryption it's OK to move elsewhere, the swap file is not
1066 * compatible anyway. */ 1066 // compatible anyway.
1067 if (*buf->b_p_key != NUL) 1067 if (*buf->b_p_key != NUL)
1068 size = B0_FNAME_SIZE_CRYPT; 1068 size = B0_FNAME_SIZE_CRYPT;
1069 #endif 1069 #endif
1070 1070
1071 n = (int)STRLEN(buf->b_p_fenc); 1071 n = (int)STRLEN(buf->b_p_fenc);
1132 /* 1132 /*
1133 * If the file name ends in ".s[a-w][a-z]" we assume this is the swap file. 1133 * If the file name ends in ".s[a-w][a-z]" we assume this is the swap file.
1134 * Otherwise a search is done to find the swap file(s). 1134 * Otherwise a search is done to find the swap file(s).
1135 */ 1135 */
1136 fname = curbuf->b_fname; 1136 fname = curbuf->b_fname;
1137 if (fname == NULL) /* When there is no file name */ 1137 if (fname == NULL) // When there is no file name
1138 fname = (char_u *)""; 1138 fname = (char_u *)"";
1139 len = (int)STRLEN(fname); 1139 len = (int)STRLEN(fname);
1140 if (checkext && len >= 4 && 1140 if (checkext && len >= 4 &&
1141 #if defined(VMS) 1141 #if defined(VMS)
1142 STRNICMP(fname + len - 4, "_s", 2) 1142 STRNICMP(fname + len - 4, "_s", 2)
1147 && vim_strchr((char_u *)"abcdefghijklmnopqrstuvw", 1147 && vim_strchr((char_u *)"abcdefghijklmnopqrstuvw",
1148 TOLOWER_ASC(fname[len - 2])) != NULL 1148 TOLOWER_ASC(fname[len - 2])) != NULL
1149 && ASCII_ISALPHA(fname[len - 1])) 1149 && ASCII_ISALPHA(fname[len - 1]))
1150 { 1150 {
1151 directly = TRUE; 1151 directly = TRUE;
1152 fname_used = vim_strsave(fname); /* make a copy for mf_open() */ 1152 fname_used = vim_strsave(fname); // make a copy for mf_open()
1153 } 1153 }
1154 else 1154 else
1155 { 1155 {
1156 directly = FALSE; 1156 directly = FALSE;
1157 1157
1158 /* count the number of matching swap files */ 1158 // count the number of matching swap files
1159 len = recover_names(fname, FALSE, 0, NULL); 1159 len = recover_names(fname, FALSE, 0, NULL);
1160 if (len == 0) /* no swap files found */ 1160 if (len == 0) // no swap files found
1161 { 1161 {
1162 semsg(_("E305: No swap file found for %s"), fname); 1162 semsg(_("E305: No swap file found for %s"), fname);
1163 goto theend; 1163 goto theend;
1164 } 1164 }
1165 if (len == 1) /* one swap file found, use it */ 1165 if (len == 1) // one swap file found, use it
1166 i = 1; 1166 i = 1;
1167 else /* several swap files found, choose */ 1167 else // several swap files found, choose
1168 { 1168 {
1169 /* list the names of the swap files */ 1169 // list the names of the swap files
1170 (void)recover_names(fname, TRUE, 0, NULL); 1170 (void)recover_names(fname, TRUE, 0, NULL);
1171 msg_putchar('\n'); 1171 msg_putchar('\n');
1172 msg_puts(_("Enter number of swap file to use (0 to quit): ")); 1172 msg_puts(_("Enter number of swap file to use (0 to quit): "));
1173 i = get_number(FALSE, NULL); 1173 i = get_number(FALSE, NULL);
1174 if (i < 1 || i > len) 1174 if (i < 1 || i > len)
1175 goto theend; 1175 goto theend;
1176 } 1176 }
1177 /* get the swap file name that will be used */ 1177 // get the swap file name that will be used
1178 (void)recover_names(fname, FALSE, i, &fname_used); 1178 (void)recover_names(fname, FALSE, i, &fname_used);
1179 } 1179 }
1180 if (fname_used == NULL) 1180 if (fname_used == NULL)
1181 goto theend; /* out of memory */ 1181 goto theend; // out of memory
1182 1182
1183 /* When called from main() still need to initialize storage structure */ 1183 // When called from main() still need to initialize storage structure
1184 if (called_from_main && ml_open(curbuf) == FAIL) 1184 if (called_from_main && ml_open(curbuf) == FAIL)
1185 getout(1); 1185 getout(1);
1186 1186
1187 /* 1187 /*
1188 * Allocate a buffer structure for the swap file that is used for recovery. 1188 * Allocate a buffer structure for the swap file that is used for recovery.
1193 goto theend; 1193 goto theend;
1194 1194
1195 /* 1195 /*
1196 * init fields in memline struct 1196 * init fields in memline struct
1197 */ 1197 */
1198 buf->b_ml.ml_stack_size = 0; /* no stack yet */ 1198 buf->b_ml.ml_stack_size = 0; // no stack yet
1199 buf->b_ml.ml_stack = NULL; /* no stack yet */ 1199 buf->b_ml.ml_stack = NULL; // no stack yet
1200 buf->b_ml.ml_stack_top = 0; /* nothing in the stack */ 1200 buf->b_ml.ml_stack_top = 0; // nothing in the stack
1201 buf->b_ml.ml_line_lnum = 0; /* no cached line */ 1201 buf->b_ml.ml_line_lnum = 0; // no cached line
1202 buf->b_ml.ml_locked = NULL; /* no locked block */ 1202 buf->b_ml.ml_locked = NULL; // no locked block
1203 buf->b_ml.ml_flags = 0; 1203 buf->b_ml.ml_flags = 0;
1204 #ifdef FEAT_CRYPT 1204 #ifdef FEAT_CRYPT
1205 buf->b_p_key = empty_option; 1205 buf->b_p_key = empty_option;
1206 buf->b_p_cm = empty_option; 1206 buf->b_p_cm = empty_option;
1207 #endif 1207 #endif
1208 1208
1209 /* 1209 /*
1210 * open the memfile from the old swap file 1210 * open the memfile from the old swap file
1211 */ 1211 */
1212 p = vim_strsave(fname_used); /* save "fname_used" for the message: 1212 p = vim_strsave(fname_used); // save "fname_used" for the message:
1213 mf_open() will consume "fname_used"! */ 1213 // mf_open() will consume "fname_used"!
1214 mfp = mf_open(fname_used, O_RDONLY); 1214 mfp = mf_open(fname_used, O_RDONLY);
1215 fname_used = p; 1215 fname_used = p;
1216 if (mfp == NULL || mfp->mf_fd < 0) 1216 if (mfp == NULL || mfp->mf_fd < 0)
1217 { 1217 {
1218 if (fname_used != NULL) 1218 if (fname_used != NULL)
1272 else 1272 else
1273 #endif 1273 #endif
1274 msg_puts_attr(_(" cannot be used on this computer.\n"), 1274 msg_puts_attr(_(" cannot be used on this computer.\n"),
1275 attr | MSG_HIST); 1275 attr | MSG_HIST);
1276 msg_puts_attr(_("The file was created on "), attr | MSG_HIST); 1276 msg_puts_attr(_("The file was created on "), attr | MSG_HIST);
1277 /* avoid going past the end of a corrupted hostname */ 1277 // avoid going past the end of a corrupted hostname
1278 b0p->b0_fname[0] = NUL; 1278 b0p->b0_fname[0] = NUL;
1279 msg_puts_attr((char *)b0p->b0_hname, attr | MSG_HIST); 1279 msg_puts_attr((char *)b0p->b0_hname, attr | MSG_HIST);
1280 msg_puts_attr(_(",\nor the file has been damaged."), attr | MSG_HIST); 1280 msg_puts_attr(_(",\nor the file has been damaged."), attr | MSG_HIST);
1281 msg_end(); 1281 msg_end();
1282 goto theend; 1282 goto theend;
1314 attr | MSG_HIST); 1314 attr | MSG_HIST);
1315 msg_end(); 1315 msg_end();
1316 goto theend; 1316 goto theend;
1317 } 1317 }
1318 if ((size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0) 1318 if ((size = vim_lseek(mfp->mf_fd, (off_T)0L, SEEK_END)) <= 0)
1319 mfp->mf_blocknr_max = 0; /* no file or empty file */ 1319 mfp->mf_blocknr_max = 0; // no file or empty file
1320 else 1320 else
1321 mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size); 1321 mfp->mf_blocknr_max = (blocknr_T)(size / mfp->mf_page_size);
1322 mfp->mf_infile_count = mfp->mf_blocknr_max; 1322 mfp->mf_infile_count = mfp->mf_blocknr_max;
1323 1323
1324 /* need to reallocate the memory used to store the data */ 1324 // need to reallocate the memory used to store the data
1325 p = alloc(mfp->mf_page_size); 1325 p = alloc(mfp->mf_page_size);
1326 if (p == NULL) 1326 if (p == NULL)
1327 goto theend; 1327 goto theend;
1328 mch_memmove(p, hp->bh_data, previous_page_size); 1328 mch_memmove(p, hp->bh_data, previous_page_size);
1329 vim_free(hp->bh_data); 1329 vim_free(hp->bh_data);
1361 && org_stat.st_mtime > swp_stat.st_mtime) 1361 && org_stat.st_mtime > swp_stat.st_mtime)
1362 || org_stat.st_mtime != mtime)) 1362 || org_stat.st_mtime != mtime))
1363 emsg(_("E308: Warning: Original file may have been changed")); 1363 emsg(_("E308: Warning: Original file may have been changed"));
1364 out_flush(); 1364 out_flush();
1365 1365
1366 /* Get the 'fileformat' and 'fileencoding' from block zero. */ 1366 // Get the 'fileformat' and 'fileencoding' from block zero.
1367 b0_ff = (b0p->b0_flags & B0_FF_MASK); 1367 b0_ff = (b0p->b0_flags & B0_FF_MASK);
1368 if (b0p->b0_flags & B0_HAS_FENC) 1368 if (b0p->b0_flags & B0_HAS_FENC)
1369 { 1369 {
1370 int fnsize = B0_FNAME_SIZE_NOCRYPT; 1370 int fnsize = B0_FNAME_SIZE_NOCRYPT;
1371 1371
1372 #ifdef FEAT_CRYPT 1372 #ifdef FEAT_CRYPT
1373 /* Use the same size as in add_b0_fenc(). */ 1373 // Use the same size as in add_b0_fenc().
1374 if (b0p->b0_id[1] != BLOCK0_ID1) 1374 if (b0p->b0_id[1] != BLOCK0_ID1)
1375 fnsize = B0_FNAME_SIZE_CRYPT; 1375 fnsize = B0_FNAME_SIZE_CRYPT;
1376 #endif 1376 #endif
1377 for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; --p) 1377 for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; --p)
1378 ; 1378 ;
1379 b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p)); 1379 b0_fenc = vim_strnsave(p, (int)(b0p->b0_fname + fnsize - p));
1380 } 1380 }
1381 1381
1382 mf_put(mfp, hp, FALSE, FALSE); /* release block 0 */ 1382 mf_put(mfp, hp, FALSE, FALSE); // release block 0
1383 hp = NULL; 1383 hp = NULL;
1384 1384
1385 /* 1385 /*
1386 * Now that we are sure that the file is going to be recovered, clear the 1386 * Now that we are sure that the file is going to be recovered, clear the
1387 * contents of the current buffer. 1387 * contents of the current buffer.
1399 (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW); 1399 (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW);
1400 1400
1401 #ifdef FEAT_CRYPT 1401 #ifdef FEAT_CRYPT
1402 if (b0_cm >= 0) 1402 if (b0_cm >= 0)
1403 { 1403 {
1404 /* Need to ask the user for the crypt key. If this fails we continue 1404 // Need to ask the user for the crypt key. If this fails we continue
1405 * without a key, will probably get garbage text. */ 1405 // without a key, will probably get garbage text.
1406 if (*curbuf->b_p_key != NUL) 1406 if (*curbuf->b_p_key != NUL)
1407 { 1407 {
1408 smsg(_("Swap file is encrypted: \"%s\""), fname_used); 1408 smsg(_("Swap file is encrypted: \"%s\""), fname_used);
1409 msg_puts(_("\nIf you entered a new crypt key but did not write the text file,")); 1409 msg_puts(_("\nIf you entered a new crypt key but did not write the text file,"));
1410 msg_puts(_("\nenter the new crypt key.")); 1410 msg_puts(_("\nenter the new crypt key."));
1424 if (buf->b_p_key == NULL) 1424 if (buf->b_p_key == NULL)
1425 buf->b_p_key = empty_option; 1425 buf->b_p_key = empty_option;
1426 } 1426 }
1427 #endif 1427 #endif
1428 1428
1429 /* Use the 'fileformat' and 'fileencoding' as stored in the swap file. */ 1429 // Use the 'fileformat' and 'fileencoding' as stored in the swap file.
1430 if (b0_ff != 0) 1430 if (b0_ff != 0)
1431 set_fileformat(b0_ff - 1, OPT_LOCAL); 1431 set_fileformat(b0_ff - 1, OPT_LOCAL);
1432 if (b0_fenc != NULL) 1432 if (b0_fenc != NULL)
1433 { 1433 {
1434 set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); 1434 set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL);
1435 vim_free(b0_fenc); 1435 vim_free(b0_fenc);
1436 } 1436 }
1437 unchanged(curbuf, TRUE, TRUE); 1437 unchanged(curbuf, TRUE, TRUE);
1438 1438
1439 bnum = 1; /* start with block 1 */ 1439 bnum = 1; // start with block 1
1440 page_count = 1; /* which is 1 page */ 1440 page_count = 1; // which is 1 page
1441 lnum = 0; /* append after line 0 in curbuf */ 1441 lnum = 0; // append after line 0 in curbuf
1442 line_count = 0; 1442 line_count = 0;
1443 idx = 0; /* start with first index in block 1 */ 1443 idx = 0; // start with first index in block 1
1444 error = 0; 1444 error = 0;
1445 buf->b_ml.ml_stack_top = 0; 1445 buf->b_ml.ml_stack_top = 0;
1446 buf->b_ml.ml_stack = NULL; 1446 buf->b_ml.ml_stack = NULL;
1447 buf->b_ml.ml_stack_size = 0; /* no stack yet */ 1447 buf->b_ml.ml_stack_size = 0; // no stack yet
1448 1448
1449 if (curbuf->b_ffname == NULL) 1449 if (curbuf->b_ffname == NULL)
1450 cannot_open = TRUE; 1450 cannot_open = TRUE;
1451 else 1451 else
1452 cannot_open = FALSE; 1452 cannot_open = FALSE;
1453 1453
1454 serious_error = FALSE; 1454 serious_error = FALSE;
1455 for ( ; !got_int; line_breakcheck()) 1455 for ( ; !got_int; line_breakcheck())
1456 { 1456 {
1457 if (hp != NULL) 1457 if (hp != NULL)
1458 mf_put(mfp, hp, FALSE, FALSE); /* release previous block */ 1458 mf_put(mfp, hp, FALSE, FALSE); // release previous block
1459 1459
1460 /* 1460 /*
1461 * get block 1461 * get block
1462 */ 1462 */
1463 if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL) 1463 if ((hp = mf_get(mfp, (blocknr_T)bnum, page_count)) == NULL)
1469 } 1469 }
1470 ++error; 1470 ++error;
1471 ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"), 1471 ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"),
1472 (colnr_T)0, TRUE); 1472 (colnr_T)0, TRUE);
1473 } 1473 }
1474 else /* there is a block */ 1474 else // there is a block
1475 { 1475 {
1476 pp = (PTR_BL *)(hp->bh_data); 1476 pp = (PTR_BL *)(hp->bh_data);
1477 if (pp->pb_id == PTR_ID) /* it is a pointer block */ 1477 if (pp->pb_id == PTR_ID) // it is a pointer block
1478 { 1478 {
1479 /* check line count when using pointer block first time */ 1479 // check line count when using pointer block first time
1480 if (idx == 0 && line_count != 0) 1480 if (idx == 0 && line_count != 0)
1481 { 1481 {
1482 for (i = 0; i < (int)pp->pb_count; ++i) 1482 for (i = 0; i < (int)pp->pb_count; ++i)
1483 line_count -= pp->pb_pointer[i].pe_line_count; 1483 line_count -= pp->pb_pointer[i].pe_line_count;
1484 if (line_count != 0) 1484 if (line_count != 0)
1493 { 1493 {
1494 ml_append(lnum++, (char_u *)_("???EMPTY BLOCK"), 1494 ml_append(lnum++, (char_u *)_("???EMPTY BLOCK"),
1495 (colnr_T)0, TRUE); 1495 (colnr_T)0, TRUE);
1496 ++error; 1496 ++error;
1497 } 1497 }
1498 else if (idx < (int)pp->pb_count) /* go a block deeper */ 1498 else if (idx < (int)pp->pb_count) // go a block deeper
1499 { 1499 {
1500 if (pp->pb_pointer[idx].pe_bnum < 0) 1500 if (pp->pb_pointer[idx].pe_bnum < 0)
1501 { 1501 {
1502 /* 1502 /*
1503 * Data block with negative block number. 1503 * Data block with negative block number.
1518 { 1518 {
1519 ++error; 1519 ++error;
1520 ml_append(lnum++, (char_u *)_("???LINES MISSING"), 1520 ml_append(lnum++, (char_u *)_("???LINES MISSING"),
1521 (colnr_T)0, TRUE); 1521 (colnr_T)0, TRUE);
1522 } 1522 }
1523 ++idx; /* get same block again for next index */ 1523 ++idx; // get same block again for next index
1524 continue; 1524 continue;
1525 } 1525 }
1526 1526
1527 /* 1527 /*
1528 * going one block deeper in the tree 1528 * going one block deeper in the tree
1529 */ 1529 */
1530 if ((top = ml_add_stack(buf)) < 0) /* new entry in stack */ 1530 if ((top = ml_add_stack(buf)) < 0) // new entry in stack
1531 { 1531 {
1532 ++error; 1532 ++error;
1533 break; /* out of memory */ 1533 break; // out of memory
1534 } 1534 }
1535 ip = &(buf->b_ml.ml_stack[top]); 1535 ip = &(buf->b_ml.ml_stack[top]);
1536 ip->ip_bnum = bnum; 1536 ip->ip_bnum = bnum;
1537 ip->ip_index = idx; 1537 ip->ip_index = idx;
1538 1538
1541 page_count = pp->pb_pointer[idx].pe_page_count; 1541 page_count = pp->pb_pointer[idx].pe_page_count;
1542 idx = 0; 1542 idx = 0;
1543 continue; 1543 continue;
1544 } 1544 }
1545 } 1545 }
1546 else /* not a pointer block */ 1546 else // not a pointer block
1547 { 1547 {
1548 dp = (DATA_BL *)(hp->bh_data); 1548 dp = (DATA_BL *)(hp->bh_data);
1549 if (dp->db_id != DATA_ID) /* block id wrong */ 1549 if (dp->db_id != DATA_ID) // block id wrong
1550 { 1550 {
1551 if (bnum == 1) 1551 if (bnum == 1)
1552 { 1552 {
1553 semsg(_("E310: Block 1 ID wrong (%s not a .swp file?)"), 1553 semsg(_("E310: Block 1 ID wrong (%s not a .swp file?)"),
1554 mfp->mf_fname); 1554 mfp->mf_fname);
1576 ++error; 1576 ++error;
1577 has_error = TRUE; 1577 has_error = TRUE;
1578 dp->db_txt_end = page_count * mfp->mf_page_size; 1578 dp->db_txt_end = page_count * mfp->mf_page_size;
1579 } 1579 }
1580 1580
1581 /* make sure there is a NUL at the end of the block */ 1581 // make sure there is a NUL at the end of the block
1582 *((char_u *)dp + dp->db_txt_end - 1) = NUL; 1582 *((char_u *)dp + dp->db_txt_end - 1) = NUL;
1583 1583
1584 /* 1584 /*
1585 * check number of lines in block 1585 * check number of lines in block
1586 * if wrong, use count in data block 1586 * if wrong, use count in data block
1611 (colnr_T)0, TRUE); 1611 (colnr_T)0, TRUE);
1612 } 1612 }
1613 } 1613 }
1614 } 1614 }
1615 1615
1616 if (buf->b_ml.ml_stack_top == 0) /* finished */ 1616 if (buf->b_ml.ml_stack_top == 0) // finished
1617 break; 1617 break;
1618 1618
1619 /* 1619 /*
1620 * go one block up in the tree 1620 * go one block up in the tree
1621 */ 1621 */
1622 ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]); 1622 ip = &(buf->b_ml.ml_stack[--(buf->b_ml.ml_stack_top)]);
1623 bnum = ip->ip_bnum; 1623 bnum = ip->ip_bnum;
1624 idx = ip->ip_index + 1; /* go to next index */ 1624 idx = ip->ip_index + 1; // go to next index
1625 page_count = 1; 1625 page_count = 1;
1626 } 1626 }
1627 1627
1628 /* 1628 /*
1629 * Compare the buffer contents with the original file. When they differ 1629 * Compare the buffer contents with the original file. When they differ
1632 * Lines lnum + 1 to ml_line_count are the original contents. 1632 * Lines lnum + 1 to ml_line_count are the original contents.
1633 * Line ml_line_count + 1 in the dummy empty line. 1633 * Line ml_line_count + 1 in the dummy empty line.
1634 */ 1634 */
1635 if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1) 1635 if (orig_file_status != OK || curbuf->b_ml.ml_line_count != lnum * 2 + 1)
1636 { 1636 {
1637 /* Recovering an empty file results in two lines and the first line is 1637 // Recovering an empty file results in two lines and the first line is
1638 * empty. Don't set the modified flag then. */ 1638 // empty. Don't set the modified flag then.
1639 if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL)) 1639 if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL))
1640 { 1640 {
1641 changed_internal(); 1641 changed_internal();
1642 ++CHANGEDTICK(curbuf); 1642 ++CHANGEDTICK(curbuf);
1643 } 1643 }
1644 } 1644 }
1645 else 1645 else
1646 { 1646 {
1647 for (idx = 1; idx <= lnum; ++idx) 1647 for (idx = 1; idx <= lnum; ++idx)
1648 { 1648 {
1649 /* Need to copy one line, fetching the other one may flush it. */ 1649 // Need to copy one line, fetching the other one may flush it.
1650 p = vim_strsave(ml_get(idx)); 1650 p = vim_strsave(ml_get(idx));
1651 i = STRCMP(p, ml_get(idx + lnum)); 1651 i = STRCMP(p, ml_get(idx + lnum));
1652 vim_free(p); 1652 vim_free(p);
1653 if (i != 0) 1653 if (i != 0)
1654 { 1654 {
1707 recoverymode = FALSE; 1707 recoverymode = FALSE;
1708 if (mfp != NULL) 1708 if (mfp != NULL)
1709 { 1709 {
1710 if (hp != NULL) 1710 if (hp != NULL)
1711 mf_put(mfp, hp, FALSE, FALSE); 1711 mf_put(mfp, hp, FALSE, FALSE);
1712 mf_close(mfp, FALSE); /* will also vim_free(mfp->mf_fname) */ 1712 mf_close(mfp, FALSE); // will also vim_free(mfp->mf_fname)
1713 } 1713 }
1714 if (buf != NULL) 1714 if (buf != NULL)
1715 { 1715 {
1716 #ifdef FEAT_CRYPT 1716 #ifdef FEAT_CRYPT
1717 if (buf->b_p_key != curbuf->b_p_key) 1717 if (buf->b_p_key != curbuf->b_p_key)
1741 * - list the swap files when recovering 1741 * - list the swap files when recovering
1742 * - find the name of the n'th swap file when recovering 1742 * - find the name of the n'th swap file when recovering
1743 */ 1743 */
1744 int 1744 int
1745 recover_names( 1745 recover_names(
1746 char_u *fname, /* base for swap file name */ 1746 char_u *fname, // base for swap file name
1747 int list, /* when TRUE, list the swap file names */ 1747 int list, // when TRUE, list the swap file names
1748 int nr, /* when non-zero, return nr'th swap file name */ 1748 int nr, // when non-zero, return nr'th swap file name
1749 char_u **fname_out) /* result when "nr" > 0 */ 1749 char_u **fname_out) // result when "nr" > 0
1750 { 1750 {
1751 int num_names; 1751 int num_names;
1752 char_u *(names[6]); 1752 char_u *(names[6]);
1753 char_u *tail; 1753 char_u *tail;
1754 char_u *p; 1754 char_u *p;
1764 #endif 1764 #endif
1765 1765
1766 if (fname != NULL) 1766 if (fname != NULL)
1767 { 1767 {
1768 #ifdef HAVE_READLINK 1768 #ifdef HAVE_READLINK
1769 /* Expand symlink in the file name, because the swap file is created 1769 // Expand symlink in the file name, because the swap file is created
1770 * with the actual file instead of with the symlink. */ 1770 // with the actual file instead of with the symlink.
1771 if (resolve_symlink(fname, fname_buf) == OK) 1771 if (resolve_symlink(fname, fname_buf) == OK)
1772 fname_res = fname_buf; 1772 fname_res = fname_buf;
1773 else 1773 else
1774 #endif 1774 #endif
1775 fname_res = fname; 1775 fname_res = fname;
1776 } 1776 }
1777 1777
1778 if (list) 1778 if (list)
1779 { 1779 {
1780 /* use msg() to start the scrolling properly */ 1780 // use msg() to start the scrolling properly
1781 msg(_("Swap files found:")); 1781 msg(_("Swap files found:"));
1782 msg_putchar('\n'); 1782 msg_putchar('\n');
1783 } 1783 }
1784 1784
1785 /* 1785 /*
1795 * it is large enough, so use 31000 for length). 1795 * it is large enough, so use 31000 for length).
1796 * Advance dirp to next directory name. 1796 * Advance dirp to next directory name.
1797 */ 1797 */
1798 (void)copy_option_part(&dirp, dir_name, 31000, ","); 1798 (void)copy_option_part(&dirp, dir_name, 31000, ",");
1799 1799
1800 if (dir_name[0] == '.' && dir_name[1] == NUL) /* check current dir */ 1800 if (dir_name[0] == '.' && dir_name[1] == NUL) // check current dir
1801 { 1801 {
1802 if (fname == NULL) 1802 if (fname == NULL)
1803 { 1803 {
1804 #ifdef VMS 1804 #ifdef VMS
1805 names[0] = vim_strsave((char_u *)"*_sw%"); 1805 names[0] = vim_strsave((char_u *)"*_sw%");
1806 #else 1806 #else
1807 names[0] = vim_strsave((char_u *)"*.sw?"); 1807 names[0] = vim_strsave((char_u *)"*.sw?");
1808 #endif 1808 #endif
1809 #if defined(UNIX) || defined(MSWIN) 1809 #if defined(UNIX) || defined(MSWIN)
1810 /* For Unix names starting with a dot are special. MS-Windows 1810 // For Unix names starting with a dot are special. MS-Windows
1811 * supports this too, on some file systems. */ 1811 // supports this too, on some file systems.
1812 names[1] = vim_strsave((char_u *)".*.sw?"); 1812 names[1] = vim_strsave((char_u *)".*.sw?");
1813 names[2] = vim_strsave((char_u *)".sw?"); 1813 names[2] = vim_strsave((char_u *)".sw?");
1814 num_names = 3; 1814 num_names = 3;
1815 #else 1815 #else
1816 # ifdef VMS 1816 # ifdef VMS
1822 #endif 1822 #endif
1823 } 1823 }
1824 else 1824 else
1825 num_names = recov_file_names(names, fname_res, TRUE); 1825 num_names = recov_file_names(names, fname_res, TRUE);
1826 } 1826 }
1827 else /* check directory dir_name */ 1827 else // check directory dir_name
1828 { 1828 {
1829 if (fname == NULL) 1829 if (fname == NULL)
1830 { 1830 {
1831 #ifdef VMS 1831 #ifdef VMS
1832 names[0] = concat_fnames(dir_name, (char_u *)"*_sw%", TRUE); 1832 names[0] = concat_fnames(dir_name, (char_u *)"*_sw%", TRUE);
1833 #else 1833 #else
1834 names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); 1834 names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE);
1835 #endif 1835 #endif
1836 #if defined(UNIX) || defined(MSWIN) 1836 #if defined(UNIX) || defined(MSWIN)
1837 /* For Unix names starting with a dot are special. MS-Windows 1837 // For Unix names starting with a dot are special. MS-Windows
1838 * supports this too, on some file systems. */ 1838 // supports this too, on some file systems.
1839 names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); 1839 names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE);
1840 names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); 1840 names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE);
1841 num_names = 3; 1841 num_names = 3;
1842 #else 1842 #else
1843 # ifdef VMS 1843 # ifdef VMS
1854 int len = (int)STRLEN(dir_name); 1854 int len = (int)STRLEN(dir_name);
1855 1855
1856 p = dir_name + len; 1856 p = dir_name + len;
1857 if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2]) 1857 if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2])
1858 { 1858 {
1859 /* Ends with '//', Use Full path for swap name */ 1859 // Ends with '//', Use Full path for swap name
1860 tail = make_percent_swname(dir_name, fname_res); 1860 tail = make_percent_swname(dir_name, fname_res);
1861 } 1861 }
1862 else 1862 else
1863 #endif 1863 #endif
1864 { 1864 {
1951 file_count += num_files; 1951 file_count += num_files;
1952 if (nr <= file_count) 1952 if (nr <= file_count)
1953 { 1953 {
1954 *fname_out = vim_strsave( 1954 *fname_out = vim_strsave(
1955 files[nr - 1 + num_files - file_count]); 1955 files[nr - 1 + num_files - file_count]);
1956 dirp = (char_u *)""; /* stop searching */ 1956 dirp = (char_u *)""; // stop searching
1957 } 1957 }
1958 } 1958 }
1959 else if (list) 1959 else if (list)
1960 { 1960 {
1961 if (dir_name[0] == '.' && dir_name[1] == NUL) 1961 if (dir_name[0] == '.' && dir_name[1] == NUL)
1974 1974
1975 if (num_files) 1975 if (num_files)
1976 { 1976 {
1977 for (i = 0; i < num_files; ++i) 1977 for (i = 0; i < num_files; ++i)
1978 { 1978 {
1979 /* print the swap file name */ 1979 // print the swap file name
1980 msg_outnum((long)++file_count); 1980 msg_outnum((long)++file_count);
1981 msg_puts(". "); 1981 msg_puts(". ");
1982 msg_puts((char *)gettail(files[i])); 1982 msg_puts((char *)gettail(files[i]));
1983 msg_putchar('\n'); 1983 msg_putchar('\n');
1984 (void)swapfile_info(files[i]); 1984 (void)swapfile_info(files[i]);
2055 dict_add_string(d, "error", (char_u *)"Not a swap file"); 2055 dict_add_string(d, "error", (char_u *)"Not a swap file");
2056 else if (b0_magic_wrong(&b0)) 2056 else if (b0_magic_wrong(&b0))
2057 dict_add_string(d, "error", (char_u *)"Magic number mismatch"); 2057 dict_add_string(d, "error", (char_u *)"Magic number mismatch");
2058 else 2058 else
2059 { 2059 {
2060 /* we have swap information */ 2060 // we have swap information
2061 dict_add_string_len(d, "version", b0.b0_version, 10); 2061 dict_add_string_len(d, "version", b0.b0_version, 10);
2062 dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE); 2062 dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE);
2063 dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE); 2063 dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE);
2064 dict_add_string_len(d, "fname", b0.b0_fname, B0_FNAME_SIZE_ORG); 2064 dict_add_string_len(d, "fname", b0.b0_fname, B0_FNAME_SIZE_ORG);
2065 2065
2136 #ifdef HAVE_STRFTIME 2136 #ifdef HAVE_STRFTIME
2137 struct tm tmval; 2137 struct tm tmval;
2138 struct tm *curtime; 2138 struct tm *curtime;
2139 2139
2140 curtime = vim_localtime(&thetime, &tmval); 2140 curtime = vim_localtime(&thetime, &tmval);
2141 /* MSVC returns NULL for an invalid value of seconds. */ 2141 // MSVC returns NULL for an invalid value of seconds.
2142 if (curtime == NULL) 2142 if (curtime == NULL)
2143 vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1); 2143 vim_strncpy((char_u *)buf, (char_u *)_("(Invalid)"), sizeof(buf) - 1);
2144 else 2144 else
2145 { 2145 {
2146 (void)strftime(buf, sizeof(buf) - 1, _("%a %b %d %H:%M:%S %Y"), 2146 (void)strftime(buf, sizeof(buf) - 1, _("%a %b %d %H:%M:%S %Y"),
2371 #else 2371 #else
2372 names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE); 2372 names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE);
2373 #endif 2373 #endif
2374 if (names[num_names] == NULL) 2374 if (names[num_names] == NULL)
2375 goto end; 2375 goto end;
2376 if (num_names >= 1) /* check if we have the same name twice */ 2376 if (num_names >= 1) // check if we have the same name twice
2377 { 2377 {
2378 p = names[num_names - 1]; 2378 p = names[num_names - 1];
2379 i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); 2379 i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]);
2380 if (i > 0) 2380 if (i > 0)
2381 p += i; /* file name has been expanded to full path */ 2381 p += i; // file name has been expanded to full path
2382 2382
2383 if (STRCMP(p, names[num_names]) != 0) 2383 if (STRCMP(p, names[num_names]) != 0)
2384 ++num_names; 2384 ++num_names;
2385 else 2385 else
2386 vim_free(names[num_names]); 2386 vim_free(names[num_names]);
2405 * Remove the one from 'shortname', if it's the same as with 'noshortname'. 2405 * Remove the one from 'shortname', if it's the same as with 'noshortname'.
2406 */ 2406 */
2407 p = names[num_names]; 2407 p = names[num_names];
2408 i = STRLEN(names[num_names]) - STRLEN(names[num_names - 1]); 2408 i = STRLEN(names[num_names]) - STRLEN(names[num_names - 1]);
2409 if (i > 0) 2409 if (i > 0)
2410 p += i; /* file name has been expanded to full path */ 2410 p += i; // file name has been expanded to full path
2411 if (STRCMP(names[num_names - 1], p) == 0) 2411 if (STRCMP(names[num_names - 1], p) == 0)
2412 vim_free(names[num_names]); 2412 vim_free(names[num_names]);
2413 else 2413 else
2414 ++num_names; 2414 ++num_names;
2415 # endif 2415 # endif
2436 stat_T st; 2436 stat_T st;
2437 2437
2438 FOR_ALL_BUFFERS(buf) 2438 FOR_ALL_BUFFERS(buf)
2439 { 2439 {
2440 if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL) 2440 if (buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp->mf_fname == NULL)
2441 continue; /* no file */ 2441 continue; // no file
2442 2442
2443 ml_flush_line(buf); /* flush buffered line */ 2443 ml_flush_line(buf); // flush buffered line
2444 /* flush locked block */ 2444 // flush locked block
2445 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); 2445 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH);
2446 if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp) 2446 if (bufIsChanged(buf) && check_file && mf_need_trans(buf->b_ml.ml_mfp)
2447 && buf->b_ffname != NULL) 2447 && buf->b_ffname != NULL)
2448 { 2448 {
2449 /* 2449 /*
2454 || st.st_mtime != buf->b_mtime_read 2454 || st.st_mtime != buf->b_mtime_read
2455 || st.st_size != buf->b_orig_size) 2455 || st.st_size != buf->b_orig_size)
2456 { 2456 {
2457 ml_preserve(buf, FALSE); 2457 ml_preserve(buf, FALSE);
2458 did_check_timestamps = FALSE; 2458 did_check_timestamps = FALSE;
2459 need_check_timestamps = TRUE; /* give message later */ 2459 need_check_timestamps = TRUE; // give message later
2460 } 2460 }
2461 } 2461 }
2462 if (buf->b_ml.ml_mfp->mf_dirty) 2462 if (buf->b_ml.ml_mfp->mf_dirty)
2463 { 2463 {
2464 (void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0) 2464 (void)mf_sync(buf->b_ml.ml_mfp, (check_char ? MFS_STOP : 0)
2465 | (bufIsChanged(buf) ? MFS_FLUSH : 0)); 2465 | (bufIsChanged(buf) ? MFS_FLUSH : 0));
2466 if (check_char && ui_char_avail()) /* character available now */ 2466 if (check_char && ui_char_avail()) // character available now
2467 break; 2467 break;
2468 } 2468 }
2469 } 2469 }
2470 } 2470 }
2471 2471
2493 if (message) 2493 if (message)
2494 emsg(_("E313: Cannot preserve, there is no swap file")); 2494 emsg(_("E313: Cannot preserve, there is no swap file"));
2495 return; 2495 return;
2496 } 2496 }
2497 2497
2498 /* We only want to stop when interrupted here, not when interrupted 2498 // We only want to stop when interrupted here, not when interrupted
2499 * before. */ 2499 // before.
2500 got_int = FALSE; 2500 got_int = FALSE;
2501 2501
2502 ml_flush_line(buf); /* flush buffered line */ 2502 ml_flush_line(buf); // flush buffered line
2503 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ 2503 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block
2504 status = mf_sync(mfp, MFS_ALL | MFS_FLUSH); 2504 status = mf_sync(mfp, MFS_ALL | MFS_FLUSH);
2505 2505
2506 /* stack is invalid after mf_sync(.., MFS_ALL) */ 2506 // stack is invalid after mf_sync(.., MFS_ALL)
2507 buf->b_ml.ml_stack_top = 0; 2507 buf->b_ml.ml_stack_top = 0;
2508 2508
2509 /* 2509 /*
2510 * Some of the data blocks may have been changed from negative to 2510 * Some of the data blocks may have been changed from negative to
2511 * positive block number. In that case the pointer blocks need to be 2511 * positive block number. In that case the pointer blocks need to be
2530 goto theend; 2530 goto theend;
2531 } 2531 }
2532 CHECK(buf->b_ml.ml_locked_low != lnum, "low != lnum"); 2532 CHECK(buf->b_ml.ml_locked_low != lnum, "low != lnum");
2533 lnum = buf->b_ml.ml_locked_high + 1; 2533 lnum = buf->b_ml.ml_locked_high + 1;
2534 } 2534 }
2535 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush locked block */ 2535 (void)ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush locked block
2536 /* sync the updated pointer blocks */ 2536 // sync the updated pointer blocks
2537 if (mf_sync(mfp, MFS_ALL | MFS_FLUSH) == FAIL) 2537 if (mf_sync(mfp, MFS_ALL | MFS_FLUSH) == FAIL)
2538 status = FAIL; 2538 status = FAIL;
2539 buf->b_ml.ml_stack_top = 0; /* stack is invalid now */ 2539 buf->b_ml.ml_stack_top = 0; // stack is invalid now
2540 } 2540 }
2541 theend: 2541 theend:
2542 got_int |= got_int_save; 2542 got_int |= got_int_save;
2543 2543
2544 if (message) 2544 if (message)
2605 */ 2605 */
2606 char_u * 2606 char_u *
2607 ml_get_buf( 2607 ml_get_buf(
2608 buf_T *buf, 2608 buf_T *buf,
2609 linenr_T lnum, 2609 linenr_T lnum,
2610 int will_change) /* line will be changed */ 2610 int will_change) // line will be changed
2611 { 2611 {
2612 bhdr_T *hp; 2612 bhdr_T *hp;
2613 DATA_BL *dp; 2613 DATA_BL *dp;
2614 static int recursive = 0; 2614 static int recursive = 0;
2615 2615
2616 if (lnum > buf->b_ml.ml_line_count) /* invalid line number */ 2616 if (lnum > buf->b_ml.ml_line_count) // invalid line number
2617 { 2617 {
2618 if (recursive == 0) 2618 if (recursive == 0)
2619 { 2619 {
2620 /* Avoid giving this message for a recursive call, may happen when 2620 // Avoid giving this message for a recursive call, may happen when
2621 * the GUI redraws part of the text. */ 2621 // the GUI redraws part of the text.
2622 ++recursive; 2622 ++recursive;
2623 siemsg(_("E315: ml_get: invalid lnum: %ld"), lnum); 2623 siemsg(_("E315: ml_get: invalid lnum: %ld"), lnum);
2624 --recursive; 2624 --recursive;
2625 } 2625 }
2626 errorret: 2626 errorret:
2658 */ 2658 */
2659 if ((hp = ml_find_line(buf, lnum, ML_FIND)) == NULL) 2659 if ((hp = ml_find_line(buf, lnum, ML_FIND)) == NULL)
2660 { 2660 {
2661 if (recursive == 0) 2661 if (recursive == 0)
2662 { 2662 {
2663 /* Avoid giving this message for a recursive call, may happen 2663 // Avoid giving this message for a recursive call, may happen
2664 * when the GUI redraws part of the text. */ 2664 // when the GUI redraws part of the text.
2665 ++recursive; 2665 ++recursive;
2666 get_trans_bufname(buf); 2666 get_trans_bufname(buf);
2667 shorten_dir(NameBuff); 2667 shorten_dir(NameBuff);
2668 siemsg(_("E316: ml_get: cannot find line %ld in buffer %d %s"), 2668 siemsg(_("E316: ml_get: cannot find line %ld in buffer %d %s"),
2669 lnum, buf->b_fnum, NameBuff); 2669 lnum, buf->b_fnum, NameBuff);
2823 ML_INSERT)) == NULL) 2823 ML_INSERT)) == NULL)
2824 goto theend; 2824 goto theend;
2825 2825
2826 buf->b_ml.ml_flags &= ~ML_EMPTY; 2826 buf->b_ml.ml_flags &= ~ML_EMPTY;
2827 2827
2828 if (lnum == 0) /* got line one instead, correct db_idx */ 2828 if (lnum == 0) // got line one instead, correct db_idx
2829 db_idx = -1; /* careful, it is negative! */ 2829 db_idx = -1; // careful, it is negative!
2830 else 2830 else
2831 db_idx = lnum - buf->b_ml.ml_locked_low; 2831 db_idx = lnum - buf->b_ml.ml_locked_low;
2832 /* get line count before the insertion */ 2832 // get line count before the insertion
2833 line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; 2833 line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
2834 2834
2835 dp = (DATA_BL *)(hp->bh_data); 2835 dp = (DATA_BL *)(hp->bh_data);
2836 2836
2837 /* 2837 /*
2852 --(buf->b_ml.ml_locked_lineadd); 2852 --(buf->b_ml.ml_locked_lineadd);
2853 --(buf->b_ml.ml_locked_high); 2853 --(buf->b_ml.ml_locked_high);
2854 if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL) 2854 if ((hp = ml_find_line(buf, lnum + 1, ML_INSERT)) == NULL)
2855 goto theend; 2855 goto theend;
2856 2856
2857 db_idx = -1; /* careful, it is negative! */ 2857 db_idx = -1; // careful, it is negative!
2858 /* get line count before the insertion */ 2858 // get line count before the insertion
2859 line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low; 2859 line_count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low;
2860 CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1"); 2860 CHECK(buf->b_ml.ml_locked_low != lnum + 1, "locked_low != lnum + 1");
2861 2861
2862 dp = (DATA_BL *)(hp->bh_data); 2862 dp = (DATA_BL *)(hp->bh_data);
2863 } 2863 }
2864 2864
2865 ++buf->b_ml.ml_line_count; 2865 ++buf->b_ml.ml_line_count;
2866 2866
2867 if ((int)dp->db_free >= space_needed) /* enough room in data block */ 2867 if ((int)dp->db_free >= space_needed) // enough room in data block
2868 { 2868 {
2869 /* 2869 /*
2870 * Insert the new line in an existing data block, or in the data block 2870 * Insert the new line in an existing data block, or in the data block
2871 * allocated above. 2871 * allocated above.
2872 */ 2872 */
2876 2876
2877 /* 2877 /*
2878 * move the text of the lines that follow to the front 2878 * move the text of the lines that follow to the front
2879 * adjust the indexes of the lines that follow 2879 * adjust the indexes of the lines that follow
2880 */ 2880 */
2881 if (line_count > db_idx + 1) /* if there are following lines */ 2881 if (line_count > db_idx + 1) // if there are following lines
2882 { 2882 {
2883 /* 2883 /*
2884 * Offset is the start of the previous line. 2884 * Offset is the start of the previous line.
2885 * This will become the character just after the new line. 2885 * This will become the character just after the new line.
2886 */ 2886 */
2911 */ 2911 */
2912 buf->b_ml.ml_flags |= ML_LOCKED_DIRTY; 2912 buf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
2913 if (!newfile) 2913 if (!newfile)
2914 buf->b_ml.ml_flags |= ML_LOCKED_POS; 2914 buf->b_ml.ml_flags |= ML_LOCKED_POS;
2915 } 2915 }
2916 else /* not enough space in data block */ 2916 else // not enough space in data block
2917 { 2917 {
2918 long line_count_left, line_count_right; 2918 long line_count_left, line_count_right;
2919 int page_count_left, page_count_right; 2919 int page_count_left, page_count_right;
2920 bhdr_T *hp_left; 2920 bhdr_T *hp_left;
2921 bhdr_T *hp_right; 2921 bhdr_T *hp_right;
2922 bhdr_T *hp_new; 2922 bhdr_T *hp_new;
2923 int lines_moved; 2923 int lines_moved;
2924 int data_moved = 0; /* init to shut up gcc */ 2924 int data_moved = 0; // init to shut up gcc
2925 int total_moved = 0; /* init to shut up gcc */ 2925 int total_moved = 0; // init to shut up gcc
2926 DATA_BL *dp_right, *dp_left; 2926 DATA_BL *dp_right, *dp_left;
2927 int stack_idx; 2927 int stack_idx;
2928 int in_left; 2928 int in_left;
2929 int lineadd; 2929 int lineadd;
2930 blocknr_T bnum_left, bnum_right; 2930 blocknr_T bnum_left, bnum_right;
2946 * block. If possible we put the new line in the left block and move 2946 * block. If possible we put the new line in the left block and move
2947 * the lines after it to the right block. Otherwise the new line is 2947 * the lines after it to the right block. Otherwise the new line is
2948 * also put in the right block. This method is more efficient when 2948 * also put in the right block. This method is more efficient when
2949 * inserting a lot of lines at one place. 2949 * inserting a lot of lines at one place.
2950 */ 2950 */
2951 if (db_idx < 0) /* left block is new, right block is existing */ 2951 if (db_idx < 0) // left block is new, right block is existing
2952 { 2952 {
2953 lines_moved = 0; 2953 lines_moved = 0;
2954 in_left = TRUE; 2954 in_left = TRUE;
2955 /* space_needed does not change */ 2955 // space_needed does not change
2956 } 2956 }
2957 else /* left block is existing, right block is new */ 2957 else // left block is existing, right block is new
2958 { 2958 {
2959 lines_moved = line_count - db_idx - 1; 2959 lines_moved = line_count - db_idx - 1;
2960 if (lines_moved == 0) 2960 if (lines_moved == 0)
2961 in_left = FALSE; /* put new line in right block */ 2961 in_left = FALSE; // put new line in right block
2962 /* space_needed does not change */ 2962 // space_needed does not change
2963 else 2963 else
2964 { 2964 {
2965 data_moved = ((dp->db_index[db_idx]) & DB_INDEX_MASK) - 2965 data_moved = ((dp->db_index[db_idx]) & DB_INDEX_MASK) -
2966 dp->db_txt_start; 2966 dp->db_txt_start;
2967 total_moved = data_moved + lines_moved * INDEX_SIZE; 2967 total_moved = data_moved + lines_moved * INDEX_SIZE;
2968 if ((int)dp->db_free + total_moved >= space_needed) 2968 if ((int)dp->db_free + total_moved >= space_needed)
2969 { 2969 {
2970 in_left = TRUE; /* put new line in left block */ 2970 in_left = TRUE; // put new line in left block
2971 space_needed = total_moved; 2971 space_needed = total_moved;
2972 } 2972 }
2973 else 2973 else
2974 { 2974 {
2975 in_left = FALSE; /* put new line in right block */ 2975 in_left = FALSE; // put new line in right block
2976 space_needed += total_moved; 2976 space_needed += total_moved;
2977 } 2977 }
2978 } 2978 }
2979 } 2979 }
2980 2980
2981 page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size; 2981 page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size;
2982 if ((hp_new = ml_new_data(mfp, newfile, page_count)) == NULL) 2982 if ((hp_new = ml_new_data(mfp, newfile, page_count)) == NULL)
2983 { 2983 {
2984 /* correct line counts in pointer blocks */ 2984 // correct line counts in pointer blocks
2985 --(buf->b_ml.ml_locked_lineadd); 2985 --(buf->b_ml.ml_locked_lineadd);
2986 --(buf->b_ml.ml_locked_high); 2986 --(buf->b_ml.ml_locked_high);
2987 goto theend; 2987 goto theend;
2988 } 2988 }
2989 if (db_idx < 0) /* left block is new */ 2989 if (db_idx < 0) // left block is new
2990 { 2990 {
2991 hp_left = hp_new; 2991 hp_left = hp_new;
2992 hp_right = hp; 2992 hp_right = hp;
2993 line_count_left = 0; 2993 line_count_left = 0;
2994 line_count_right = line_count; 2994 line_count_right = line_count;
2995 } 2995 }
2996 else /* right block is new */ 2996 else // right block is new
2997 { 2997 {
2998 hp_left = hp; 2998 hp_left = hp;
2999 hp_right = hp_new; 2999 hp_right = hp_new;
3000 line_count_left = line_count; 3000 line_count_left = line_count;
3001 line_count_right = 0; 3001 line_count_right = 0;
3061 mch_memmove((char *)dp_left + dp_left->db_txt_start, 3061 mch_memmove((char *)dp_left + dp_left->db_txt_start,
3062 line, (size_t)len); 3062 line, (size_t)len);
3063 ++line_count_left; 3063 ++line_count_left;
3064 } 3064 }
3065 3065
3066 if (db_idx < 0) /* left block is new */ 3066 if (db_idx < 0) // left block is new
3067 { 3067 {
3068 lnum_left = lnum + 1; 3068 lnum_left = lnum + 1;
3069 lnum_right = 0; 3069 lnum_right = 0;
3070 } 3070 }
3071 else /* right block is new */ 3071 else // right block is new
3072 { 3072 {
3073 lnum_left = 0; 3073 lnum_left = 0;
3074 if (in_left) 3074 if (in_left)
3075 lnum_right = lnum + 2; 3075 lnum_right = lnum + 2;
3076 else 3076 else
3096 * set ml_locked_lineadd to 0, because the updating of the 3096 * set ml_locked_lineadd to 0, because the updating of the
3097 * pointer blocks is done below 3097 * pointer blocks is done below
3098 */ 3098 */
3099 lineadd = buf->b_ml.ml_locked_lineadd; 3099 lineadd = buf->b_ml.ml_locked_lineadd;
3100 buf->b_ml.ml_locked_lineadd = 0; 3100 buf->b_ml.ml_locked_lineadd = 0;
3101 ml_find_line(buf, (linenr_T)0, ML_FLUSH); /* flush data block */ 3101 ml_find_line(buf, (linenr_T)0, ML_FLUSH); // flush data block
3102 3102
3103 /* 3103 /*
3104 * update pointer blocks for the new data block 3104 * update pointer blocks for the new data block
3105 */ 3105 */
3106 for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; 3106 for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0;
3108 { 3108 {
3109 ip = &(buf->b_ml.ml_stack[stack_idx]); 3109 ip = &(buf->b_ml.ml_stack[stack_idx]);
3110 pb_idx = ip->ip_index; 3110 pb_idx = ip->ip_index;
3111 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) 3111 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
3112 goto theend; 3112 goto theend;
3113 pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ 3113 pp = (PTR_BL *)(hp->bh_data); // must be pointer block
3114 if (pp->pb_id != PTR_ID) 3114 if (pp->pb_id != PTR_ID)
3115 { 3115 {
3116 iemsg(_("E317: pointer block id wrong 3")); 3116 iemsg(_("E317: pointer block id wrong 3"));
3117 mf_put(mfp, hp, FALSE, FALSE); 3117 mf_put(mfp, hp, FALSE, FALSE);
3118 goto theend; 3118 goto theend;
3119 } 3119 }
3120 /* 3120 /*
3121 * TODO: If the pointer block is full and we are adding at the end 3121 * TODO: If the pointer block is full and we are adding at the end
3122 * try to insert in front of the next block 3122 * try to insert in front of the next block
3123 */ 3123 */
3124 /* block not full, add one entry */ 3124 // block not full, add one entry
3125 if (pp->pb_count < pp->pb_count_max) 3125 if (pp->pb_count < pp->pb_count_max)
3126 { 3126 {
3127 if (pb_idx + 1 < (int)pp->pb_count) 3127 if (pb_idx + 1 < (int)pp->pb_count)
3128 mch_memmove(&pp->pb_pointer[pb_idx + 2], 3128 mch_memmove(&pp->pb_pointer[pb_idx + 2],
3129 &pp->pb_pointer[pb_idx + 1], 3129 &pp->pb_pointer[pb_idx + 1],
3140 pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left; 3140 pp->pb_pointer[pb_idx].pe_old_lnum = lnum_left;
3141 if (lnum_right != 0) 3141 if (lnum_right != 0)
3142 pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right; 3142 pp->pb_pointer[pb_idx + 1].pe_old_lnum = lnum_right;
3143 3143
3144 mf_put(mfp, hp, TRUE, FALSE); 3144 mf_put(mfp, hp, TRUE, FALSE);
3145 buf->b_ml.ml_stack_top = stack_idx + 1; /* truncate stack */ 3145 buf->b_ml.ml_stack_top = stack_idx + 1; // truncate stack
3146 3146
3147 if (lineadd) 3147 if (lineadd)
3148 { 3148 {
3149 --(buf->b_ml.ml_stack_top); 3149 --(buf->b_ml.ml_stack_top);
3150 /* fix line count for rest of blocks in the stack */ 3150 // fix line count for rest of blocks in the stack
3151 ml_lineadd(buf, lineadd); 3151 ml_lineadd(buf, lineadd);
3152 /* fix stack itself */ 3152 // fix stack itself
3153 buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high += 3153 buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high +=
3154 lineadd; 3154 lineadd;
3155 ++(buf->b_ml.ml_stack_top); 3155 ++(buf->b_ml.ml_stack_top);
3156 } 3156 }
3157 3157
3158 /* 3158 /*
3159 * We are finished, break the loop here. 3159 * We are finished, break the loop here.
3160 */ 3160 */
3161 break; 3161 break;
3162 } 3162 }
3163 else /* pointer block full */ 3163 else // pointer block full
3164 { 3164 {
3165 /* 3165 /*
3166 * split the pointer block 3166 * split the pointer block
3167 * allocate a new pointer block 3167 * allocate a new pointer block
3168 * move some of the pointer into the new block 3168 * move some of the pointer into the new block
3169 * prepare for updating the parent block 3169 * prepare for updating the parent block
3170 */ 3170 */
3171 for (;;) /* do this twice when splitting block 1 */ 3171 for (;;) // do this twice when splitting block 1
3172 { 3172 {
3173 hp_new = ml_new_ptr(mfp); 3173 hp_new = ml_new_ptr(mfp);
3174 if (hp_new == NULL) /* TODO: try to fix tree */ 3174 if (hp_new == NULL) // TODO: try to fix tree
3175 goto theend; 3175 goto theend;
3176 pp_new = (PTR_BL *)(hp_new->bh_data); 3176 pp_new = (PTR_BL *)(hp_new->bh_data);
3177 3177
3178 if (hp->bh_bnum != 1) 3178 if (hp->bh_bnum != 1)
3179 break; 3179 break;
3188 pp->pb_count = 1; 3188 pp->pb_count = 1;
3189 pp->pb_pointer[0].pe_bnum = hp_new->bh_bnum; 3189 pp->pb_pointer[0].pe_bnum = hp_new->bh_bnum;
3190 pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count; 3190 pp->pb_pointer[0].pe_line_count = buf->b_ml.ml_line_count;
3191 pp->pb_pointer[0].pe_old_lnum = 1; 3191 pp->pb_pointer[0].pe_old_lnum = 1;
3192 pp->pb_pointer[0].pe_page_count = 1; 3192 pp->pb_pointer[0].pe_page_count = 1;
3193 mf_put(mfp, hp, TRUE, FALSE); /* release block 1 */ 3193 mf_put(mfp, hp, TRUE, FALSE); // release block 1
3194 hp = hp_new; /* new block is to be split */ 3194 hp = hp_new; // new block is to be split
3195 pp = pp_new; 3195 pp = pp_new;
3196 CHECK(stack_idx != 0, _("stack_idx should be 0")); 3196 CHECK(stack_idx != 0, _("stack_idx should be 0"));
3197 ip->ip_index = 0; 3197 ip->ip_index = 0;
3198 ++stack_idx; /* do block 1 again later */ 3198 ++stack_idx; // do block 1 again later
3199 } 3199 }
3200 /* 3200 /*
3201 * move the pointers after the current one to the new block 3201 * move the pointers after the current one to the new block
3202 * If there are none, the new entry will be in the new block. 3202 * If there are none, the new entry will be in the new block.
3203 */ 3203 */
3254 * Safety check: fallen out of for loop? 3254 * Safety check: fallen out of for loop?
3255 */ 3255 */
3256 if (stack_idx < 0) 3256 if (stack_idx < 0)
3257 { 3257 {
3258 iemsg(_("E318: Updated too many blocks?")); 3258 iemsg(_("E318: Updated too many blocks?"));
3259 buf->b_ml.ml_stack_top = 0; /* invalidate stack */ 3259 buf->b_ml.ml_stack_top = 0; // invalidate stack
3260 } 3260 }
3261 } 3261 }
3262 3262
3263 #ifdef FEAT_BYTEOFF 3263 #ifdef FEAT_BYTEOFF
3264 /* The line was inserted below 'lnum' */ 3264 // The line was inserted below 'lnum'
3265 ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE); 3265 ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE);
3266 #endif 3266 #endif
3267 #ifdef FEAT_NETBEANS_INTG 3267 #ifdef FEAT_NETBEANS_INTG
3268 if (netbeans_active()) 3268 if (netbeans_active())
3269 { 3269 {
3327 * 3327 *
3328 * return FAIL for failure, OK otherwise 3328 * return FAIL for failure, OK otherwise
3329 */ 3329 */
3330 int 3330 int
3331 ml_append( 3331 ml_append(
3332 linenr_T lnum, /* append after this line (can be 0) */ 3332 linenr_T lnum, // append after this line (can be 0)
3333 char_u *line, /* text of the new line */ 3333 char_u *line, // text of the new line
3334 colnr_T len, /* length of new line, including NUL, or 0 */ 3334 colnr_T len, // length of new line, including NUL, or 0
3335 int newfile) /* flag, see above */ 3335 int newfile) // flag, see above
3336 { 3336 {
3337 /* When starting up, we might still need to create the memfile */ 3337 // When starting up, we might still need to create the memfile
3338 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) 3338 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
3339 return FAIL; 3339 return FAIL;
3340 return ml_append_flush(curbuf, lnum, line, len, newfile); 3340 return ml_append_flush(curbuf, lnum, line, len, newfile);
3341 } 3341 }
3342 3342
3346 * a memline. 3346 * a memline.
3347 */ 3347 */
3348 int 3348 int
3349 ml_append_buf( 3349 ml_append_buf(
3350 buf_T *buf, 3350 buf_T *buf,
3351 linenr_T lnum, /* append after this line (can be 0) */ 3351 linenr_T lnum, // append after this line (can be 0)
3352 char_u *line, /* text of the new line */ 3352 char_u *line, // text of the new line
3353 colnr_T len, /* length of new line, including NUL, or 0 */ 3353 colnr_T len, // length of new line, including NUL, or 0
3354 int newfile) /* flag, see above */ 3354 int newfile) // flag, see above
3355 { 3355 {
3356 if (buf->b_ml.ml_mfp == NULL) 3356 if (buf->b_ml.ml_mfp == NULL)
3357 return FAIL; 3357 return FAIL;
3358 return ml_append_flush(buf, lnum, line, len, newfile); 3358 return ml_append_flush(buf, lnum, line, len, newfile);
3359 } 3359 }
3395 int copy) 3395 int copy)
3396 { 3396 {
3397 char_u *line = line_arg; 3397 char_u *line = line_arg;
3398 colnr_T len = len_arg; 3398 colnr_T len = len_arg;
3399 3399
3400 if (line == NULL) /* just checking... */ 3400 if (line == NULL) // just checking...
3401 return FAIL; 3401 return FAIL;
3402 3402
3403 /* When starting up, we might still need to create the memfile */ 3403 // When starting up, we might still need to create the memfile
3404 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) 3404 if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
3405 return FAIL; 3405 return FAIL;
3406 3406
3407 if (!has_props) 3407 if (!has_props)
3408 ++len; // include the NUL after the text 3408 ++len; // include the NUL after the text
3604 bhdr_T *hp; 3604 bhdr_T *hp;
3605 memfile_T *mfp; 3605 memfile_T *mfp;
3606 DATA_BL *dp; 3606 DATA_BL *dp;
3607 PTR_BL *pp; 3607 PTR_BL *pp;
3608 infoptr_T *ip; 3608 infoptr_T *ip;
3609 int count; /* number of entries in block */ 3609 int count; // number of entries in block
3610 int idx; 3610 int idx;
3611 int stack_idx; 3611 int stack_idx;
3612 int text_start; 3612 int text_start;
3613 int line_start; 3613 int line_start;
3614 long line_size; 3614 long line_size;
3623 lowest_marked--; 3623 lowest_marked--;
3624 3624
3625 /* 3625 /*
3626 * If the file becomes empty the last line is replaced by an empty line. 3626 * If the file becomes empty the last line is replaced by an empty line.
3627 */ 3627 */
3628 if (buf->b_ml.ml_line_count == 1) /* file becomes empty */ 3628 if (buf->b_ml.ml_line_count == 1) // file becomes empty
3629 { 3629 {
3630 if (message 3630 if (message
3631 #ifdef FEAT_NETBEANS_INTG 3631 #ifdef FEAT_NETBEANS_INTG
3632 && !netbeansSuppressNoLines 3632 && !netbeansSuppressNoLines
3633 #endif 3633 #endif
3634 ) 3634 )
3635 set_keep_msg((char_u *)_(no_lines_msg), 0); 3635 set_keep_msg((char_u *)_(no_lines_msg), 0);
3636 3636
3637 /* FEAT_BYTEOFF already handled in there, don't worry 'bout it below */ 3637 // FEAT_BYTEOFF already handled in there, don't worry 'bout it below
3638 i = ml_replace((linenr_T)1, (char_u *)"", TRUE); 3638 i = ml_replace((linenr_T)1, (char_u *)"", TRUE);
3639 buf->b_ml.ml_flags |= ML_EMPTY; 3639 buf->b_ml.ml_flags |= ML_EMPTY;
3640 3640
3641 return i; 3641 return i;
3642 } 3642 }
3652 3652
3653 if ((hp = ml_find_line(buf, lnum, ML_DELETE)) == NULL) 3653 if ((hp = ml_find_line(buf, lnum, ML_DELETE)) == NULL)
3654 return FAIL; 3654 return FAIL;
3655 3655
3656 dp = (DATA_BL *)(hp->bh_data); 3656 dp = (DATA_BL *)(hp->bh_data);
3657 /* compute line count before the delete */ 3657 // compute line count before the delete
3658 count = (long)(buf->b_ml.ml_locked_high) 3658 count = (long)(buf->b_ml.ml_locked_high)
3659 - (long)(buf->b_ml.ml_locked_low) + 2; 3659 - (long)(buf->b_ml.ml_locked_low) + 2;
3660 idx = lnum - buf->b_ml.ml_locked_low; 3660 idx = lnum - buf->b_ml.ml_locked_low;
3661 3661
3662 --buf->b_ml.ml_line_count; 3662 --buf->b_ml.ml_line_count;
3663 3663
3664 line_start = ((dp->db_index[idx]) & DB_INDEX_MASK); 3664 line_start = ((dp->db_index[idx]) & DB_INDEX_MASK);
3665 if (idx == 0) /* first line in block, text at the end */ 3665 if (idx == 0) // first line in block, text at the end
3666 line_size = dp->db_txt_end - line_start; 3666 line_size = dp->db_txt_end - line_start;
3667 else 3667 else
3668 line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start; 3668 line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start;
3669 3669
3670 #ifdef FEAT_NETBEANS_INTG 3670 #ifdef FEAT_NETBEANS_INTG
3695 * The line counts in the pointer blocks have already been adjusted by 3695 * The line counts in the pointer blocks have already been adjusted by
3696 * ml_find_line(). 3696 * ml_find_line().
3697 */ 3697 */
3698 if (count == 1) 3698 if (count == 1)
3699 { 3699 {
3700 mf_free(mfp, hp); /* free the data block */ 3700 mf_free(mfp, hp); // free the data block
3701 buf->b_ml.ml_locked = NULL; 3701 buf->b_ml.ml_locked = NULL;
3702 3702
3703 for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0; 3703 for (stack_idx = buf->b_ml.ml_stack_top - 1; stack_idx >= 0;
3704 --stack_idx) 3704 --stack_idx)
3705 { 3705 {
3706 buf->b_ml.ml_stack_top = 0; /* stack is invalid when failing */ 3706 buf->b_ml.ml_stack_top = 0; // stack is invalid when failing
3707 ip = &(buf->b_ml.ml_stack[stack_idx]); 3707 ip = &(buf->b_ml.ml_stack[stack_idx]);
3708 idx = ip->ip_index; 3708 idx = ip->ip_index;
3709 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) 3709 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
3710 goto theend; 3710 goto theend;
3711 pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ 3711 pp = (PTR_BL *)(hp->bh_data); // must be pointer block
3712 if (pp->pb_id != PTR_ID) 3712 if (pp->pb_id != PTR_ID)
3713 { 3713 {
3714 iemsg(_("E317: pointer block id wrong 4")); 3714 iemsg(_("E317: pointer block id wrong 4"));
3715 mf_put(mfp, hp, FALSE, FALSE); 3715 mf_put(mfp, hp, FALSE, FALSE);
3716 goto theend; 3716 goto theend;
3717 } 3717 }
3718 count = --(pp->pb_count); 3718 count = --(pp->pb_count);
3719 if (count == 0) /* the pointer block becomes empty! */ 3719 if (count == 0) // the pointer block becomes empty!
3720 mf_free(mfp, hp); 3720 mf_free(mfp, hp);
3721 else 3721 else
3722 { 3722 {
3723 if (count != idx) /* move entries after the deleted one */ 3723 if (count != idx) // move entries after the deleted one
3724 mch_memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1], 3724 mch_memmove(&pp->pb_pointer[idx], &pp->pb_pointer[idx + 1],
3725 (size_t)(count - idx) * sizeof(PTR_EN)); 3725 (size_t)(count - idx) * sizeof(PTR_EN));
3726 mf_put(mfp, hp, TRUE, FALSE); 3726 mf_put(mfp, hp, TRUE, FALSE);
3727 3727
3728 buf->b_ml.ml_stack_top = stack_idx; /* truncate stack */ 3728 buf->b_ml.ml_stack_top = stack_idx; // truncate stack
3729 /* fix line count for rest of blocks in the stack */ 3729 // fix line count for rest of blocks in the stack
3730 if (buf->b_ml.ml_locked_lineadd != 0) 3730 if (buf->b_ml.ml_locked_lineadd != 0)
3731 { 3731 {
3732 ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); 3732 ml_lineadd(buf, buf->b_ml.ml_locked_lineadd);
3733 buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high += 3733 buf->b_ml.ml_stack[buf->b_ml.ml_stack_top].ip_high +=
3734 buf->b_ml.ml_locked_lineadd; 3734 buf->b_ml.ml_locked_lineadd;
3792 void 3792 void
3793 ml_setmarked(linenr_T lnum) 3793 ml_setmarked(linenr_T lnum)
3794 { 3794 {
3795 bhdr_T *hp; 3795 bhdr_T *hp;
3796 DATA_BL *dp; 3796 DATA_BL *dp;
3797 /* invalid line number */ 3797 // invalid line number
3798 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count 3798 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count
3799 || curbuf->b_ml.ml_mfp == NULL) 3799 || curbuf->b_ml.ml_mfp == NULL)
3800 return; /* give error message? */ 3800 return; // give error message?
3801 3801
3802 if (lowest_marked == 0 || lowest_marked > lnum) 3802 if (lowest_marked == 0 || lowest_marked > lnum)
3803 lowest_marked = lnum; 3803 lowest_marked = lnum;
3804 3804
3805 /* 3805 /*
3806 * find the data block containing the line 3806 * find the data block containing the line
3807 * This also fills the stack with the blocks from the root to the data block 3807 * This also fills the stack with the blocks from the root to the data block
3808 * This also releases any locked block. 3808 * This also releases any locked block.
3809 */ 3809 */
3810 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) 3810 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
3811 return; /* give error message? */ 3811 return; // give error message?
3812 3812
3813 dp = (DATA_BL *)(hp->bh_data); 3813 dp = (DATA_BL *)(hp->bh_data);
3814 dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED; 3814 dp->db_index[lnum - curbuf->b_ml.ml_locked_low] |= DB_MARKED;
3815 curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY; 3815 curbuf->b_ml.ml_flags |= ML_LOCKED_DIRTY;
3816 } 3816 }
3839 * Find the data block containing the line. 3839 * Find the data block containing the line.
3840 * This also fills the stack with the blocks from the root to the data 3840 * This also fills the stack with the blocks from the root to the data
3841 * block This also releases any locked block. 3841 * block This also releases any locked block.
3842 */ 3842 */
3843 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) 3843 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
3844 return (linenr_T)0; /* give error message? */ 3844 return (linenr_T)0; // give error message?
3845 3845
3846 dp = (DATA_BL *)(hp->bh_data); 3846 dp = (DATA_BL *)(hp->bh_data);
3847 3847
3848 for (i = lnum - curbuf->b_ml.ml_locked_low; 3848 for (i = lnum - curbuf->b_ml.ml_locked_low;
3849 lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum) 3849 lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
3868 bhdr_T *hp; 3868 bhdr_T *hp;
3869 DATA_BL *dp; 3869 DATA_BL *dp;
3870 linenr_T lnum; 3870 linenr_T lnum;
3871 int i; 3871 int i;
3872 3872
3873 if (curbuf->b_ml.ml_mfp == NULL) /* nothing to do */ 3873 if (curbuf->b_ml.ml_mfp == NULL) // nothing to do
3874 return; 3874 return;
3875 3875
3876 /* 3876 /*
3877 * The search starts with line lowest_marked. 3877 * The search starts with line lowest_marked.
3878 */ 3878 */
3882 * Find the data block containing the line. 3882 * Find the data block containing the line.
3883 * This also fills the stack with the blocks from the root to the data 3883 * This also fills the stack with the blocks from the root to the data
3884 * block and releases any locked block. 3884 * block and releases any locked block.
3885 */ 3885 */
3886 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL) 3886 if ((hp = ml_find_line(curbuf, lnum, ML_FIND)) == NULL)
3887 return; /* give error message? */ 3887 return; // give error message?
3888 3888
3889 dp = (DATA_BL *)(hp->bh_data); 3889 dp = (DATA_BL *)(hp->bh_data);
3890 3890
3891 for (i = lnum - curbuf->b_ml.ml_locked_low; 3891 for (i = lnum - curbuf->b_ml.ml_locked_low;
3892 lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum) 3892 lnum <= curbuf->b_ml.ml_locked_high; ++i, ++lnum)
3920 int count; 3920 int count;
3921 int i; 3921 int i;
3922 static int entered = FALSE; 3922 static int entered = FALSE;
3923 3923
3924 if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL) 3924 if (buf->b_ml.ml_line_lnum == 0 || buf->b_ml.ml_mfp == NULL)
3925 return; /* nothing to do */ 3925 return; // nothing to do
3926 3926
3927 if (buf->b_ml.ml_flags & ML_LINE_DIRTY) 3927 if (buf->b_ml.ml_flags & ML_LINE_DIRTY)
3928 { 3928 {
3929 /* This code doesn't work recursively, but Netbeans may call back here 3929 // This code doesn't work recursively, but Netbeans may call back here
3930 * when obtaining the cursor position. */ 3930 // when obtaining the cursor position.
3931 if (entered) 3931 if (entered)
3932 return; 3932 return;
3933 entered = TRUE; 3933 entered = TRUE;
3934 3934
3935 lnum = buf->b_ml.ml_line_lnum; 3935 lnum = buf->b_ml.ml_line_lnum;
3942 { 3942 {
3943 dp = (DATA_BL *)(hp->bh_data); 3943 dp = (DATA_BL *)(hp->bh_data);
3944 idx = lnum - buf->b_ml.ml_locked_low; 3944 idx = lnum - buf->b_ml.ml_locked_low;
3945 start = ((dp->db_index[idx]) & DB_INDEX_MASK); 3945 start = ((dp->db_index[idx]) & DB_INDEX_MASK);
3946 old_line = (char_u *)dp + start; 3946 old_line = (char_u *)dp + start;
3947 if (idx == 0) /* line is last in block */ 3947 if (idx == 0) // line is last in block
3948 old_len = dp->db_txt_end - start; 3948 old_len = dp->db_txt_end - start;
3949 else /* text of previous line follows */ 3949 else // text of previous line follows
3950 old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start; 3950 old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start;
3951 new_len = buf->b_ml.ml_line_len; 3951 new_len = buf->b_ml.ml_line_len;
3952 extra = new_len - old_len; /* negative if lines gets smaller */ 3952 extra = new_len - old_len; // negative if lines gets smaller
3953 3953
3954 /* 3954 /*
3955 * if new line fits in data block, replace directly 3955 * if new line fits in data block, replace directly
3956 */ 3956 */
3957 if ((int)dp->db_free >= extra) 3957 if ((int)dp->db_free >= extra)
3958 { 3958 {
3959 /* if the length changes and there are following lines */ 3959 // if the length changes and there are following lines
3960 count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; 3960 count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1;
3961 if (extra != 0 && idx < count - 1) 3961 if (extra != 0 && idx < count - 1)
3962 { 3962 {
3963 /* move text of following lines */ 3963 // move text of following lines
3964 mch_memmove((char *)dp + dp->db_txt_start - extra, 3964 mch_memmove((char *)dp + dp->db_txt_start - extra,
3965 (char *)dp + dp->db_txt_start, 3965 (char *)dp + dp->db_txt_start,
3966 (size_t)(start - dp->db_txt_start)); 3966 (size_t)(start - dp->db_txt_start));
3967 3967
3968 /* adjust pointers of this and following lines */ 3968 // adjust pointers of this and following lines
3969 for (i = idx + 1; i < count; ++i) 3969 for (i = idx + 1; i < count; ++i)
3970 dp->db_index[i] -= extra; 3970 dp->db_index[i] -= extra;
3971 } 3971 }
3972 dp->db_index[idx] -= extra; 3972 dp->db_index[idx] -= extra;
3973 3973
3974 /* adjust free space */ 3974 // adjust free space
3975 dp->db_free -= extra; 3975 dp->db_free -= extra;
3976 dp->db_txt_start -= extra; 3976 dp->db_txt_start -= extra;
3977 3977
3978 /* copy new line into the data block */ 3978 // copy new line into the data block
3979 mch_memmove(old_line - extra, new_line, (size_t)new_len); 3979 mch_memmove(old_line - extra, new_line, (size_t)new_len);
3980 buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); 3980 buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS);
3981 #ifdef FEAT_BYTEOFF 3981 #ifdef FEAT_BYTEOFF
3982 /* The else case is already covered by the insert and delete */ 3982 // The else case is already covered by the insert and delete
3983 ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE); 3983 ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE);
3984 #endif 3984 #endif
3985 } 3985 }
3986 else 3986 else
3987 { 3987 {
3990 * Append first, because ml_delete_int() cannot delete the 3990 * Append first, because ml_delete_int() cannot delete the
3991 * last line in a buffer, which causes trouble for a buffer 3991 * last line in a buffer, which causes trouble for a buffer
3992 * that has only one line. 3992 * that has only one line.
3993 * Don't forget to copy the mark! 3993 * Don't forget to copy the mark!
3994 */ 3994 */
3995 /* How about handling errors??? */ 3995 // How about handling errors???
3996 (void)ml_append_int(buf, lnum, new_line, new_len, FALSE, 3996 (void)ml_append_int(buf, lnum, new_line, new_len, FALSE,
3997 (dp->db_index[idx] & DB_MARKED)); 3997 (dp->db_index[idx] & DB_MARKED));
3998 (void)ml_delete_int(buf, lnum, FALSE); 3998 (void)ml_delete_int(buf, lnum, FALSE);
3999 } 3999 }
4000 } 4000 }
4093 if (ML_SIMPLE(action) 4093 if (ML_SIMPLE(action)
4094 && buf->b_ml.ml_locked_low <= lnum 4094 && buf->b_ml.ml_locked_low <= lnum
4095 && buf->b_ml.ml_locked_high >= lnum 4095 && buf->b_ml.ml_locked_high >= lnum
4096 && !mf_dont_release) 4096 && !mf_dont_release)
4097 { 4097 {
4098 /* remember to update pointer blocks and stack later */ 4098 // remember to update pointer blocks and stack later
4099 if (action == ML_INSERT) 4099 if (action == ML_INSERT)
4100 { 4100 {
4101 ++(buf->b_ml.ml_locked_lineadd); 4101 ++(buf->b_ml.ml_locked_lineadd);
4102 ++(buf->b_ml.ml_locked_high); 4102 ++(buf->b_ml.ml_locked_high);
4103 } 4103 }
4119 */ 4119 */
4120 if (buf->b_ml.ml_locked_lineadd != 0) 4120 if (buf->b_ml.ml_locked_lineadd != 0)
4121 ml_lineadd(buf, buf->b_ml.ml_locked_lineadd); 4121 ml_lineadd(buf, buf->b_ml.ml_locked_lineadd);
4122 } 4122 }
4123 4123
4124 if (action == ML_FLUSH) /* nothing else to do */ 4124 if (action == ML_FLUSH) // nothing else to do
4125 return NULL; 4125 return NULL;
4126 4126
4127 bnum = 1; /* start at the root of the tree */ 4127 bnum = 1; // start at the root of the tree
4128 page_count = 1; 4128 page_count = 1;
4129 low = 1; 4129 low = 1;
4130 high = buf->b_ml.ml_line_count; 4130 high = buf->b_ml.ml_line_count;
4131 4131
4132 if (action == ML_FIND) /* first try stack entries */ 4132 if (action == ML_FIND) // first try stack entries
4133 { 4133 {
4134 for (top = buf->b_ml.ml_stack_top - 1; top >= 0; --top) 4134 for (top = buf->b_ml.ml_stack_top - 1; top >= 0; --top)
4135 { 4135 {
4136 ip = &(buf->b_ml.ml_stack[top]); 4136 ip = &(buf->b_ml.ml_stack[top]);
4137 if (ip->ip_low <= lnum && ip->ip_high >= lnum) 4137 if (ip->ip_low <= lnum && ip->ip_high >= lnum)
4138 { 4138 {
4139 bnum = ip->ip_bnum; 4139 bnum = ip->ip_bnum;
4140 low = ip->ip_low; 4140 low = ip->ip_low;
4141 high = ip->ip_high; 4141 high = ip->ip_high;
4142 buf->b_ml.ml_stack_top = top; /* truncate stack at prev entry */ 4142 buf->b_ml.ml_stack_top = top; // truncate stack at prev entry
4143 break; 4143 break;
4144 } 4144 }
4145 } 4145 }
4146 if (top < 0) 4146 if (top < 0)
4147 buf->b_ml.ml_stack_top = 0; /* not found, start at the root */ 4147 buf->b_ml.ml_stack_top = 0; // not found, start at the root
4148 } 4148 }
4149 else /* ML_DELETE or ML_INSERT */ 4149 else // ML_DELETE or ML_INSERT
4150 buf->b_ml.ml_stack_top = 0; /* start at the root */ 4150 buf->b_ml.ml_stack_top = 0; // start at the root
4151 4151
4152 /* 4152 /*
4153 * search downwards in the tree until a data block is found 4153 * search downwards in the tree until a data block is found
4154 */ 4154 */
4155 for (;;) 4155 for (;;)
4164 ++high; 4164 ++high;
4165 else if (action == ML_DELETE) 4165 else if (action == ML_DELETE)
4166 --high; 4166 --high;
4167 4167
4168 dp = (DATA_BL *)(hp->bh_data); 4168 dp = (DATA_BL *)(hp->bh_data);
4169 if (dp->db_id == DATA_ID) /* data block */ 4169 if (dp->db_id == DATA_ID) // data block
4170 { 4170 {
4171 buf->b_ml.ml_locked = hp; 4171 buf->b_ml.ml_locked = hp;
4172 buf->b_ml.ml_locked_low = low; 4172 buf->b_ml.ml_locked_low = low;
4173 buf->b_ml.ml_locked_high = high; 4173 buf->b_ml.ml_locked_high = high;
4174 buf->b_ml.ml_locked_lineadd = 0; 4174 buf->b_ml.ml_locked_lineadd = 0;
4175 buf->b_ml.ml_flags &= ~(ML_LOCKED_DIRTY | ML_LOCKED_POS); 4175 buf->b_ml.ml_flags &= ~(ML_LOCKED_DIRTY | ML_LOCKED_POS);
4176 return hp; 4176 return hp;
4177 } 4177 }
4178 4178
4179 pp = (PTR_BL *)(dp); /* must be pointer block */ 4179 pp = (PTR_BL *)(dp); // must be pointer block
4180 if (pp->pb_id != PTR_ID) 4180 if (pp->pb_id != PTR_ID)
4181 { 4181 {
4182 iemsg(_("E317: pointer block id wrong")); 4182 iemsg(_("E317: pointer block id wrong"));
4183 goto error_block; 4183 goto error_block;
4184 } 4184 }
4185 4185
4186 if ((top = ml_add_stack(buf)) < 0) /* add new entry to stack */ 4186 if ((top = ml_add_stack(buf)) < 0) // add new entry to stack
4187 goto error_block; 4187 goto error_block;
4188 ip = &(buf->b_ml.ml_stack[top]); 4188 ip = &(buf->b_ml.ml_stack[top]);
4189 ip->ip_bnum = bnum; 4189 ip->ip_bnum = bnum;
4190 ip->ip_low = low; 4190 ip->ip_low = low;
4191 ip->ip_high = high; 4191 ip->ip_high = high;
4192 ip->ip_index = -1; /* index not known yet */ 4192 ip->ip_index = -1; // index not known yet
4193 4193
4194 dirty = FALSE; 4194 dirty = FALSE;
4195 for (idx = 0; idx < (int)pp->pb_count; ++idx) 4195 for (idx = 0; idx < (int)pp->pb_count; ++idx)
4196 { 4196 {
4197 t = pp->pb_pointer[idx].pe_line_count; 4197 t = pp->pb_pointer[idx].pe_line_count;
4219 } 4219 }
4220 4220
4221 break; 4221 break;
4222 } 4222 }
4223 } 4223 }
4224 if (idx >= (int)pp->pb_count) /* past the end: something wrong! */ 4224 if (idx >= (int)pp->pb_count) // past the end: something wrong!
4225 { 4225 {
4226 if (lnum > buf->b_ml.ml_line_count) 4226 if (lnum > buf->b_ml.ml_line_count)
4227 siemsg(_("E322: line number out of range: %ld past the end"), 4227 siemsg(_("E322: line number out of range: %ld past the end"),
4228 lnum - buf->b_ml.ml_line_count); 4228 lnum - buf->b_ml.ml_line_count);
4229 4229
4271 int top; 4271 int top;
4272 infoptr_T *newstack; 4272 infoptr_T *newstack;
4273 4273
4274 top = buf->b_ml.ml_stack_top; 4274 top = buf->b_ml.ml_stack_top;
4275 4275
4276 /* may have to increase the stack size */ 4276 // may have to increase the stack size
4277 if (top == buf->b_ml.ml_stack_size) 4277 if (top == buf->b_ml.ml_stack_size)
4278 { 4278 {
4279 CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */ 4279 CHECK(top > 0, _("Stack size increases")); // more than 5 levels???
4280 4280
4281 newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR); 4281 newstack = ALLOC_MULT(infoptr_T, buf->b_ml.ml_stack_size + STACK_INCR);
4282 if (newstack == NULL) 4282 if (newstack == NULL)
4283 return -1; 4283 return -1;
4284 if (top > 0) 4284 if (top > 0)
4315 for (idx = buf->b_ml.ml_stack_top - 1; idx >= 0; --idx) 4315 for (idx = buf->b_ml.ml_stack_top - 1; idx >= 0; --idx)
4316 { 4316 {
4317 ip = &(buf->b_ml.ml_stack[idx]); 4317 ip = &(buf->b_ml.ml_stack[idx]);
4318 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL) 4318 if ((hp = mf_get(mfp, ip->ip_bnum, 1)) == NULL)
4319 break; 4319 break;
4320 pp = (PTR_BL *)(hp->bh_data); /* must be pointer block */ 4320 pp = (PTR_BL *)(hp->bh_data); // must be pointer block
4321 if (pp->pb_id != PTR_ID) 4321 if (pp->pb_id != PTR_ID)
4322 { 4322 {
4323 mf_put(mfp, hp, FALSE, FALSE); 4323 mf_put(mfp, hp, FALSE, FALSE);
4324 iemsg(_("E317: pointer block id wrong 2")); 4324 iemsg(_("E317: pointer block id wrong 2"));
4325 break; 4325 break;
4346 int depth = 0; 4346 int depth = 0;
4347 4347
4348 if (fname == NULL) 4348 if (fname == NULL)
4349 return FAIL; 4349 return FAIL;
4350 4350
4351 /* Put the result so far in tmp[], starting with the original name. */ 4351 // Put the result so far in tmp[], starting with the original name.
4352 vim_strncpy(tmp, fname, MAXPATHL - 1); 4352 vim_strncpy(tmp, fname, MAXPATHL - 1);
4353 4353
4354 for (;;) 4354 for (;;)
4355 { 4355 {
4356 /* Limit symlink depth to 100, catch recursive loops. */ 4356 // Limit symlink depth to 100, catch recursive loops.
4357 if (++depth == 100) 4357 if (++depth == 100)
4358 { 4358 {
4359 semsg(_("E773: Symlink loop for \"%s\""), fname); 4359 semsg(_("E773: Symlink loop for \"%s\""), fname);
4360 return FAIL; 4360 return FAIL;
4361 } 4361 }
4363 ret = readlink((char *)tmp, (char *)buf, MAXPATHL - 1); 4363 ret = readlink((char *)tmp, (char *)buf, MAXPATHL - 1);
4364 if (ret <= 0) 4364 if (ret <= 0)
4365 { 4365 {
4366 if (errno == EINVAL || errno == ENOENT) 4366 if (errno == EINVAL || errno == ENOENT)
4367 { 4367 {
4368 /* Found non-symlink or not existing file, stop here. 4368 // Found non-symlink or not existing file, stop here.
4369 * When at the first level use the unmodified name, skip the 4369 // When at the first level use the unmodified name, skip the
4370 * call to vim_FullName(). */ 4370 // call to vim_FullName().
4371 if (depth == 1) 4371 if (depth == 1)
4372 return FAIL; 4372 return FAIL;
4373 4373
4374 /* Use the resolved name in tmp[]. */ 4374 // Use the resolved name in tmp[].
4375 break; 4375 break;
4376 } 4376 }
4377 4377
4378 /* There must be some error reading links, use original name. */ 4378 // There must be some error reading links, use original name.
4379 return FAIL; 4379 return FAIL;
4380 } 4380 }
4381 buf[ret] = NUL; 4381 buf[ret] = NUL;
4382 4382
4383 /* 4383 /*
4428 #if defined(UNIX) || defined(MSWIN) // Need _very_ long file names 4428 #if defined(UNIX) || defined(MSWIN) // Need _very_ long file names
4429 int len = (int)STRLEN(dir_name); 4429 int len = (int)STRLEN(dir_name);
4430 4430
4431 s = dir_name + len; 4431 s = dir_name + len;
4432 if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2]) 4432 if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2])
4433 { /* Ends with '//', Use Full path */ 4433 { // Ends with '//', Use Full path
4434 r = NULL; 4434 r = NULL;
4435 if ((s = make_percent_swname(dir_name, fname)) != NULL) 4435 if ((s = make_percent_swname(dir_name, fname)) != NULL)
4436 { 4436 {
4437 r = modname(s, (char_u *)".swp", FALSE); 4437 r = modname(s, (char_u *)".swp", FALSE);
4438 vim_free(s); 4438 vim_free(s);
4440 return r; 4440 return r;
4441 } 4441 }
4442 #endif 4442 #endif
4443 4443
4444 #ifdef HAVE_READLINK 4444 #ifdef HAVE_READLINK
4445 /* Expand symlink in the file name, so that we put the swap file with the 4445 // Expand symlink in the file name, so that we put the swap file with the
4446 * actual file instead of with the symlink. */ 4446 // actual file instead of with the symlink.
4447 if (resolve_symlink(fname, fname_buf) == OK) 4447 if (resolve_symlink(fname, fname_buf) == OK)
4448 fname_res = fname_buf; 4448 fname_res = fname_buf;
4449 #endif 4449 #endif
4450 4450
4451 r = buf_modname( 4451 r = buf_modname(
4455 #if defined(VMS) 4455 #if defined(VMS)
4456 "_swp", 4456 "_swp",
4457 #else 4457 #else
4458 ".swp", 4458 ".swp",
4459 #endif 4459 #endif
4460 /* Prepend a '.' to the swap file name for the current directory. */ 4460 // Prepend a '.' to the swap file name for the current directory.
4461 dir_name[0] == '.' && dir_name[1] == NUL); 4461 dir_name[0] == '.' && dir_name[1] == NUL);
4462 if (r == NULL) /* out of memory */ 4462 if (r == NULL) // out of memory
4463 return NULL; 4463 return NULL;
4464 4464
4465 s = get_file_in_dir(r, dir_name); 4465 s = get_file_in_dir(r, dir_name);
4466 vim_free(r); 4466 vim_free(r);
4467 return s; 4467 return s;
4480 * The return value is an allocated string and can be NULL. 4480 * The return value is an allocated string and can be NULL.
4481 */ 4481 */
4482 char_u * 4482 char_u *
4483 get_file_in_dir( 4483 get_file_in_dir(
4484 char_u *fname, 4484 char_u *fname,
4485 char_u *dname) /* don't use "dirname", it is a global for Alpha */ 4485 char_u *dname) // don't use "dirname", it is a global for Alpha
4486 { 4486 {
4487 char_u *t; 4487 char_u *t;
4488 char_u *tail; 4488 char_u *tail;
4489 char_u *retval; 4489 char_u *retval;
4490 int save_char; 4490 int save_char;
4493 4493
4494 if (dname[0] == '.' && dname[1] == NUL) 4494 if (dname[0] == '.' && dname[1] == NUL)
4495 retval = vim_strsave(fname); 4495 retval = vim_strsave(fname);
4496 else if (dname[0] == '.' && vim_ispathsep(dname[1])) 4496 else if (dname[0] == '.' && vim_ispathsep(dname[1]))
4497 { 4497 {
4498 if (tail == fname) /* no path before file name */ 4498 if (tail == fname) // no path before file name
4499 retval = concat_fnames(dname + 2, tail, TRUE); 4499 retval = concat_fnames(dname + 2, tail, TRUE);
4500 else 4500 else
4501 { 4501 {
4502 save_char = *tail; 4502 save_char = *tail;
4503 *tail = NUL; 4503 *tail = NUL;
4504 t = concat_fnames(fname, dname + 2, TRUE); 4504 t = concat_fnames(fname, dname + 2, TRUE);
4505 *tail = save_char; 4505 *tail = save_char;
4506 if (t == NULL) /* out of memory */ 4506 if (t == NULL) // out of memory
4507 retval = NULL; 4507 retval = NULL;
4508 else 4508 else
4509 { 4509 {
4510 retval = concat_fnames(t, tail, TRUE); 4510 retval = concat_fnames(t, tail, TRUE);
4511 vim_free(t); 4511 vim_free(t);
4528 /* 4528 /*
4529 * Print the ATTENTION message: info about an existing swap file. 4529 * Print the ATTENTION message: info about an existing swap file.
4530 */ 4530 */
4531 static void 4531 static void
4532 attention_message( 4532 attention_message(
4533 buf_T *buf, /* buffer being edited */ 4533 buf_T *buf, // buffer being edited
4534 char_u *fname) /* swap file name */ 4534 char_u *fname) // swap file name
4535 { 4535 {
4536 stat_T st; 4536 stat_T st;
4537 time_t swap_mtime; 4537 time_t swap_mtime;
4538 4538
4539 ++no_wait_return; 4539 ++no_wait_return;
4554 msg_puts(_(" dated: ")); 4554 msg_puts(_(" dated: "));
4555 msg_puts(get_ctime(st.st_mtime, TRUE)); 4555 msg_puts(get_ctime(st.st_mtime, TRUE));
4556 if (swap_mtime != 0 && st.st_mtime > swap_mtime) 4556 if (swap_mtime != 0 && st.st_mtime > swap_mtime)
4557 msg_puts(_(" NEWER than swap file!\n")); 4557 msg_puts(_(" NEWER than swap file!\n"));
4558 } 4558 }
4559 /* Some of these messages are long to allow translation to 4559 // Some of these messages are long to allow translation to
4560 * other languages. */ 4560 // other languages.
4561 msg_puts(_("\n(1) Another program may be editing the same file. If this is the case,\n be careful not to end up with two different instances of the same\n file when making changes. Quit, or continue with caution.\n")); 4561 msg_puts(_("\n(1) Another program may be editing the same file. If this is the case,\n be careful not to end up with two different instances of the same\n file when making changes. Quit, or continue with caution.\n"));
4562 msg_puts(_("(2) An edit session for this file crashed.\n")); 4562 msg_puts(_("(2) An edit session for this file crashed.\n"));
4563 msg_puts(_(" If this is the case, use \":recover\" or \"vim -r ")); 4563 msg_puts(_(" If this is the case, use \":recover\" or \"vim -r "));
4564 msg_outtrans(buf->b_fname); 4564 msg_outtrans(buf->b_fname);
4565 msg_puts(_("\"\n to recover the changes (see \":help recovery\").\n")); 4565 msg_puts(_("\"\n to recover the changes (see \":help recovery\").\n"));
4586 do_swapexists(buf_T *buf, char_u *fname) 4586 do_swapexists(buf_T *buf, char_u *fname)
4587 { 4587 {
4588 set_vim_var_string(VV_SWAPNAME, fname, -1); 4588 set_vim_var_string(VV_SWAPNAME, fname, -1);
4589 set_vim_var_string(VV_SWAPCHOICE, NULL, -1); 4589 set_vim_var_string(VV_SWAPCHOICE, NULL, -1);
4590 4590
4591 /* Trigger SwapExists autocommands with <afile> set to the file being 4591 // Trigger SwapExists autocommands with <afile> set to the file being
4592 * edited. Disallow changing directory here. */ 4592 // edited. Disallow changing directory here.
4593 ++allbuf_lock; 4593 ++allbuf_lock;
4594 apply_autocmds(EVENT_SWAPEXISTS, buf->b_fname, NULL, FALSE, NULL); 4594 apply_autocmds(EVENT_SWAPEXISTS, buf->b_fname, NULL, FALSE, NULL);
4595 --allbuf_lock; 4595 --allbuf_lock;
4596 4596
4597 set_vim_var_string(VV_SWAPNAME, NULL, -1); 4597 set_vim_var_string(VV_SWAPNAME, NULL, -1);
4622 * Note: May trigger SwapExists autocmd, pointers may change! 4622 * Note: May trigger SwapExists autocmd, pointers may change!
4623 */ 4623 */
4624 static char_u * 4624 static char_u *
4625 findswapname( 4625 findswapname(
4626 buf_T *buf, 4626 buf_T *buf,
4627 char_u **dirp, /* pointer to list of directories */ 4627 char_u **dirp, // pointer to list of directories
4628 char_u *old_fname) /* don't give warning for this file name */ 4628 char_u *old_fname) // don't give warning for this file name
4629 { 4629 {
4630 char_u *fname; 4630 char_u *fname;
4631 int n; 4631 int n;
4632 char_u *dir_name; 4632 char_u *dir_name;
4633 #ifdef AMIGA 4633 #ifdef AMIGA
4679 (void)copy_option_part(dirp, dir_name, 31000, ","); 4679 (void)copy_option_part(dirp, dir_name, 31000, ",");
4680 4680
4681 /* 4681 /*
4682 * we try different names until we find one that does not exist yet 4682 * we try different names until we find one that does not exist yet
4683 */ 4683 */
4684 if (dir_name == NULL) /* out of memory */ 4684 if (dir_name == NULL) // out of memory
4685 fname = NULL; 4685 fname = NULL;
4686 else 4686 else
4687 fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name); 4687 fname = makeswapname(buf_fname, buf->b_ffname, buf, dir_name);
4688 4688
4689 for (;;) 4689 for (;;)
4690 { 4690 {
4691 if (fname == NULL) /* must be out of memory */ 4691 if (fname == NULL) // must be out of memory
4692 break; 4692 break;
4693 if ((n = (int)STRLEN(fname)) == 0) /* safety check */ 4693 if ((n = (int)STRLEN(fname)) == 0) // safety check
4694 { 4694 {
4695 VIM_CLEAR(fname); 4695 VIM_CLEAR(fname);
4696 break; 4696 break;
4697 } 4697 }
4698 #if defined(UNIX) 4698 #if defined(UNIX)
4723 { 4723 {
4724 fname2 = alloc(n + 2); 4724 fname2 = alloc(n + 2);
4725 if (fname2 != NULL) 4725 if (fname2 != NULL)
4726 { 4726 {
4727 STRCPY(fname2, fname); 4727 STRCPY(fname2, fname);
4728 /* if fname == "xx.xx.swp", fname2 = "xx.xx.swx" 4728 // if fname == "xx.xx.swp", fname2 = "xx.xx.swx"
4729 * if fname == ".xx.swp", fname2 = ".xx.swpx" 4729 // if fname == ".xx.swp", fname2 = ".xx.swpx"
4730 * if fname == "123456789.swp", fname2 = "12345678x.swp" 4730 // if fname == "123456789.swp", fname2 = "12345678x.swp"
4731 */
4732 if (vim_strchr(tail, '.') != NULL) 4731 if (vim_strchr(tail, '.') != NULL)
4733 fname2[n - 1] = 'x'; 4732 fname2[n - 1] = 'x';
4734 else if (*gettail(fname) == '.') 4733 else if (*gettail(fname) == '.')
4735 { 4734 {
4736 fname2[n] = 'x'; 4735 fname2[n] = 'x';
4781 { 4780 {
4782 buf->b_shortname = TRUE; 4781 buf->b_shortname = TRUE;
4783 vim_free(fname); 4782 vim_free(fname);
4784 fname = makeswapname(buf_fname, buf->b_ffname, 4783 fname = makeswapname(buf_fname, buf->b_ffname,
4785 buf, dir_name); 4784 buf, dir_name);
4786 continue; /* try again with b_shortname set */ 4785 continue; // try again with b_shortname set
4787 } 4786 }
4788 } 4787 }
4789 } 4788 }
4790 } 4789 }
4791 #endif 4790 #endif
4792 /* 4791 /*
4793 * check if the swapfile already exists 4792 * check if the swapfile already exists
4794 */ 4793 */
4795 if (mch_getperm(fname) < 0) /* it does not exist */ 4794 if (mch_getperm(fname) < 0) // it does not exist
4796 { 4795 {
4797 #ifdef HAVE_LSTAT 4796 #ifdef HAVE_LSTAT
4798 stat_T sb; 4797 stat_T sb;
4799 4798
4800 /* 4799 /*
4808 /* 4807 /*
4809 * on the Amiga mch_getperm() will return -1 when the file exists 4808 * on the Amiga mch_getperm() will return -1 when the file exists
4810 * but is being used by another program. This happens if you edit 4809 * but is being used by another program. This happens if you edit
4811 * a file twice. 4810 * a file twice.
4812 */ 4811 */
4813 if (fh != (BPTR)NULL) /* can open file, OK */ 4812 if (fh != (BPTR)NULL) // can open file, OK
4814 { 4813 {
4815 Close(fh); 4814 Close(fh);
4816 mch_remove(fname); 4815 mch_remove(fname);
4817 break; 4816 break;
4818 } 4817 }
4830 break; 4829 break;
4831 4830
4832 /* 4831 /*
4833 * get here when file already exists 4832 * get here when file already exists
4834 */ 4833 */
4835 if (fname[n - 2] == 'w' && fname[n - 1] == 'p') /* first try */ 4834 if (fname[n - 2] == 'w' && fname[n - 1] == 'p') // first try
4836 { 4835 {
4837 /* 4836 /*
4838 * on MS-DOS compatible filesystems (e.g. messydos) file.doc.swp 4837 * on MS-DOS compatible filesystems (e.g. messydos) file.doc.swp
4839 * and file.doc are the same file. To guess if this problem is 4838 * and file.doc are the same file. To guess if this problem is
4840 * present try if file.doc.swx exists. If it does, we set 4839 * present try if file.doc.swx exists. If it does, we set
4841 * buf->b_shortname and try file_doc.swp (dots replaced by 4840 * buf->b_shortname and try file_doc.swp (dots replaced by
4842 * underscores for this file), and try again. If it doesn't we 4841 * underscores for this file), and try again. If it doesn't we
4843 * assume that "file.doc.swp" already exists. 4842 * assume that "file.doc.swp" already exists.
4844 */ 4843 */
4845 if (!(buf->b_p_sn || buf->b_shortname)) /* not tried yet */ 4844 if (!(buf->b_p_sn || buf->b_shortname)) // not tried yet
4846 { 4845 {
4847 fname[n - 1] = 'x'; 4846 fname[n - 1] = 'x';
4848 r = mch_getperm(fname); /* try "file.swx" */ 4847 r = mch_getperm(fname); // try "file.swx"
4849 fname[n - 1] = 'p'; 4848 fname[n - 1] = 'p';
4850 if (r >= 0) /* "file.swx" seems to exist */ 4849 if (r >= 0) // "file.swx" seems to exist
4851 { 4850 {
4852 buf->b_shortname = TRUE; 4851 buf->b_shortname = TRUE;
4853 vim_free(fname); 4852 vim_free(fname);
4854 fname = makeswapname(buf_fname, buf->b_ffname, 4853 fname = makeswapname(buf_fname, buf->b_ffname,
4855 buf, dir_name); 4854 buf, dir_name);
4856 continue; /* try again with '.' replaced with '_' */ 4855 continue; // try again with '.' replaced with '_'
4857 } 4856 }
4858 } 4857 }
4859 /* 4858 /*
4860 * If we get here the ".swp" file really exists. 4859 * If we get here the ".swp" file really exists.
4861 * Give an error message, unless recovering, no file name, we are 4860 * Give an error message, unless recovering, no file name, we are
4889 if (fnamecmp(gettail(buf->b_ffname), 4888 if (fnamecmp(gettail(buf->b_ffname),
4890 gettail(b0.b0_fname)) != 0 4889 gettail(b0.b0_fname)) != 0
4891 || !same_directory(fname, buf->b_ffname)) 4890 || !same_directory(fname, buf->b_ffname))
4892 { 4891 {
4893 #ifdef CHECK_INODE 4892 #ifdef CHECK_INODE
4894 /* Symlinks may point to the same file even 4893 // Symlinks may point to the same file even
4895 * when the name differs, need to check the 4894 // when the name differs, need to check the
4896 * inode too. */ 4895 // inode too.
4897 expand_env(b0.b0_fname, NameBuff, MAXPATHL); 4896 expand_env(b0.b0_fname, NameBuff, MAXPATHL);
4898 if (fnamecmp_ino(buf->b_ffname, NameBuff, 4897 if (fnamecmp_ino(buf->b_ffname, NameBuff,
4899 char_to_long(b0.b0_ino))) 4898 char_to_long(b0.b0_ino)))
4900 #endif 4899 #endif
4901 differ = TRUE; 4900 differ = TRUE;
4919 } 4918 }
4920 } 4919 }
4921 close(fd); 4920 close(fd);
4922 } 4921 }
4923 4922
4924 /* give the ATTENTION message when there is an old swap file 4923 // give the ATTENTION message when there is an old swap file
4925 * for the current file, and the buffer was not recovered. */ 4924 // for the current file, and the buffer was not recovered.
4926 if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED) 4925 if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED)
4927 && vim_strchr(p_shm, SHM_ATTENTION) == NULL) 4926 && vim_strchr(p_shm, SHM_ATTENTION) == NULL)
4928 { 4927 {
4929 int choice = 0; 4928 int choice = 0;
4930 stat_T st; 4929 stat_T st;
4931 #ifdef CREATE_DUMMY_FILE 4930 #ifdef CREATE_DUMMY_FILE
4932 int did_use_dummy = FALSE; 4931 int did_use_dummy = FALSE;
4933 4932
4934 /* Avoid getting a warning for the file being created 4933 // Avoid getting a warning for the file being created
4935 * outside of Vim, it was created at the start of this 4934 // outside of Vim, it was created at the start of this
4936 * function. Delete the file now, because Vim might exit 4935 // function. Delete the file now, because Vim might exit
4937 * here if the window is closed. */ 4936 // here if the window is closed.
4938 if (dummyfd != NULL) 4937 if (dummyfd != NULL)
4939 { 4938 {
4940 fclose(dummyfd); 4939 fclose(dummyfd);
4941 dummyfd = NULL; 4940 dummyfd = NULL;
4942 mch_remove(buf_fname); 4941 mch_remove(buf_fname);
5018 # endif 5017 # endif
5019 (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"), 1, NULL, FALSE); 5018 (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"), 1, NULL, FALSE);
5020 5019
5021 # ifdef HAVE_PROCESS_STILL_RUNNING 5020 # ifdef HAVE_PROCESS_STILL_RUNNING
5022 if (process_still_running && choice >= 4) 5021 if (process_still_running && choice >= 4)
5023 choice++; /* Skip missing "Delete it" button */ 5022 choice++; // Skip missing "Delete it" button
5024 # endif 5023 # endif
5025 vim_free(name); 5024 vim_free(name);
5026 5025
5027 /* pretend screen didn't scroll, need redraw anyway */ 5026 // pretend screen didn't scroll, need redraw anyway
5028 msg_scrolled = 0; 5027 msg_scrolled = 0;
5029 redraw_all_later(NOT_VALID); 5028 redraw_all_later(NOT_VALID);
5030 } 5029 }
5031 #endif 5030 #endif
5032 5031
5052 swap_exists_action = SEA_QUIT; 5051 swap_exists_action = SEA_QUIT;
5053 got_int = TRUE; 5052 got_int = TRUE;
5054 break; 5053 break;
5055 } 5054 }
5056 5055
5057 /* If the file was deleted this fname can be used. */ 5056 // If the file was deleted this fname can be used.
5058 if (mch_getperm(fname) < 0) 5057 if (mch_getperm(fname) < 0)
5059 break; 5058 break;
5060 } 5059 }
5061 else 5060 else
5062 { 5061 {
5063 msg_puts("\n"); 5062 msg_puts("\n");
5064 if (msg_silent == 0) 5063 if (msg_silent == 0)
5065 /* call wait_return() later */ 5064 // call wait_return() later
5066 need_wait_return = TRUE; 5065 need_wait_return = TRUE;
5067 } 5066 }
5068 5067
5069 #ifdef CREATE_DUMMY_FILE 5068 #ifdef CREATE_DUMMY_FILE
5070 /* Going to try another name, need the dummy file again. */ 5069 // Going to try another name, need the dummy file again.
5071 if (did_use_dummy) 5070 if (did_use_dummy)
5072 dummyfd = mch_fopen((char *)buf_fname, "w"); 5071 dummyfd = mch_fopen((char *)buf_fname, "w");
5073 #endif 5072 #endif
5074 } 5073 }
5075 } 5074 }
5079 * Change the ".swp" extension to find another file that can be used. 5078 * Change the ".swp" extension to find another file that can be used.
5080 * First decrement the last char: ".swo", ".swn", etc. 5079 * First decrement the last char: ".swo", ".swn", etc.
5081 * If that still isn't enough decrement the last but one char: ".svz" 5080 * If that still isn't enough decrement the last but one char: ".svz"
5082 * Can happen when editing many "No Name" buffers. 5081 * Can happen when editing many "No Name" buffers.
5083 */ 5082 */
5084 if (fname[n - 1] == 'a') /* ".s?a" */ 5083 if (fname[n - 1] == 'a') // ".s?a"
5085 { 5084 {
5086 if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */ 5085 if (fname[n - 2] == 'a') // ".saa": tried enough, give up
5087 { 5086 {
5088 emsg(_("E326: Too many swap files found")); 5087 emsg(_("E326: Too many swap files found"));
5089 VIM_CLEAR(fname); 5088 VIM_CLEAR(fname);
5090 break; 5089 break;
5091 } 5090 }
5092 --fname[n - 2]; /* ".svz", ".suz", etc. */ 5091 --fname[n - 2]; // ".svz", ".suz", etc.
5093 fname[n - 1] = 'z' + 1; 5092 fname[n - 1] = 'z' + 1;
5094 } 5093 }
5095 --fname[n - 1]; /* ".swo", ".swn", etc. */ 5094 --fname[n - 1]; // ".swo", ".swn", etc.
5096 } 5095 }
5097 5096
5098 vim_free(dir_name); 5097 vim_free(dir_name);
5099 #ifdef CREATE_DUMMY_FILE 5098 #ifdef CREATE_DUMMY_FILE
5100 if (dummyfd != NULL) /* file has been created temporarily */ 5099 if (dummyfd != NULL) // file has been created temporarily
5101 { 5100 {
5102 fclose(dummyfd); 5101 fclose(dummyfd);
5103 mch_remove(buf_fname); 5102 mch_remove(buf_fname);
5104 } 5103 }
5105 #endif 5104 #endif
5169 * versions. 5168 * versions.
5170 */ 5169 */
5171 5170
5172 static int 5171 static int
5173 fnamecmp_ino( 5172 fnamecmp_ino(
5174 char_u *fname_c, /* current file name */ 5173 char_u *fname_c, // current file name
5175 char_u *fname_s, /* file name from swap file */ 5174 char_u *fname_s, // file name from swap file
5176 long ino_block0) 5175 long ino_block0)
5177 { 5176 {
5178 stat_T st; 5177 stat_T st;
5179 ino_t ino_c = 0; /* ino of current file */ 5178 ino_t ino_c = 0; // ino of current file
5180 ino_t ino_s; /* ino of file from swap file */ 5179 ino_t ino_s; // ino of file from swap file
5181 char_u buf_c[MAXPATHL]; /* full path of fname_c */ 5180 char_u buf_c[MAXPATHL]; // full path of fname_c
5182 char_u buf_s[MAXPATHL]; /* full path of fname_s */ 5181 char_u buf_s[MAXPATHL]; // full path of fname_s
5183 int retval_c; /* flag: buf_c valid */ 5182 int retval_c; // flag: buf_c valid
5184 int retval_s; /* flag: buf_s valid */ 5183 int retval_s; // flag: buf_s valid
5185 5184
5186 if (mch_stat((char *)fname_c, &st) == 0) 5185 if (mch_stat((char *)fname_c, &st) == 0)
5187 ino_c = (ino_t)st.st_ino; 5186 ino_c = (ino_t)st.st_ino;
5188 5187
5189 /* 5188 /*
5215 */ 5214 */
5216 if (ino_s == 0 && ino_c == 0 && retval_c == FAIL && retval_s == FAIL) 5215 if (ino_s == 0 && ino_c == 0 && retval_c == FAIL && retval_s == FAIL)
5217 return STRCMP(fname_c, fname_s) != 0; 5216 return STRCMP(fname_c, fname_s) != 0;
5218 return TRUE; 5217 return TRUE;
5219 } 5218 }
5220 #endif /* CHECK_INODE */ 5219 #endif // CHECK_INODE
5221 5220
5222 /* 5221 /*
5223 * Move a long integer into a four byte character array. 5222 * Move a long integer into a four byte character array.
5224 * Used for machine independency in block zero. 5223 * Used for machine independency in block zero.
5225 */ 5224 */
5313 return NULL; 5312 return NULL;
5314 head_end = (char_u *)(&dp->db_index[dp->db_line_count]); 5313 head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
5315 text_start = (char_u *)dp + dp->db_txt_start; 5314 text_start = (char_u *)dp + dp->db_txt_start;
5316 text_len = size - dp->db_txt_start; 5315 text_len = size - dp->db_txt_start;
5317 5316
5318 /* Copy the header and the text. */ 5317 // Copy the header and the text.
5319 mch_memmove(new_data, dp, head_end - (char_u *)dp); 5318 mch_memmove(new_data, dp, head_end - (char_u *)dp);
5320 5319
5321 /* Encrypt the text. */ 5320 // Encrypt the text.
5322 crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start); 5321 crypt_encode(state, text_start, text_len, new_data + dp->db_txt_start);
5323 crypt_free_state(state); 5322 crypt_free_state(state);
5324 5323
5325 /* Clear the gap. */ 5324 // Clear the gap.
5326 if (head_end < text_start) 5325 if (head_end < text_start)
5327 vim_memset(new_data + (head_end - data), 0, text_start - head_end); 5326 vim_memset(new_data + (head_end - data), 0, text_start - head_end);
5328 5327
5329 return new_data; 5328 return new_data;
5330 } 5329 }
5351 text_start = (char_u *)dp + dp->db_txt_start; 5350 text_start = (char_u *)dp + dp->db_txt_start;
5352 text_len = dp->db_txt_end - dp->db_txt_start; 5351 text_len = dp->db_txt_end - dp->db_txt_start;
5353 5352
5354 if (head_end > text_start || dp->db_txt_start > size 5353 if (head_end > text_start || dp->db_txt_start > size
5355 || dp->db_txt_end > size) 5354 || dp->db_txt_end > size)
5356 return; /* data was messed up */ 5355 return; // data was messed up
5357 5356
5358 state = ml_crypt_prepare(mfp, offset, TRUE); 5357 state = ml_crypt_prepare(mfp, offset, TRUE);
5359 if (state != NULL) 5358 if (state != NULL)
5360 { 5359 {
5361 /* Decrypt the text in place. */ 5360 // Decrypt the text in place.
5362 crypt_decode_inplace(state, text_start, text_len); 5361 crypt_decode_inplace(state, text_start, text_len);
5363 crypt_free_state(state); 5362 crypt_free_state(state);
5364 } 5363 }
5365 } 5364 }
5366 } 5365 }
5378 char_u *key; 5377 char_u *key;
5379 char_u *seed; 5378 char_u *seed;
5380 5379
5381 if (reading && mfp->mf_old_key != NULL) 5380 if (reading && mfp->mf_old_key != NULL)
5382 { 5381 {
5383 /* Reading back blocks with the previous key/method/seed. */ 5382 // Reading back blocks with the previous key/method/seed.
5384 method_nr = mfp->mf_old_cm; 5383 method_nr = mfp->mf_old_cm;
5385 key = mfp->mf_old_key; 5384 key = mfp->mf_old_key;
5386 seed = mfp->mf_old_seed; 5385 seed = mfp->mf_old_seed;
5387 } 5386 }
5388 else 5387 else
5394 if (*key == NUL) 5393 if (*key == NUL)
5395 return NULL; 5394 return NULL;
5396 5395
5397 if (method_nr == CRYPT_M_ZIP) 5396 if (method_nr == CRYPT_M_ZIP)
5398 { 5397 {
5399 /* For PKzip: Append the offset to the key, so that we use a different 5398 // For PKzip: Append the offset to the key, so that we use a different
5400 * key for every block. */ 5399 // key for every block.
5401 vim_snprintf((char *)salt, sizeof(salt), "%s%ld", key, (long)offset); 5400 vim_snprintf((char *)salt, sizeof(salt), "%s%ld", key, (long)offset);
5402 return crypt_create(method_nr, salt, NULL, 0, NULL, 0); 5401 return crypt_create(method_nr, salt, NULL, 0, NULL, 0);
5403 } 5402 }
5404 5403
5405 /* Using blowfish or better: add salt and seed. We use the byte offset 5404 // Using blowfish or better: add salt and seed. We use the byte offset
5406 * of the block for the salt. */ 5405 // of the block for the salt.
5407 vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset); 5406 vim_snprintf((char *)salt, sizeof(salt), "%ld", (long)offset);
5408 return crypt_create(method_nr, key, salt, (int)STRLEN(salt), 5407 return crypt_create(method_nr, key, salt, (int)STRLEN(salt),
5409 seed, MF_SEED_LEN); 5408 seed, MF_SEED_LEN);
5410 } 5409 }
5411 5410
5412 #endif 5411 #endif
5413 5412
5414 5413
5415 #if defined(FEAT_BYTEOFF) || defined(PROTO) 5414 #if defined(FEAT_BYTEOFF) || defined(PROTO)
5416 5415
5417 #define MLCS_MAXL 800 /* max no of lines in chunk */ 5416 #define MLCS_MAXL 800 // max no of lines in chunk
5418 #define MLCS_MINL 400 /* should be half of MLCS_MAXL */ 5417 #define MLCS_MINL 400 // should be half of MLCS_MAXL
5419 5418
5420 /* 5419 /*
5421 * Keep information for finding byte offset of a line, updtype may be one of: 5420 * Keep information for finding byte offset of a line, updtype may be one of:
5422 * ML_CHNK_ADDLINE: Add len to parent chunk, possibly splitting it 5421 * ML_CHNK_ADDLINE: Add len to parent chunk, possibly splitting it
5423 * Careful: ML_CHNK_ADDLINE may cause ml_find_line() to be called. 5422 * Careful: ML_CHNK_ADDLINE may cause ml_find_line() to be called.
5485 curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; 5484 curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
5486 } 5485 }
5487 else if (curix < buf->b_ml.ml_usedchunks - 1 5486 else if (curix < buf->b_ml.ml_usedchunks - 1
5488 && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) 5487 && line >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines)
5489 { 5488 {
5490 /* Adjust cached curix & curline */ 5489 // Adjust cached curix & curline
5491 curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; 5490 curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines;
5492 curix++; 5491 curix++;
5493 } 5492 }
5494 curchnk = buf->b_ml.ml_chunksize + curix; 5493 curchnk = buf->b_ml.ml_chunksize + curix;
5495 5494
5498 curchnk->mlcs_totalsize += len; 5497 curchnk->mlcs_totalsize += len;
5499 if (updtype == ML_CHNK_ADDLINE) 5498 if (updtype == ML_CHNK_ADDLINE)
5500 { 5499 {
5501 curchnk->mlcs_numlines++; 5500 curchnk->mlcs_numlines++;
5502 5501
5503 /* May resize here so we don't have to do it in both cases below */ 5502 // May resize here so we don't have to do it in both cases below
5504 if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) 5503 if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks)
5505 { 5504 {
5506 chunksize_T *t_chunksize = buf->b_ml.ml_chunksize; 5505 chunksize_T *t_chunksize = buf->b_ml.ml_chunksize;
5507 5506
5508 buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2; 5507 buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2;
5509 buf->b_ml.ml_chunksize = (chunksize_T *) 5508 buf->b_ml.ml_chunksize = (chunksize_T *)
5510 vim_realloc(buf->b_ml.ml_chunksize, 5509 vim_realloc(buf->b_ml.ml_chunksize,
5511 sizeof(chunksize_T) * buf->b_ml.ml_numchunks); 5510 sizeof(chunksize_T) * buf->b_ml.ml_numchunks);
5512 if (buf->b_ml.ml_chunksize == NULL) 5511 if (buf->b_ml.ml_chunksize == NULL)
5513 { 5512 {
5514 /* Hmmmm, Give up on offset for this buffer */ 5513 // Hmmmm, Give up on offset for this buffer
5515 vim_free(t_chunksize); 5514 vim_free(t_chunksize);
5516 buf->b_ml.ml_usedchunks = -1; 5515 buf->b_ml.ml_usedchunks = -1;
5517 return; 5516 return;
5518 } 5517 }
5519 } 5518 }
5520 5519
5521 if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) 5520 if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL)
5522 { 5521 {
5523 int count; /* number of entries in block */ 5522 int count; // number of entries in block
5524 int idx; 5523 int idx;
5525 int end_idx; 5524 int end_idx;
5526 int text_end; 5525 int text_end;
5527 int linecnt; 5526 int linecnt;
5528 5527
5529 mch_memmove(buf->b_ml.ml_chunksize + curix + 1, 5528 mch_memmove(buf->b_ml.ml_chunksize + curix + 1,
5530 buf->b_ml.ml_chunksize + curix, 5529 buf->b_ml.ml_chunksize + curix,
5531 (buf->b_ml.ml_usedchunks - curix) * 5530 (buf->b_ml.ml_usedchunks - curix) *
5532 sizeof(chunksize_T)); 5531 sizeof(chunksize_T));
5533 /* Compute length of first half of lines in the split chunk */ 5532 // Compute length of first half of lines in the split chunk
5534 size = 0; 5533 size = 0;
5535 linecnt = 0; 5534 linecnt = 0;
5536 while (curline < buf->b_ml.ml_line_count 5535 while (curline < buf->b_ml.ml_line_count
5537 && linecnt < MLCS_MINL) 5536 && linecnt < MLCS_MINL)
5538 { 5537 {
5571 size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & DB_INDEX_MASK)) + 1; 5570 size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & DB_INDEX_MASK)) + 1;
5572 } 5571 }
5573 else 5572 else
5574 #endif 5573 #endif
5575 { 5574 {
5576 if (idx == 0)/* first line in block, text at the end */ 5575 if (idx == 0)// first line in block, text at the end
5577 text_end = dp->db_txt_end; 5576 text_end = dp->db_txt_end;
5578 else 5577 else
5579 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); 5578 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
5580 size += text_end - ((dp->db_index[end_idx]) & DB_INDEX_MASK); 5579 size += text_end - ((dp->db_index[end_idx]) & DB_INDEX_MASK);
5581 } 5580 }
5583 buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt; 5582 buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt;
5584 buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt; 5583 buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt;
5585 buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size; 5584 buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size;
5586 buf->b_ml.ml_chunksize[curix + 1].mlcs_totalsize -= size; 5585 buf->b_ml.ml_chunksize[curix + 1].mlcs_totalsize -= size;
5587 buf->b_ml.ml_usedchunks++; 5586 buf->b_ml.ml_usedchunks++;
5588 ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */ 5587 ml_upd_lastbuf = NULL; // Force recalc of curix & curline
5589 return; 5588 return;
5590 } 5589 }
5591 else if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MINL 5590 else if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MINL
5592 && curix == buf->b_ml.ml_usedchunks - 1 5591 && curix == buf->b_ml.ml_usedchunks - 1
5593 && buf->b_ml.ml_line_count - line <= 1) 5592 && buf->b_ml.ml_line_count - line <= 1)
5630 } 5629 }
5631 } 5630 }
5632 else if (updtype == ML_CHNK_DELLINE) 5631 else if (updtype == ML_CHNK_DELLINE)
5633 { 5632 {
5634 curchnk->mlcs_numlines--; 5633 curchnk->mlcs_numlines--;
5635 ml_upd_lastbuf = NULL; /* Force recalc of curix & curline */ 5634 ml_upd_lastbuf = NULL; // Force recalc of curix & curline
5636 if (curix < (buf->b_ml.ml_usedchunks - 1) 5635 if (curix < (buf->b_ml.ml_usedchunks - 1)
5637 && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines) 5636 && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines)
5638 <= MLCS_MINL) 5637 <= MLCS_MINL)
5639 { 5638 {
5640 curix++; 5639 curix++;
5652 > MLCS_MINL)) 5651 > MLCS_MINL))
5653 { 5652 {
5654 return; 5653 return;
5655 } 5654 }
5656 5655
5657 /* Collapse chunks */ 5656 // Collapse chunks
5658 curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines; 5657 curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines;
5659 curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize; 5658 curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize;
5660 buf->b_ml.ml_usedchunks--; 5659 buf->b_ml.ml_usedchunks--;
5661 if (curix < buf->b_ml.ml_usedchunks) 5660 if (curix < buf->b_ml.ml_usedchunks)
5662 { 5661 {
5685 linenr_T curline; 5684 linenr_T curline;
5686 int curix; 5685 int curix;
5687 long size; 5686 long size;
5688 bhdr_T *hp; 5687 bhdr_T *hp;
5689 DATA_BL *dp; 5688 DATA_BL *dp;
5690 int count; /* number of entries in block */ 5689 int count; // number of entries in block
5691 int idx; 5690 int idx;
5692 int start_idx; 5691 int start_idx;
5693 int text_end; 5692 int text_end;
5694 long offset; 5693 long offset;
5695 int len; 5694 int len;
5696 int ffdos = (get_fileformat(buf) == EOL_DOS); 5695 int ffdos = (get_fileformat(buf) == EOL_DOS);
5697 int extra = 0; 5696 int extra = 0;
5698 5697
5699 /* take care of cached line first */ 5698 // take care of cached line first
5700 ml_flush_line(curbuf); 5699 ml_flush_line(curbuf);
5701 5700
5702 if (buf->b_ml.ml_usedchunks == -1 5701 if (buf->b_ml.ml_usedchunks == -1
5703 || buf->b_ml.ml_chunksize == NULL 5702 || buf->b_ml.ml_chunksize == NULL
5704 || lnum < 0) 5703 || lnum < 0)
5707 if (offp == NULL) 5706 if (offp == NULL)
5708 offset = 0; 5707 offset = 0;
5709 else 5708 else
5710 offset = *offp; 5709 offset = *offp;
5711 if (lnum == 0 && offset <= 0) 5710 if (lnum == 0 && offset <= 0)
5712 return 1; /* Not a "find offset" and offset 0 _must_ be in line 1 */ 5711 return 1; // Not a "find offset" and offset 0 _must_ be in line 1
5713 /* 5712 /*
5714 * Find the last chunk before the one containing our line. Last chunk is 5713 * Find the last chunk before the one containing our line. Last chunk is
5715 * special because it will never qualify 5714 * special because it will never qualify
5716 */ 5715 */
5717 curline = 1; 5716 curline = 1;
5737 return -1; 5736 return -1;
5738 dp = (DATA_BL *)(hp->bh_data); 5737 dp = (DATA_BL *)(hp->bh_data);
5739 count = (long)(buf->b_ml.ml_locked_high) - 5738 count = (long)(buf->b_ml.ml_locked_high) -
5740 (long)(buf->b_ml.ml_locked_low) + 1; 5739 (long)(buf->b_ml.ml_locked_low) + 1;
5741 start_idx = idx = curline - buf->b_ml.ml_locked_low; 5740 start_idx = idx = curline - buf->b_ml.ml_locked_low;
5742 if (idx == 0)/* first line in block, text at the end */ 5741 if (idx == 0)// first line in block, text at the end
5743 text_end = dp->db_txt_end; 5742 text_end = dp->db_txt_end;
5744 else 5743 else
5745 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); 5744 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
5746 /* Compute index of last line to use in this MEMLINE */ 5745 // Compute index of last line to use in this MEMLINE
5747 if (lnum != 0) 5746 if (lnum != 0)
5748 { 5747 {
5749 if (curline + (count - idx) >= lnum) 5748 if (curline + (count - idx) >= lnum)
5750 idx += lnum - curline - 1; 5749 idx += lnum - curline - 1;
5751 else 5750 else
5792 else 5791 else
5793 *offp = offset - size + len 5792 *offp = offset - size + len
5794 - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); 5793 - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
5795 curline += idx - start_idx + extra; 5794 curline += idx - start_idx + extra;
5796 if (curline > buf->b_ml.ml_line_count) 5795 if (curline > buf->b_ml.ml_line_count)
5797 return -1; /* exactly one byte beyond the end */ 5796 return -1; // exactly one byte beyond the end
5798 return curline; 5797 return curline;
5799 } 5798 }
5800 curline = buf->b_ml.ml_locked_high + 1; 5799 curline = buf->b_ml.ml_locked_high + 1;
5801 } 5800 }
5802 5801
5803 if (lnum != 0) 5802 if (lnum != 0)
5804 { 5803 {
5805 /* Count extra CR characters. */ 5804 // Count extra CR characters.
5806 if (ffdos) 5805 if (ffdos)
5807 size += lnum - 1; 5806 size += lnum - 1;
5808 5807
5809 /* Don't count the last line break if 'noeol' and ('bin' or 5808 // Don't count the last line break if 'noeol' and ('bin' or
5810 * 'nofixeol'). */ 5809 // 'nofixeol').
5811 if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol 5810 if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol
5812 && lnum > buf->b_ml.ml_line_count) 5811 && lnum > buf->b_ml.ml_line_count)
5813 size -= ffdos + 1; 5812 size -= ffdos + 1;
5814 } 5813 }
5815 5814
5823 goto_byte(long cnt) 5822 goto_byte(long cnt)
5824 { 5823 {
5825 long boff = cnt; 5824 long boff = cnt;
5826 linenr_T lnum; 5825 linenr_T lnum;
5827 5826
5828 ml_flush_line(curbuf); /* cached line may be dirty */ 5827 ml_flush_line(curbuf); // cached line may be dirty
5829 setpcmark(); 5828 setpcmark();
5830 if (boff) 5829 if (boff)
5831 --boff; 5830 --boff;
5832 lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff); 5831 lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff);
5833 if (lnum < 1) /* past the end */ 5832 if (lnum < 1) // past the end
5834 { 5833 {
5835 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; 5834 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
5836 curwin->w_curswant = MAXCOL; 5835 curwin->w_curswant = MAXCOL;
5837 coladvance((colnr_T)MAXCOL); 5836 coladvance((colnr_T)MAXCOL);
5838 } 5837 }
5843 curwin->w_cursor.coladd = 0; 5842 curwin->w_cursor.coladd = 0;
5844 curwin->w_set_curswant = TRUE; 5843 curwin->w_set_curswant = TRUE;
5845 } 5844 }
5846 check_cursor(); 5845 check_cursor();
5847 5846
5848 /* Make sure the cursor is on the first byte of a multi-byte char. */ 5847 // Make sure the cursor is on the first byte of a multi-byte char.
5849 if (has_mbyte) 5848 if (has_mbyte)
5850 mb_adjust_cursor(); 5849 mb_adjust_cursor();
5851 } 5850 }
5852 #endif 5851 #endif