From 7a8e9a559a8d08937a0fde473fb992f18e74132f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 17 Jun 2022 21:56:33 -0400 Subject: [PATCH] Factor out build-conditional wresize calls. Instead of using #if HAVE_CURSES_WRESIZE at each call site, we can make a simple wrapper function that "works" in either case. --- src/curses.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/curses.c b/src/curses.c index cdaf396..8405e23 100644 --- a/src/curses.c +++ b/src/curses.c @@ -201,17 +201,25 @@ static void curs_redraw_goal(struct app_state *state, uint_fast32_t mask) } } +/* Thin wrapper around wresize which returns ERR if support is unavailable. */ +static int do_wresize(WINDOW *window, int lines, int columns) +{ +#if HAVE_CURSES_WRESIZE + return wresize(window, lines, columns); +#endif + return ERR; +} + static WINDOW *realloc_area(WINDOW **orig, int h, int w, int y, int x) { WINDOW *win = *orig; if (win) { -#if HAVE_CURSES_WRESIZE - if (wresize(win, h, w) != ERR) { + if (do_wresize(win, h, w) != ERR) { mvwin(win, y, x); return win; } -#endif + delwin(win); } @@ -228,13 +236,9 @@ static void realloc_tiles(WINDOW **win, int h) if (fill && border) { int old_w, old_h; -#if HAVE_CURSES_WRESIZE - if (wresize(fill, h-2, w-2) != ERR - && wresize(border, h, w) != ERR) - { + if (do_wresize(fill, h-2, w-2) != ERR + && do_wresize(border, h, w) != ERR) return; - } -#endif getmaxyx(border, old_h, old_w); if (old_h == h) -- 2.43.2