This commit is contained in:
Jan Edmund Lazo
2019-04-30 03:57:24 -04:00
parent c3edbf813a
commit 0e7048ae05
11 changed files with 173 additions and 168 deletions

View File

@@ -855,7 +855,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
return FAIL; return FAIL;
for (extra = 0, l = line1; l <= line2; l++) { for (extra = 0, l = line1; l <= line2; l++) {
str = vim_strsave(ml_get(l + extra)); str = vim_strsave(ml_get(l + extra));
ml_append(dest + l - line1, str, (colnr_T)0, FALSE); ml_append(dest + l - line1, str, (colnr_T)0, false);
xfree(str); xfree(str);
if (dest < line1) if (dest < line1)
extra++; extra++;
@@ -914,9 +914,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL)
return FAIL; return FAIL;
for (l = line1; l <= line2; l++) for (l = line1; l <= line2; l++) {
ml_delete(line1 + extra, TRUE); ml_delete(line1 + extra, true);
}
if (!global_busy && num_lines > p_report) { if (!global_busy && num_lines > p_report) {
if (num_lines == 1) if (num_lines == 1)
MSG(_("1 line moved")); MSG(_("1 line moved"));
@@ -982,7 +982,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
/* need to use vim_strsave() because the line will be unlocked within /* need to use vim_strsave() because the line will be unlocked within
* ml_append() */ * ml_append() */
p = vim_strsave(ml_get(line1)); p = vim_strsave(ml_get(line1));
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false);
xfree(p); xfree(p);
/* situation 2: skip already copied lines */ /* situation 2: skip already copied lines */
@@ -2720,7 +2720,7 @@ static int append_indent = 0; /* autoindent for first line */
void ex_append(exarg_T *eap) void ex_append(exarg_T *eap)
{ {
char_u *theline; char_u *theline;
int did_undo = FALSE; bool did_undo = false;
linenr_T lnum = eap->line2; linenr_T lnum = eap->line2;
int indent = 0; int indent = 0;
char_u *p; char_u *p;
@@ -2808,16 +2808,16 @@ void ex_append(exarg_T *eap)
if (p[0] == NUL) if (p[0] == NUL)
theline[0] = NUL; theline[0] = NUL;
did_undo = TRUE; did_undo = true;
ml_append(lnum, theline, (colnr_T)0, FALSE); ml_append(lnum, theline, (colnr_T)0, false);
appended_lines_mark(lnum + (empty ? 1 : 0), 1L); appended_lines_mark(lnum + (empty ? 1 : 0), 1L);
xfree(theline); xfree(theline);
++lnum; ++lnum;
if (empty) { if (empty) {
ml_delete(2L, FALSE); ml_delete(2L, false);
empty = FALSE; empty = 0;
} }
} }
State = NORMAL; State = NORMAL;
@@ -2862,7 +2862,7 @@ void ex_change(exarg_T *eap)
for (lnum = eap->line2; lnum >= eap->line1; --lnum) { for (lnum = eap->line2; lnum >= eap->line1; --lnum) {
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */
break; break;
ml_delete(eap->line1, FALSE); ml_delete(eap->line1, false);
} }
/* make sure the cursor is not beyond the end of the file now */ /* make sure the cursor is not beyond the end of the file now */
@@ -3989,8 +3989,9 @@ skip:
++lnum; ++lnum;
if (u_savedel(lnum, nmatch_tl) != OK) if (u_savedel(lnum, nmatch_tl) != OK)
break; break;
for (i = 0; i < nmatch_tl; ++i) for (i = 0; i < nmatch_tl; i++) {
ml_delete(lnum, (int)FALSE); ml_delete(lnum, false);
}
mark_adjust(lnum, lnum + nmatch_tl - 1, mark_adjust(lnum, lnum + nmatch_tl - 1,
(long)MAXLNUM, -nmatch_tl, false); (long)MAXLNUM, -nmatch_tl, false);
if (subflags.do_ask) { if (subflags.do_ask) {
@@ -5154,10 +5155,11 @@ void fix_help_buffer(void)
} }
convert_setup(&vc, NULL, NULL); convert_setup(&vc, NULL, NULL);
ml_append(lnum, cp, (colnr_T)0, FALSE); ml_append(lnum, cp, (colnr_T)0, false);
if (cp != IObuff) if (cp != IObuff) {
xfree(cp); xfree(cp);
++lnum; }
lnum++;
} }
fclose(fd); fclose(fd);
} }

View File

