Merge pull request #4039 from cacplate/pr-3696

window.c: change return types to bool (adoption of #3696)
This commit is contained in:
Justin M. Keyes 2016-01-25 14:12:12 -05:00
commit ce0e66260f
2 changed files with 157 additions and 136 deletions

View File

@ -6305,7 +6305,7 @@ bool has_event(int event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// @param force When true, ignore autocmd_busy /// @param force When true, ignore autocmd_busy
/// @param group autocmd group ID or AUGROUP_ALL /// @param group autocmd group ID or AUGROUP_ALL
/// @param buf Buffer for <abuf> /// @param buf Buffer for <abuf>
/// @param exarg Ex command arguments /// @param eap Ex command arguments
/// ///
/// @return true if some commands were executed. /// @return true if some commands were executed.
static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,

View File

@ -1044,19 +1044,21 @@ static void win_init_some(win_T *newp, win_T *oldp)
} }
/* /// Check if "win" is a pointer to an existing window in the current tabpage.
* Check if "win" is a pointer to an existing window. ///
*/ /// @param win window to check
int win_valid(win_T *win) bool win_valid(win_T *win) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
if (win == NULL) if (win == NULL) {
return FALSE; return false;
}
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp == win) { if (wp == win) {
return TRUE; return true;
} }
} }
return FALSE; return false;
} }
/* /*
@ -1732,21 +1734,18 @@ close_windows (
shell_new_rows(); shell_new_rows();
} }
/* /// Check that current window is the last one.
* Return TRUE if the current window is the only window that exists (ignoring ///
* "aucmd_win"). /// @return true if the current window is the only window that exists, false if
* Returns FALSE if there is a window, possibly in another tab page. /// there is another, possibly in another tab page.
*/ static bool last_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
static int last_window(void)
{ {
return one_window() && first_tabpage->tp_next == NULL; return one_window() && first_tabpage->tp_next == NULL;
} }
/* /// Check that current tab page contains no more then one window other than
* Return TRUE if there is only one window other than "aucmd_win" in the /// "aucmd_win".
* current tab page. bool one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
*/
bool one_window(void)
{ {
bool seen_one = false; bool seen_one = false;
@ -1761,14 +1760,20 @@ bool one_window(void)
return true; return true;
} }
/* /// Close the possibly last window in a tab page.
* Close the possibly last window in a tab page. ///
* Returns TRUE when the window was closed already. /// @param win window to close
*/ /// @param free_buf whether to free the window's current buffer
static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_curtab) /// @param prev_curtab previous tabpage that will be closed if "win" is the
/// last window in the tabpage
///
/// @return true when the window was closed already.
static bool close_last_window_tabpage(win_T *win, bool free_buf,
tabpage_T *prev_curtab)
FUNC_ATTR_NONNULL_ARG(1)
{ {
if (firstwin != lastwin) { if (firstwin != lastwin) {
return FALSE; return false;
} }
buf_T *old_curbuf = curbuf; buf_T *old_curbuf = curbuf;
@ -1809,14 +1814,15 @@ static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_c
terminal_resize(term, 0, 0); terminal_resize(term, 0, 0);
} }
/* Since goto_tabpage_tp above did not trigger *Enter autocommands, do // Since goto_tabpage_tp above did not trigger *Enter autocommands, do
* that now. */ // that now.
apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, FALSE, curbuf); apply_autocmds(EVENT_TABCLOSED, prev_idx, prev_idx, false, curbuf);
apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf);
if (old_curbuf != curbuf) if (old_curbuf != curbuf) {
apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
return TRUE; }
return true;
} }
/* /*
@ -2301,20 +2307,22 @@ static win_T *frame2win(frame_T *frp)
return frp->fr_win; return frp->fr_win;
} }
/* /// Check that the frame "frp" contains the window "wp".
* Return TRUE if frame "frp" contains window "wp". ///
*/ /// @param frp frame
static int frame_has_win(frame_T *frp, win_T *wp) /// @param wp window
static bool frame_has_win(frame_T *frp, win_T *wp)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
{ {
frame_T *p; if (frp->fr_layout == FR_LEAF) {
if (frp->fr_layout == FR_LEAF)
return frp->fr_win == wp; return frp->fr_win == wp;
}
for (p = frp->fr_child; p != NULL; p = p->fr_next) for (frame_T *p = frp->fr_child; p != NULL; p = p->fr_next) {
if (frame_has_win(p, wp)) if (frame_has_win(p, wp)) {
return TRUE; return true;
return FALSE; }
}
return false;
} }
/* /*
@ -2406,58 +2414,72 @@ frame_new_height (
topfrp->fr_height = height; topfrp->fr_height = height;
} }
/* /// Return true if height of frame "frp" should not be changed because of
* Return TRUE if height of frame "frp" should not be changed because of /// the 'winfixheight' option.
* the 'winfixheight' option. ///
*/ /// @param frp frame
static int frame_fixed_height(frame_T *frp) ///
/// @return true if the frame has a fixed height
static bool frame_fixed_height(frame_T *frp)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
/* frame with one window: fixed height if 'winfixheight' set. */ // frame with one window: fixed height if 'winfixheight' set.
if (frp->fr_win != NULL) if (frp->fr_win != NULL) {
return frp->fr_win->w_p_wfh; return frp->fr_win->w_p_wfh;
}
if (frp->fr_layout == FR_ROW) { if (frp->fr_layout == FR_ROW) {
/* The frame is fixed height if one of the frames in the row is fixed // The frame is fixed height if one of the frames in the row is fixed
* height. */ // height.
for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) {
if (frame_fixed_height(frp)) if (frame_fixed_height(frp)) {
return TRUE; return true;
return FALSE; }
}
return false;
} }
/* frp->fr_layout == FR_COL: The frame is fixed height if all of the // frp->fr_layout == FR_COL: The frame is fixed height if all of the
* frames in the row are fixed height. */ // frames in the row are fixed height.
for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) {
if (!frame_fixed_height(frp)) if (!frame_fixed_height(frp)) {
return FALSE; return false;
return TRUE; }
}
return true;
} }
/* /// Return true if width of frame "frp" should not be changed because of
* Return TRUE if width of frame "frp" should not be changed because of /// the 'winfixwidth' option.
* the 'winfixwidth' option. ///
*/ /// @param frp frame
static int frame_fixed_width(frame_T *frp) ///
/// @return true if the frame has a fixed width
static bool frame_fixed_width(frame_T *frp)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
/* frame with one window: fixed width if 'winfixwidth' set. */ // frame with one window: fixed width if 'winfixwidth' set.
if (frp->fr_win != NULL) if (frp->fr_win != NULL) {
return frp->fr_win->w_p_wfw; return frp->fr_win->w_p_wfw;
}
if (frp->fr_layout == FR_COL) { if (frp->fr_layout == FR_COL) {
/* The frame is fixed width if one of the frames in the row is fixed // The frame is fixed width if one of the frames in the row is fixed
* width. */ // width.
for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) {
if (frame_fixed_width(frp)) if (frame_fixed_width(frp)) {
return TRUE; return true;
return FALSE; }
}
return false;
} }
/* frp->fr_layout == FR_ROW: The frame is fixed width if all of the // frp->fr_layout == FR_ROW: The frame is fixed width if all of the
* frames in the row are fixed width. */ // frames in the row are fixed width.
for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) {
if (!frame_fixed_width(frp)) if (!frame_fixed_width(frp)) {
return FALSE; return false;
return TRUE; }
}
return true;
} }
/* /*
@ -3028,10 +3050,10 @@ int make_tabpages(int maxcount)
return count - todo; return count - todo;
} }
/* /// Check that tpc points to a valid tab page.
* Return TRUE when "tpc" points to a valid tab page. ///
*/ /// @param[in] tpc Tabpage to check.
bool valid_tabpage(tabpage_T *tpc) bool valid_tabpage(tabpage_T *tpc) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
FOR_ALL_TABS(tp) { FOR_ALL_TABS(tp) {
if (tp == tpc) { if (tp == tpc) {
@ -5052,27 +5074,22 @@ int min_rows(void)
return total; return total;
} }
/* /// Check that there is only one window (and only one tab page), not counting a
* Return TRUE if there is only one window (in the current tab page), not /// help or preview window, unless it is the current window. Does not count
* counting a help or preview window, unless it is the current window. /// "aucmd_win".
* Does not count "aucmd_win". bool only_one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
*/
int only_one_window(void)
{ {
// If there is another tab page there always is another window.
if (first_tabpage->tp_next != NULL) {
return false;
}
int count = 0; int count = 0;
/* If there is another tab page there always is another window. */
if (first_tabpage->tp_next != NULL)
return FALSE;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer != NULL if (wp->w_buffer != NULL
&& (!((wp->w_buffer->b_help && !curbuf->b_help) && (!((wp->w_buffer->b_help && !curbuf->b_help)
|| wp->w_p_pvw || wp->w_p_pvw) || wp == curwin) && wp != aucmd_win) {
) || wp == curwin) count++;
&& wp != aucmd_win
) {
++count;
} }
} }
return count <= 1; return count <= 1;
@ -5571,38 +5588,42 @@ matchitem_T *get_match(win_T *wp, int id)
} }
/* /// Check that "topfrp" and its children are at the right height.
* Return TRUE if "topfrp" and its children are at the right height. ///
*/ /// @param topfrp top frame pointer
static int frame_check_height(frame_T *topfrp, int height) /// @param height expected height
static bool frame_check_height(frame_T *topfrp, int height)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
frame_T *frp; if (topfrp->fr_height != height) {
return false;
if (topfrp->fr_height != height) }
return FALSE; if (topfrp->fr_layout == FR_ROW) {
for (frame_T *frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) {
if (topfrp->fr_layout == FR_ROW) if (frp->fr_height != height) {
for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) return false;
if (frp->fr_height != height) }
return FALSE; }
}
return TRUE; return true;
} }
/* /// Check that "topfrp" and its children are at the right width.
* Return TRUE if "topfrp" and its children are at the right width. ///
*/ /// @param topfrp top frame pointer
static int frame_check_width(frame_T *topfrp, int width) /// @param width expected width
static bool frame_check_width(frame_T *topfrp, int width)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
frame_T *frp; if (topfrp->fr_width != width) {
return false;
if (topfrp->fr_width != width) }
return FALSE; if (topfrp->fr_layout == FR_COL) {
for (frame_T *frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) {
if (topfrp->fr_layout == FR_COL) if (frp->fr_width != width) {
for (frp = topfrp->fr_child; frp != NULL; frp = frp->fr_next) return false;
if (frp->fr_width != width) }
return FALSE; }
}
return TRUE; return true;
} }