From 8295a88ff0f15f2c5266b1e1f576cfe8896c6fc7 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 18 Dec 2015 10:41:09 +0000 Subject: [PATCH] Using a couple less #ifdefs, to mimic how this is done in set_colorpairs(). git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5495 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +++ src/color.c | 35 +++++++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f6876b8..f430738d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-12-18 Benno Schulenberg + * src/color.c (color_init): Use less #ifdefs. + 2015-12-11 Benno Schulenberg * doc/syntax/Makefile.am: Add missing autoconf and nftables syntaxes. * ChangeLog: Correct a bug number, plus a few other tweaks. diff --git a/src/color.c b/src/color.c index 8557aa20..a005eebb 100644 --- a/src/color.c +++ b/src/color.c @@ -101,39 +101,38 @@ void set_colorpairs(void) /* Initialize the color information. */ void color_init(void) { + colortype *tmpcolor = openfile->colorstrings; + bool using_defaults = FALSE; + short foreground, background; + assert(openfile != NULL); - if (has_colors()) { - const colortype *tmpcolor; + /* If the terminal is not capable of colors, forget it. */ + if (!has_colors()) + return; + #ifdef HAVE_USE_DEFAULT_COLORS - /* Use the default colors, if available. */ - bool defok = (use_default_colors() != ERR); + /* Allow using the default colors, if available. */ + using_defaults = (use_default_colors() != ERR); #endif - for (tmpcolor = openfile->colorstrings; tmpcolor != NULL; + for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) { - short foreground = tmpcolor->fg, background = tmpcolor->bg; - if (foreground == -1) { -#ifdef HAVE_USE_DEFAULT_COLORS - if (!defok) -#endif + foreground = tmpcolor->fg; + background = tmpcolor->bg; + + if (foreground == -1 && !using_defaults) foreground = COLOR_WHITE; - } - if (background == -1) { -#ifdef HAVE_USE_DEFAULT_COLORS - if (!defok) -#endif + if (background == -1 && !using_defaults) background = COLOR_BLACK; - } init_pair(tmpcolor->pairnum, foreground, background); #ifdef DEBUG - fprintf(stderr, "init_pair(): fg = %hd, bg = %hd\n", tmpcolor->fg, tmpcolor->bg); + fprintf(stderr, "init_pair(): fg = %hd, bg = %hd\n", foreground, background); #endif } - } } /* Clean up a regex we previously compiled. */ -- 2.39.5