@@ -7213,10 +7213,11 @@ static void ex_read(exarg_T *eap)
else else
lnum = 1; lnum = 1;
if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) { if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) {
ml_delete(lnum, FALSE); ml_delete(lnum, false);
if (curwin->w_cursor.lnum > 1 if (curwin->w_cursor.lnum > 1
&& curwin->w_cursor.lnum >= lnum) && curwin->w_cursor.lnum >= lnum) {
--curwin->w_cursor.lnum; curwin->w_cursor.lnum--;
}
deleted_lines_mark(lnum, 1L); deleted_lines_mark(lnum, 1L);
} }
} }

View File

@@ -6110,9 +6110,9 @@ static int open_cmdwin(void)
do { do {
if (++i == hislen) if (++i == hislen)
i = 0; i = 0;
if (history[histtype][i].hisstr != NULL) if (history[histtype][i].hisstr != NULL) {
ml_append(lnum++, history[histtype][i].hisstr, ml_append(lnum++, history[histtype][i].hisstr, (colnr_T)0, false);
(colnr_T)0, FALSE); }
} while (i != hisidx[histtype]); } while (i != hisidx[histtype]);
} }
} }

View File

@@ -308,8 +308,8 @@ readfile (
#ifdef UNIX #ifdef UNIX
int swap_mode = -1; /* protection bits for swap file */ int swap_mode = -1; /* protection bits for swap file */
#endif #endif
int fileformat = 0; /* end-of-line format */ int fileformat = 0; // end-of-line format
int keep_fileformat = FALSE; bool keep_fileformat = false;
FileInfo file_info; FileInfo file_info;
int file_readonly; int file_readonly;
linenr_T skip_count = 0; linenr_T skip_count = 0;
@@ -317,21 +317,21 @@ readfile (
int msg_save = msg_scroll; int msg_save = msg_scroll;
linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of
// last read was missing the eol // last read was missing the eol
int file_rewind = false; bool file_rewind = false;
int can_retry; int can_retry;
linenr_T conv_error = 0; /* line nr with conversion error */ linenr_T conv_error = 0; // line nr with conversion error
linenr_T illegal_byte = 0; /* line nr with illegal byte */ linenr_T illegal_byte = 0; // line nr with illegal byte
int keep_dest_enc = FALSE; /* don't retry when char doesn't fit bool keep_dest_enc = false; // don't retry when char doesn't fit
in destination encoding */ // in destination encoding
int bad_char_behavior = BAD_REPLACE; int bad_char_behavior = BAD_REPLACE;
/* BAD_KEEP, BAD_DROP or character to /* BAD_KEEP, BAD_DROP or character to
* replace with */ * replace with */
char_u *tmpname = NULL; /* name of 'charconvert' output file */ char_u *tmpname = NULL; /* name of 'charconvert' output file */
int fio_flags = 0; int fio_flags = 0;
char_u *fenc; /* fileencoding to use */ char_u *fenc; // fileencoding to use
int fenc_alloced; /* fenc_next is in allocated memory */ bool fenc_alloced; // fenc_next is in allocated memory
char_u *fenc_next = NULL; /* next item in 'fencs' or NULL */ char_u *fenc_next = NULL; // next item in 'fencs' or NULL
int advance_fenc = FALSE; bool advance_fenc = false;
long real_size = 0; long real_size = 0;
# ifdef USE_ICONV # ifdef USE_ICONV
iconv_t iconv_fd = (iconv_t)-1; /* descriptor for iconv() or -1 */ iconv_t iconv_fd = (iconv_t)-1; /* descriptor for iconv() or -1 */
@@ -764,11 +764,11 @@ readfile (
*/ */
if (eap != NULL && eap->force_enc != 0) { if (eap != NULL && eap->force_enc != 0) {
fenc = enc_canonize(eap->cmd + eap->force_enc); fenc = enc_canonize(eap->cmd + eap->force_enc);
fenc_alloced = TRUE; fenc_alloced = true;
keep_dest_enc = TRUE; keep_dest_enc = true;
} else if (curbuf->b_p_bin) { } else if (curbuf->b_p_bin) {
fenc = (char_u *)""; /* binary: don't convert */ fenc = (char_u *)""; // binary: don't convert
fenc_alloced = FALSE; fenc_alloced = false;
} else if (curbuf->b_help) { } else if (curbuf->b_help) {
// Help files are either utf-8 or latin1. Try utf-8 first, if this // Help files are either utf-8 or latin1. Try utf-8 first, if this
// fails it must be latin1. // fails it must be latin1.
@@ -779,12 +779,12 @@ readfile (
fenc_alloced = false; fenc_alloced = false;
} else if (*p_fencs == NUL) { } else if (*p_fencs == NUL) {
fenc = curbuf->b_p_fenc; /* use format from buffer */ fenc = curbuf->b_p_fenc; // use format from buffer
fenc_alloced = FALSE; fenc_alloced = false;
} else { } else {
fenc_next = p_fencs; /* try items in 'fileencodings' */ fenc_next = p_fencs; /* try items in 'fileencodings' */
fenc = next_fenc(&fenc_next); fenc = next_fenc(&fenc_next);
fenc_alloced = TRUE; fenc_alloced = true;
} }
/* /*
@@ -817,10 +817,11 @@ retry:
error = true; error = true;
goto failed; goto failed;
} }
/* Delete the previously read lines. */ // Delete the previously read lines.
while (lnum > from) while (lnum > from) {
ml_delete(lnum--, FALSE); ml_delete(lnum--, false);
file_rewind = FALSE; }
file_rewind = false;
if (set_options) { if (set_options) {
curbuf->b_p_bomb = FALSE; curbuf->b_p_bomb = FALSE;
curbuf->b_start_bomb = FALSE; curbuf->b_start_bomb = FALSE;
@@ -832,9 +833,9 @@ retry:
* When retrying with another "fenc" and the first time "fileformat" * When retrying with another "fenc" and the first time "fileformat"
* will be reset. * will be reset.
*/ */
if (keep_fileformat) if (keep_fileformat) {
keep_fileformat = FALSE; keep_fileformat = false;
else { } else {
if (eap != NULL && eap->force_ff != 0) { if (eap != NULL && eap->force_ff != 0) {
fileformat = get_fileformat_force(curbuf, eap); fileformat = get_fileformat_force(curbuf, eap);
try_unix = try_dos = try_mac = FALSE; try_unix = try_dos = try_mac = FALSE;
@@ -858,7 +859,7 @@ retry:
/* /*
* Try the next entry in 'fileencodings'. * Try the next entry in 'fileencodings'.
*/ */
advance_fenc = FALSE; advance_fenc = false;
if (eap != NULL && eap->force_enc != 0) { if (eap != NULL && eap->force_enc != 0) {
/* Conversion given with "++cc=" wasn't possible, read /* Conversion given with "++cc=" wasn't possible, read
@@ -868,7 +869,7 @@ retry:
if (fenc_alloced) if (fenc_alloced)
xfree(fenc); xfree(fenc);
fenc = (char_u *)""; fenc = (char_u *)"";
fenc_alloced = FALSE; fenc_alloced = false;
} else { } else {
if (fenc_alloced) if (fenc_alloced)
xfree(fenc); xfree(fenc);
@@ -877,7 +878,7 @@ retry:
fenc_alloced = (fenc_next != NULL); fenc_alloced = (fenc_next != NULL);
} else { } else {
fenc = (char_u *)""; fenc = (char_u *)"";
fenc_alloced = FALSE; fenc_alloced = false;
} }
} }
if (tmpname != NULL) { if (tmpname != NULL) {
@@ -943,8 +944,8 @@ retry:
if (tmpname == NULL) { if (tmpname == NULL) {
tmpname = readfile_charconvert(fname, fenc, &fd); tmpname = readfile_charconvert(fname, fenc, &fd);
if (tmpname == NULL) { if (tmpname == NULL) {
/* Conversion failed. Try another one. */ // Conversion failed. Try another one.
advance_fenc = TRUE; advance_fenc = true;
if (fd < 0) { if (fd < 0) {
/* Re-opening the original file failed! */ /* Re-opening the original file failed! */
EMSG(_("E202: Conversion made file unreadable!")); EMSG(_("E202: Conversion made file unreadable!"));
@@ -962,7 +963,7 @@ retry:
) { ) {
/* Conversion wanted but we can't. /* Conversion wanted but we can't.
* Try the next conversion in 'fileencodings' */ * Try the next conversion in 'fileencodings' */
advance_fenc = TRUE; advance_fenc = true;
goto retry; goto retry;
} }
} }
@@ -1197,14 +1198,14 @@ retry:
if (fio_flags == FIO_UCSBOM) { if (fio_flags == FIO_UCSBOM) {
if (ccname == NULL) { if (ccname == NULL) {
/* No BOM detected: retry with next encoding. */ // No BOM detected: retry with next encoding.
advance_fenc = TRUE; advance_fenc = true;
} else { } else {
/* BOM detected: set "fenc" and jump back */ /* BOM detected: set "fenc" and jump back */
if (fenc_alloced) if (fenc_alloced)
xfree(fenc); xfree(fenc);
fenc = ccname; fenc = ccname;
fenc_alloced = FALSE; fenc_alloced = false;
} }
/* retry reading without getting new bytes or rewinding */ /* retry reading without getting new bytes or rewinding */
skip_read = TRUE; skip_read = TRUE;
@@ -1529,9 +1530,9 @@ rewind_retry:
did_iconv = TRUE; did_iconv = TRUE;
else else
# endif # endif
/* use next item from 'fileencodings' */ // use next item from 'fileencodings'
advance_fenc = TRUE; advance_fenc = true;
file_rewind = TRUE; file_rewind = true;
goto retry; goto retry;
} }
} }
@@ -1665,8 +1666,8 @@ rewind_retry:
fileformat = EOL_UNIX; fileformat = EOL_UNIX;
if (set_options) if (set_options)
set_fileformat(EOL_UNIX, OPT_LOCAL); set_fileformat(EOL_UNIX, OPT_LOCAL);
file_rewind = TRUE; file_rewind = true;
keep_fileformat = TRUE; keep_fileformat = true;
goto retry; goto retry;
} }
ff_error = EOL_DOS; ff_error = EOL_DOS;
@@ -1777,8 +1778,8 @@ failed:
if (!recoverymode) { if (!recoverymode) {
/* need to delete the last line, which comes from the empty buffer */ /* need to delete the last line, which comes from the empty buffer */
if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) { if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete(curbuf->b_ml.ml_line_count, FALSE); ml_delete(curbuf->b_ml.ml_line_count, false);
--linecnt; linecnt--;
} }
linecnt = curbuf->b_ml.ml_line_count - linecnt; linecnt = curbuf->b_ml.ml_line_count - linecnt;
if (filesize == 0) if (filesize == 0)
@@ -4911,9 +4912,9 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
/* Copy the lines in "frombuf" to "tobuf". */ /* Copy the lines in "frombuf" to "tobuf". */
curbuf = tobuf; curbuf = tobuf;
for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; lnum++) {
p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); p = vim_strsave(ml_get_buf(frombuf, lnum, false));
if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) { if (ml_append(lnum - 1, p, 0, false) == FAIL) {
xfree(p); xfree(p);
retval = FAIL; retval = FAIL;
break; break;
@@ -4924,14 +4925,15 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
/* Delete all the lines in "frombuf". */ /* Delete all the lines in "frombuf". */
if (retval != FAIL) { if (retval != FAIL) {
curbuf = frombuf; curbuf = frombuf;
for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum) for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; lnum--) {
if (ml_delete(lnum, FALSE) == FAIL) { if (ml_delete(lnum, false) == FAIL) {
/* Oops! We could try putting back the saved lines, but that // Oops! We could try putting back the saved lines, but that
* might fail again... */ // might fail again...
retval = FAIL; retval = FAIL;
break; break;
} }
} }
}
curbuf = tbuf; curbuf = tbuf;
return retval; return retval;

View File

@@ -349,7 +349,7 @@ int ml_open(buf_T *buf)
/* /*
* Allocate first data block and create an empty line 1. * Allocate first data block and create an empty line 1.
*/ */
hp = ml_new_data(mfp, FALSE, 1); hp = ml_new_data(mfp, false, 1);
if (hp->bh_bnum != 2) { if (hp->bh_bnum != 2) {
IEMSG(_("E298: Didn't get block nr 2?")); IEMSG(_("E298: Didn't get block nr 2?"));
goto error; goto error;
@@ -764,7 +764,7 @@ void ml_recover(void)
long error; long error;
int cannot_open; int cannot_open;
linenr_T line_count; linenr_T line_count;
int has_error; bool has_error;
int idx; int idx;
int top; int top;
int txt_start; int txt_start;
@@ -984,8 +984,9 @@ void ml_recover(void)
* Now that we are sure that the file is going to be recovered, clear the * Now that we are sure that the file is going to be recovered, clear the
* contents of the current buffer. * contents of the current buffer.
*/ */
while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) {
ml_delete((linenr_T)1, FALSE); ml_delete((linenr_T)1, false);
}
/* /*
* Try reading the original file to obtain the values of 'fileformat', * Try reading the original file to obtain the values of 'fileformat',
@@ -1034,8 +1035,8 @@ void ml_recover(void)
} }
++error; ++error;
ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"), ml_append(lnum++, (char_u *)_("???MANY LINES MISSING"),
(colnr_T)0, TRUE); (colnr_T)0, true);
} else { /* there is a block */ } else { // there is a block
pp = hp->bh_data; pp = hp->bh_data;
if (pp->pb_id == PTR_ID) { /* it is a pointer block */ if (pp->pb_id == PTR_ID) { /* it is a pointer block */
/* check line count when using pointer block first time */ /* check line count when using pointer block first time */
@@ -1045,15 +1046,15 @@ void ml_recover(void)
if (line_count != 0) { if (line_count != 0) {
++error; ++error;
ml_append(lnum++, (char_u *)_("???LINE COUNT WRONG"), ml_append(lnum++, (char_u *)_("???LINE COUNT WRONG"),
(colnr_T)0, TRUE); (colnr_T)0, true);
} }
} }
if (pp->pb_count == 0) { if (pp->pb_count == 0) {
ml_append(lnum++, (char_u *)_("???EMPTY BLOCK"), ml_append(lnum++, (char_u *)_("???EMPTY BLOCK"),
(colnr_T)0, TRUE); (colnr_T)0, true);
++error; error++;
} else if (idx < (int)pp->pb_count) { /* go a block deeper */ } else if (idx < (int)pp->pb_count) { // go a block deeper
if (pp->pb_pointer[idx].pe_bnum < 0) { if (pp->pb_pointer[idx].pe_bnum < 0) {
/* /*
* Data block with negative block number. * Data block with negative block number.
@@ -1073,7 +1074,7 @@ void ml_recover(void)
if (cannot_open) { if (cannot_open) {
++error; ++error;
ml_append(lnum++, (char_u *)_("???LINES MISSING"), ml_append(lnum++, (char_u *)_("???LINES MISSING"),
(colnr_T)0, TRUE); (colnr_T)0, true);
} }
++idx; /* get same block again for next index */ ++idx; /* get same block again for next index */
continue; continue;
@@ -1103,23 +1104,21 @@ void ml_recover(void)
} }
++error; ++error;
ml_append(lnum++, (char_u *)_("???BLOCK MISSING"), ml_append(lnum++, (char_u *)_("???BLOCK MISSING"),
(colnr_T)0, TRUE); (colnr_T)0, true);
} else { } else {
/* // it is a data block
* it is a data block // Append all the lines in this block
* Append all the lines in this block has_error = false;
*/ // check length of block
has_error = FALSE; // if wrong, use length in pointer block
/*
* check length of block
* if wrong, use length in pointer block
*/
if (page_count * mfp->mf_page_size != dp->db_txt_end) { if (page_count * mfp->mf_page_size != dp->db_txt_end) {
ml_append(lnum++, ml_append(
(char_u *)_("??? from here until ???END lines may be messed up"), lnum++,
(colnr_T)0, TRUE); (char_u *)_("??? from here until ???END lines"
++error; " may be messed up"),
has_error = TRUE; (colnr_T)0, true);
error++;
has_error = true;
dp->db_txt_end = page_count * mfp->mf_page_size; dp->db_txt_end = page_count * mfp->mf_page_size;
} }
@@ -1131,12 +1130,13 @@ void ml_recover(void)
* if wrong, use count in data block * if wrong, use count in data block
*/ */
if (line_count != dp->db_line_count) { if (line_count != dp->db_line_count) {
ml_append(lnum++, ml_append(
(char_u *)_( lnum++,
"??? from here until ???END lines may have been inserted/deleted"), (char_u *)_("??? from here until ???END lines"
(colnr_T)0, TRUE); " may have been inserted/deleted"),
++error; (colnr_T)0, true);
has_error = TRUE; error++;
has_error = true;
} }
for (i = 0; i < dp->db_line_count; ++i) { for (i = 0; i < dp->db_line_count; ++i) {
@@ -1147,11 +1147,11 @@ void ml_recover(void)
++error; ++error;
} else } else
p = (char_u *)dp + txt_start; p = (char_u *)dp + txt_start;
ml_append(lnum++, p, (colnr_T)0, TRUE); ml_append(lnum++, p, (colnr_T)0, true);
}
if (has_error) {
ml_append(lnum++, (char_u *)_("???END"), (colnr_T)0, true);
} }
if (has_error)
ml_append(lnum++, (char_u *)_("???END"),
(colnr_T)0, TRUE);
} }
} }
} }
@@ -1202,7 +1202,7 @@ void ml_recover(void)
*/ */
while (curbuf->b_ml.ml_line_count > lnum while (curbuf->b_ml.ml_line_count > lnum
&& !(curbuf->b_ml.ml_flags & ML_EMPTY)) && !(curbuf->b_ml.ml_flags & ML_EMPTY))
ml_delete(curbuf->b_ml.ml_line_count, FALSE); ml_delete(curbuf->b_ml.ml_line_count, false);
curbuf->b_flags |= BF_RECOVERED; curbuf->b_flags |= BF_RECOVERED;
recoverymode = FALSE; recoverymode = FALSE;
@@ -1814,7 +1814,7 @@ char_u *
ml_get_buf ( ml_get_buf (
buf_T *buf, buf_T *buf,
linenr_T lnum, linenr_T lnum,
int will_change /* line will be changed */ bool will_change // line will be changed
) )
{ {
bhdr_T *hp; bhdr_T *hp;
@@ -1900,12 +1900,11 @@ int ml_line_alloced(void)
* *
* return FAIL for failure, OK otherwise * return FAIL for failure, OK otherwise
*/ */
int int ml_append(
ml_append ( linenr_T lnum, // append after this line (can be 0)
linenr_T lnum, /* append after this line (can be 0) */ char_u *line, // text of the new line
char_u *line, /* text of the new line */ colnr_T len, // length of new line, including NUL, or 0
colnr_T len, /* length of new line, including NUL, or 0 */ bool newfile // flag, see above
int newfile /* flag, see above */
) )
{ {
/* When starting up, we might still need to create the memfile */ /* When starting up, we might still need to create the memfile */
@@ -1921,13 +1920,12 @@ ml_append (
* Like ml_append() but for an arbitrary buffer. The buffer must already have * Like ml_append() but for an arbitrary buffer. The buffer must already have
* a memline. * a memline.
*/ */
int int ml_append_buf(
ml_append_buf (
buf_T *buf, buf_T *buf,
linenr_T lnum, /* append after this line (can be 0) */ linenr_T lnum, // append after this line (can be 0)
char_u *line, /* text of the new line */ char_u *line, // text of the new line
colnr_T len, /* length of new line, including NUL, or 0 */ colnr_T len, // length of new line, including NUL, or 0
int newfile /* flag, see above */ bool newfile // flag, see above
) )
{ {
if (buf->b_ml.ml_mfp == NULL) if (buf->b_ml.ml_mfp == NULL)
@@ -1938,14 +1936,13 @@ ml_append_buf (
return ml_append_int(buf, lnum, line, len, newfile, FALSE); return ml_append_int(buf, lnum, line, len, newfile, FALSE);
} }
static int static int ml_append_int(
ml_append_int (
buf_T *buf, buf_T *buf,
linenr_T lnum, /* append after this line (can be 0) */ linenr_T lnum, // append after this line (can be 0)
char_u *line, /* text of the new line */ char_u *line, // text of the new line
colnr_T len, /* length of line, including NUL, or 0 */ colnr_T len, // length of line, including NUL, or 0
int newfile, /* flag, see above */ bool newfile, // flag, see above
int mark /* mark the new line */ int mark // mark the new line
) )
{ {
int i; int i;
@@ -2428,13 +2425,13 @@ int ml_replace(linenr_T lnum, char_u *line, bool copy)
/// ///
/// @param message Show "--No lines in buffer--" message. /// @param message Show "--No lines in buffer--" message.
/// @return FAIL for failure, OK otherwise /// @return FAIL for failure, OK otherwise
int ml_delete(linenr_T lnum, int message) int ml_delete(linenr_T lnum, bool message)
{ {
ml_flush_line(curbuf); ml_flush_line(curbuf);
return ml_delete_int(curbuf, lnum, message); return ml_delete_int(curbuf, lnum, message);
} }
static int ml_delete_int(buf_T *buf, linenr_T lnum, int message) static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
{ {
bhdr_T *hp; bhdr_T *hp;
memfile_T *mfp; memfile_T *mfp;
@@ -2754,17 +2751,15 @@ static void ml_flush_line(buf_T *buf)
/* The else case is already covered by the insert and delete */ /* The else case is already covered by the insert and delete */
ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE); ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE);
} else { } else {
/* // Cannot do it in one data block: Delete and append.
* Cannot do it in one data block: Delete and append. // Append first, because ml_delete_int() cannot delete the
* Append first, because ml_delete_int() cannot delete the // last line in a buffer, which causes trouble for a buffer
* last line in a buffer, which causes trouble for a buffer // that has only one line.
* that has only one line. // Don't forget to copy the mark!
* Don't forget to copy the mark! // How about handling errors???
*/ (void)ml_append_int(buf, lnum, new_line, new_len, false,
/* How about handling errors??? */
(void)ml_append_int(buf, lnum, new_line, new_len, FALSE,
(dp->db_index[idx] & DB_MARKED)); (dp->db_index[idx] & DB_MARKED));
(void)ml_delete_int(buf, lnum, FALSE); (void)ml_delete_int(buf, lnum, false);
} }
} }
xfree(new_line); xfree(new_line);
@@ -2778,7 +2773,7 @@ static void ml_flush_line(buf_T *buf)
/* /*
* create a new, empty, data block * create a new, empty, data block
*/ */
static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count) static bhdr_T *ml_new_data(memfile_T *mfp, bool negative, int page_count)
{ {
assert(page_count >= 0); assert(page_count >= 0);
bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count); bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count);

View File

@@ -745,9 +745,9 @@ open_line (
if (dir == BACKWARD) if (dir == BACKWARD)
--curwin->w_cursor.lnum; --curwin->w_cursor.lnum;
if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) { if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) {
if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE) if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, false) == FAIL) {
== FAIL)
goto theend; goto theend;
}
// Postpone calling changed_lines(), because it would mess up folding // Postpone calling changed_lines(), because it would mess up folding
// with markers. // with markers.
// Skip mark_adjust when adding a line after the last one, there can't // Skip mark_adjust when adding a line after the last one, there can't
@@ -1747,8 +1747,8 @@ del_lines (
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */
break; break;
ml_delete(first, TRUE); ml_delete(first, true);
++n; n++;
/* If we delete the last line in the file, stop */ /* If we delete the last line in the file, stop */
if (first > curbuf->b_ml.ml_line_count) if (first > curbuf->b_ml.ml_line_count)

View File

@@ -3001,9 +3001,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
/* add a new line */ /* add a new line */
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"",
(colnr_T)1, FALSE) == FAIL) (colnr_T)1, false) == FAIL) {
break; break;
++nr_lines; }
nr_lines++;
} }
/* get the old line and advance to the position to insert at */ /* get the old line and advance to the position to insert at */
oldp = get_cursor_line_ptr(); oldp = get_cursor_line_ptr();
@@ -3190,8 +3191,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
newp = (char_u *) xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); newp = (char_u *) xmalloc((size_t)(STRLEN(ptr) + totlen + 1));
STRCPY(newp, y_array[y_size - 1]); STRCPY(newp, y_array[y_size - 1]);
STRCAT(newp, ptr); STRCAT(newp, ptr);
/* insert second line */ // insert second line
ml_append(lnum, newp, (colnr_T)0, FALSE); ml_append(lnum, newp, (colnr_T)0, false);
xfree(newp); xfree(newp);
oldp = ml_get(lnum); oldp = ml_get(lnum);

