mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
diff.c: change return type to bool
Co-authored-by: Wayne Rowcliffe (@war1025)
This commit is contained in:
@@ -1531,37 +1531,37 @@ int diff_check(win_T *wp, linenr_T lnum)
|
|||||||
return maxcount - dp->df_count[idx];
|
return maxcount - dp->df_count[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare two entries in diff "*dp" and return TRUE if they are equal.
|
/// Compare two entries in diff "dp" and return true if they are equal.
|
||||||
///
|
///
|
||||||
/// @param dp
|
/// @param dp diff
|
||||||
/// @param idx1 First entry in diff "*dp"
|
/// @param idx1 first entry in diff "dp"
|
||||||
/// @param idx2 Second entry in diff "*dp"
|
/// @param idx2 second entry in diff "dp"
|
||||||
///
|
///
|
||||||
/// @return return TRUE if two entires are equal.
|
/// @return true if two entires are equal.
|
||||||
static int diff_equal_entry(diff_T *dp, int idx1, int idx2)
|
static bool diff_equal_entry(diff_T *dp, int idx1, int idx2)
|
||||||
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
if (dp->df_count[idx1] != dp->df_count[idx2]) {
|
if (dp->df_count[idx1] != dp->df_count[idx2]) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diff_check_sanity(curtab, dp) == FAIL) {
|
if (diff_check_sanity(curtab, dp) == FAIL) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (int i = 0; i < dp->df_count[idx1]; i++) {
|
||||||
for (i = 0; i < dp->df_count[idx1]; ++i) {
|
|
||||||
char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1],
|
char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1],
|
||||||
dp->df_lnum[idx1] + i, FALSE));
|
dp->df_lnum[idx1] + i, false));
|
||||||
|
|
||||||
int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2],
|
int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2],
|
||||||
dp->df_lnum[idx2] + i, FALSE));
|
dp->df_lnum[idx2] + i, false));
|
||||||
xfree(line);
|
xfree(line);
|
||||||
|
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare strings "s1" and "s2" according to 'diffopt'.
|
/// Compare strings "s1" and "s2" according to 'diffopt'.
|
||||||
@@ -1830,28 +1830,30 @@ int diffopt_changed(void)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return TRUE if 'diffopt' contains "horizontal".
|
/// Check that "diffopt" contains "horizontal".
|
||||||
///
|
bool diffopt_horizontal(void)
|
||||||
/// @return TRUE if 'diffopt' contains "horizontal"
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
int diffopt_horizontal(void)
|
|
||||||
{
|
{
|
||||||
return (diff_flags & DIFF_HORIZONTAL) != 0;
|
return (diff_flags & DIFF_HORIZONTAL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the difference within a changed line.
|
/// Find the difference within a changed line.
|
||||||
///
|
///
|
||||||
/// @param startp first char of the change
|
/// @param wp window whose current buffer to check
|
||||||
/// @param endp last char of the change
|
/// @param lnum line number to check within the buffer
|
||||||
|
/// @param startp first char of the change
|
||||||
|
/// @param endp last char of the change
|
||||||
///
|
///
|
||||||
/// @returns TRUE if the line was added, no other buffer has it.
|
/// @return true if the line was added, no other buffer has it.
|
||||||
int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
||||||
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
char_u *line_new;
|
char_u *line_new;
|
||||||
int si_org;
|
int si_org;
|
||||||
int si_new;
|
int si_new;
|
||||||
int ei_org;
|
int ei_org;
|
||||||
int ei_new;
|
int ei_new;
|
||||||
int added = TRUE;
|
bool added = true;
|
||||||
|
|
||||||
// Make a copy of the line, the next ml_get() will invalidate it.
|
// Make a copy of the line, the next ml_get() will invalidate it.
|
||||||
char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE));
|
char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE));
|
||||||
@@ -1860,7 +1862,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
if (idx == DB_COUNT) {
|
if (idx == DB_COUNT) {
|
||||||
// cannot happen
|
// cannot happen
|
||||||
xfree(line_org);
|
xfree(line_org);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search for a change that includes "lnum" in the list of diffblocks.
|
// search for a change that includes "lnum" in the list of diffblocks.
|
||||||
@@ -1873,7 +1875,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
|
|
||||||
if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) {
|
if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) {
|
||||||
xfree(line_org);
|
xfree(line_org);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int off = lnum - dp->df_lnum[idx];
|
int off = lnum - dp->df_lnum[idx];
|
||||||
@@ -1884,7 +1886,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
if (off >= dp->df_count[i]) {
|
if (off >= dp->df_count[i]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
added = FALSE;
|
added = false;
|
||||||
line_new = ml_get_buf(curtab->tp_diffbuf[i],
|
line_new = ml_get_buf(curtab->tp_diffbuf[i],
|
||||||
dp->df_lnum[i] + off, FALSE);
|
dp->df_lnum[i] + off, FALSE);
|
||||||
|
|
||||||
@@ -1956,21 +1958,22 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return TRUE if line "lnum" is not close to a diff block, this line should
|
/// Check that line "lnum" is not close to a diff block, this line should
|
||||||
/// be in a fold.
|
/// be in a fold.
|
||||||
///
|
///
|
||||||
/// @param wp
|
/// @param wp window containing the buffer to check
|
||||||
/// @param lnum
|
/// @param lnum line number to check within the buffer
|
||||||
///
|
///
|
||||||
/// @return FALSE if there are no diff blocks at all in this window.
|
/// @return false if there are no diff blocks at all in this window.
|
||||||
int diff_infold(win_T *wp, linenr_T lnum)
|
bool diff_infold(win_T *wp, linenr_T lnum)
|
||||||
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
int other = FALSE;
|
bool other = false;
|
||||||
diff_T *dp;
|
diff_T *dp;
|
||||||
|
|
||||||
// Return if 'diff' isn't set.
|
// Return if 'diff' isn't set.
|
||||||
if (!wp->w_p_diff) {
|
if (!wp->w_p_diff) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
@@ -1979,13 +1982,13 @@ int diff_infold(win_T *wp, linenr_T lnum)
|
|||||||
if (curtab->tp_diffbuf[i] == wp->w_buffer) {
|
if (curtab->tp_diffbuf[i] == wp->w_buffer) {
|
||||||
idx = i;
|
idx = i;
|
||||||
} else if (curtab->tp_diffbuf[i] != NULL) {
|
} else if (curtab->tp_diffbuf[i] != NULL) {
|
||||||
other = TRUE;
|
other = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return here if there are no diffs in the window
|
// return here if there are no diffs in the window
|
||||||
if ((idx == -1) || !other) {
|
if ((idx == -1) || !other) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curtab->tp_diff_invalid) {
|
if (curtab->tp_diff_invalid) {
|
||||||
@@ -1995,7 +1998,7 @@ int diff_infold(win_T *wp, linenr_T lnum)
|
|||||||
|
|
||||||
// Return if there are no diff blocks. All lines will be folded.
|
// Return if there are no diff blocks. All lines will be folded.
|
||||||
if (curtab->tp_first_diff == NULL) {
|
if (curtab->tp_first_diff == NULL) {
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) {
|
for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) {
|
||||||
@@ -2006,10 +2009,10 @@ int diff_infold(win_T *wp, linenr_T lnum)
|
|||||||
|
|
||||||
// If this change ends before the line we have a match.
|
// If this change ends before the line we have a match.
|
||||||
if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) {
|
if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "dp" and "do" commands.
|
/// "dp" and "do" commands.
|
||||||
@@ -2372,12 +2375,11 @@ static void diff_fold_update(diff_T *dp, int skip_idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the buffer is in diff-mode.
|
/// Checks that the buffer is in diff-mode.
|
||||||
///
|
///
|
||||||
/// @param buf The buffer to check.
|
/// @param buf buffer to check.
|
||||||
///
|
|
||||||
/// @return TRUE if buffer "buf" is in diff-mode.
|
|
||||||
bool diff_mode_buf(buf_T *buf)
|
bool diff_mode_buf(buf_T *buf)
|
||||||
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
FOR_ALL_TABS(tp) {
|
FOR_ALL_TABS(tp) {
|
||||||
if (diff_buf_idx_tp(buf, tp) != DB_COUNT) {
|
if (diff_buf_idx_tp(buf, tp) != DB_COUNT) {
|
||||||
|
Reference in New Issue
Block a user