From: Nick Bowler Date: Sat, 18 Jun 2022 01:56:33 +0000 (-0400) Subject: Factor out build-conditional wresize calls. X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/7a8e9a559a8d08937a0fde473fb992f18e74132f 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. --- 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)