View File

@@ -672,7 +672,7 @@ static int pum_set_selected(int n, int repeat)
&& (curbuf->b_p_bh[0] == 'w')) { && (curbuf->b_p_bh[0] == 'w')) {
// Already a "wipeout" buffer, make it empty. // Already a "wipeout" buffer, make it empty.
while (!BUFEMPTY()) { while (!BUFEMPTY()) {
ml_delete((linenr_T)1, FALSE); ml_delete((linenr_T)1, false);
} }
} else { } else {
// Don't want to sync undo in the current buffer. // Don't want to sync undo in the current buffer.
@@ -697,11 +697,11 @@ static int pum_set_selected(int n, int repeat)
for (p = pum_array[pum_selected].pum_info; *p != NUL;) { for (p = pum_array[pum_selected].pum_info; *p != NUL;) {
e = vim_strchr(p, '\n'); e = vim_strchr(p, '\n');
if (e == NULL) { if (e == NULL) {
ml_append(lnum++, p, 0, FALSE); ml_append(lnum++, p, 0, false);
break; break;
} else { } else {
*e = NUL; *e = NUL;
ml_append(lnum++, p, (int)(e - p + 1), FALSE); ml_append(lnum++, p, (int)(e - p + 1), false);
*e = '\n'; *e = '\n';
p = e + 1; p = e + 1;
} }

View File

@@ -7100,9 +7100,9 @@ void ex_spelldump(exarg_T *eap)
spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0); spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0);
// Delete the empty line that we started with. // Delete the empty line that we started with.
if (curbuf->b_ml.ml_line_count > 1) if (curbuf->b_ml.ml_line_count > 1) {
ml_delete(curbuf->b_ml.ml_line_count, FALSE); ml_delete(curbuf->b_ml.ml_line_count, false);
}
redraw_later(NOT_VALID); redraw_later(NOT_VALID);
} }
@@ -7171,7 +7171,7 @@ spell_dump_compl (
if (do_region && region_names != NULL) { if (do_region && region_names != NULL) {
if (pat == NULL) { if (pat == NULL) {
vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names); vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names);
ml_append(lnum++, IObuff, (colnr_T)0, FALSE); ml_append(lnum++, IObuff, (colnr_T)0, false);
} }
} else } else
do_region = false; do_region = false;
@@ -7185,7 +7185,7 @@ spell_dump_compl (
if (pat == NULL) { if (pat == NULL) {
vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname); vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname);
ml_append(lnum++, IObuff, (colnr_T)0, FALSE); ml_append(lnum++, IObuff, (colnr_T)0, false);
} }
// When matching with a pattern and there are no prefixes only use // When matching with a pattern and there are no prefixes only use
@@ -7347,15 +7347,16 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int d
} }
} }
ml_append(lnum, p, (colnr_T)0, FALSE); ml_append(lnum, p, (colnr_T)0, false);
} else if (((dumpflags & DUMPFLAG_ICASE) } else if (((dumpflags & DUMPFLAG_ICASE)
? mb_strnicmp(p, pat, STRLEN(pat)) == 0 ? mb_strnicmp(p, pat, STRLEN(pat)) == 0
: STRNCMP(p, pat, STRLEN(pat)) == 0) : STRNCMP(p, pat, STRLEN(pat)) == 0)
&& ins_compl_add_infercase(p, (int)STRLEN(p), && ins_compl_add_infercase(p, (int)STRLEN(p),
p_ic, NULL, *dir, 0) == OK) p_ic, NULL, *dir, 0) == OK) {
// if dir was BACKWARD then honor it just once // if dir was BACKWARD then honor it just once
*dir = FORWARD; *dir = FORWARD;
} }
}
// For ":spelldump": Find matching prefixes for "word". Prepend each to // For ":spelldump": Find matching prefixes for "word". Prepend each to
// "word" and append a line to the buffer. // "word" and append a line to the buffer.

View File

@@ -955,9 +955,10 @@ someerror:
break; break;
} }
if (ml_append_buf(slang->sl_sugbuf, (linenr_T)wordnr, if (ml_append_buf(slang->sl_sugbuf, (linenr_T)wordnr,
ga.ga_data, ga.ga_len, TRUE) == FAIL) ga.ga_data, ga.ga_len, true) == FAIL) {
goto someerror; goto someerror;
} }
}
ga_clear(&ga); ga_clear(&ga);
// Need to put word counts in the word tries, so that we can find // Need to put word counts in the word tries, so that we can find
@@ -4920,9 +4921,10 @@ sug_filltable (
((char_u *)gap->ga_data)[gap->ga_len++] = NUL; ((char_u *)gap->ga_data)[gap->ga_len++] = NUL;
if (ml_append_buf(spin->si_spellbuf, (linenr_T)wordnr, if (ml_append_buf(spin->si_spellbuf, (linenr_T)wordnr,
gap->ga_data, gap->ga_len, TRUE) == FAIL) gap->ga_data, gap->ga_len, true) == FAIL) {
return -1; return -1;
++wordnr; }
wordnr++;
// Remove extra NUL entries, we no longer need them. We don't // Remove extra NUL entries, we no longer need them. We don't
// bother freeing the nodes, the won't be reused anyway. // bother freeing the nodes, the won't be reused anyway.

View File

@@ -2151,7 +2151,7 @@ static void u_undoredo(int undo, bool do_buf_event)
int new_flags; int new_flags;
fmark_T namedm[NMARKS]; fmark_T namedm[NMARKS];
visualinfo_T visualinfo; visualinfo_T visualinfo;
int empty_buffer; /* buffer became empty */ bool empty_buffer; // buffer became empty
u_header_T *curhead = curbuf->b_u_curhead; u_header_T *curhead = curbuf->b_u_curhead;
/* Don't want autocommands using the undo structures here, they are /* Don't want autocommands using the undo structures here, they are
@@ -2218,7 +2218,7 @@ static void u_undoredo(int undo, bool do_buf_event)
} }
} }
empty_buffer = FALSE; empty_buffer = false;
/* delete the lines between top and bot and save them in newarray */ /* delete the lines between top and bot and save them in newarray */
if (oldsize > 0) { if (oldsize > 0) {
@@ -2229,9 +2229,10 @@ static void u_undoredo(int undo, bool do_buf_event)
newarray[i] = u_save_line(lnum); newarray[i] = u_save_line(lnum);
/* remember we deleted the last line in the buffer, and a /* remember we deleted the last line in the buffer, and a
* dummy empty line will be inserted */ * dummy empty line will be inserted */
if (curbuf->b_ml.ml_line_count == 1) if (curbuf->b_ml.ml_line_count == 1) {
empty_buffer = TRUE; empty_buffer = true;
ml_delete(lnum, FALSE); }
ml_delete(lnum, false);
} }
} else } else
newarray = NULL; newarray = NULL;
@@ -2246,7 +2247,7 @@ static void u_undoredo(int undo, bool do_buf_event)
if (empty_buffer && lnum == 0) { if (empty_buffer && lnum == 0) {
ml_replace((linenr_T)1, uep->ue_array[i], true); ml_replace((linenr_T)1, uep->ue_array[i], true);
} else { } else {
ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE); ml_append(lnum, uep->ue_array[i], (colnr_T)0, false);
} }
xfree(uep->ue_array[i]); xfree(uep->ue_array[i]);
} }