Refactor. Move code to turn attributes on/off into separate
functions. Express both old and new functions to manipulate attributes using those functions. Check that the the new API's opts argument (reserved by the standard for future use) is NULL and error out if not (like getcchar/setcchar). No functional change intended.
This commit is contained in:
parent
0d71550e67
commit
44b007ca68
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: attributes.c,v 1.26 2018/11/22 23:37:31 uwe Exp $ */
|
||||
/* $NetBSD: attributes.c,v 1.27 2018/11/23 11:11:59 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
|
@ -31,14 +31,17 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: attributes.c,v 1.26 2018/11/22 23:37:31 uwe Exp $");
|
||||
__RCSID("$NetBSD: attributes.c,v 1.27 2018/11/23 11:11:59 uwe Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
static int __wattr_off(WINDOW *, attr_t);
|
||||
static int __wattr_on(WINDOW *, attr_t);
|
||||
static void __wcolor_set(WINDOW *, attr_t);
|
||||
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
/*
|
||||
* attr_get --
|
||||
|
@ -102,7 +105,7 @@ color_set(short pair, void *opt)
|
|||
int
|
||||
attron(int attr)
|
||||
{
|
||||
return wattr_on(stdscr, (attr_t) attr, NULL);
|
||||
return __wattr_on(stdscr, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -112,7 +115,7 @@ attron(int attr)
|
|||
int
|
||||
attroff(int attr)
|
||||
{
|
||||
return wattr_off(stdscr, (attr_t) attr, NULL);
|
||||
return __wattr_off(stdscr, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -155,53 +158,13 @@ wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opt)
|
|||
* wattr_on --
|
||||
* Test and set wide attributes on window
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
wattr_on(WINDOW *win, attr_t attr, void *opt)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
if (__predict_false(opt != NULL))
|
||||
return ERR;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can enter modes, set the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
|
||||
win->wattr |= __BLINK;
|
||||
if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
|
||||
win->wattr |= __BOLD;
|
||||
if (attr & __DIM && t_enter_dim_mode(t) != NULL)
|
||||
win->wattr |= __DIM;
|
||||
if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
|
||||
win->wattr |= __BLANK;
|
||||
if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
|
||||
win->wattr |= __PROTECT;
|
||||
if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
|
||||
win->wattr |= __REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LOW;
|
||||
if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_TOP;
|
||||
if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LEFT;
|
||||
if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
|
||||
t_exit_standout_mode(t) != NULL)
|
||||
wstandout(win);
|
||||
if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
|
||||
t_exit_underline_mode(t) != NULL)
|
||||
wunderscore(win);
|
||||
if (attr & __COLOR)
|
||||
__wcolor_set(win, attr);
|
||||
return OK;
|
||||
return __wattr_on(win, attr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -211,55 +174,16 @@ wattr_on(WINDOW *win, attr_t attr, void *opt)
|
|||
* Note that the 'me' sequence unsets all attributes. We handle
|
||||
* which attributes should really be set in refresh.c:makech().
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
wattr_off(WINDOW *win, attr_t attr, void *opt)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
if (__predict_false(opt != NULL))
|
||||
return ERR;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can do exit modes, unset the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK)
|
||||
win->wattr &= ~__BLINK;
|
||||
if (attr & __BOLD)
|
||||
win->wattr &= ~__BOLD;
|
||||
if (attr & __DIM)
|
||||
win->wattr &= ~__DIM;
|
||||
if (attr & __BLANK)
|
||||
win->wattr &= ~__BLANK;
|
||||
if (attr & __PROTECT)
|
||||
win->wattr &= ~__PROTECT;
|
||||
if (attr & __REVERSE)
|
||||
win->wattr &= ~__REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW)
|
||||
win->wattr &= ~WA_LOW;
|
||||
if (attr & WA_TOP)
|
||||
win->wattr &= ~WA_TOP;
|
||||
if (attr & WA_LEFT)
|
||||
win->wattr &= ~WA_LEFT;
|
||||
if (attr & WA_RIGHT)
|
||||
win->wattr &= ~WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL)
|
||||
win->wattr &= ~WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL)
|
||||
win->wattr &= ~WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT)
|
||||
wstandend(win);
|
||||
if (attr & __UNDERSCORE)
|
||||
wunderend(win);
|
||||
if (attr & __COLOR) {
|
||||
if (max_colors != 0)
|
||||
win->wattr &= ~__COLOR;
|
||||
}
|
||||
return OK;
|
||||
return __wattr_off(win, attr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wattr_set --
|
||||
* Set wide attributes and color pair on window
|
||||
|
@ -271,13 +195,17 @@ wattr_set(WINDOW *win, attr_t attr, short pair, void *opt)
|
|||
__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
|
||||
win, attr, pair);
|
||||
#endif
|
||||
wattr_off(win, __ATTRIBUTES, opt);
|
||||
if (__predict_false(opt != NULL))
|
||||
return ERR;
|
||||
|
||||
/*
|
||||
* This overwrites any colour setting from the attributes
|
||||
* and is compatible with ncurses.
|
||||
*/
|
||||
attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
|
||||
wattr_on(win, attr, opt);
|
||||
|
||||
__wattr_off(win, __ATTRIBUTES);
|
||||
__wattr_on(win, attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -319,7 +247,7 @@ wattron(WINDOW *win, int attr)
|
|||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
return wattr_on(win, (attr_t) attr, NULL);
|
||||
return __wattr_on(win, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -332,7 +260,7 @@ wattroff(WINDOW *win, int attr)
|
|||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
return wattr_off(win, (attr_t) attr, NULL);
|
||||
return __wattr_off(win, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -346,8 +274,8 @@ wattrset(WINDOW *win, int attr)
|
|||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
wattr_off(win, __ATTRIBUTES, NULL);
|
||||
wattr_on(win, (attr_t) attr, NULL);
|
||||
__wattr_off(win, __ATTRIBUTES);
|
||||
__wattr_on(win, (attr_t) attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -440,10 +368,105 @@ term_attrs(void)
|
|||
return attr;
|
||||
}
|
||||
|
||||
/*
|
||||
* __wcolor_set --
|
||||
* Set color attribute on window
|
||||
*/
|
||||
|
||||
static int
|
||||
__wattr_on(WINDOW *win, attr_t attr)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can enter modes, set the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
|
||||
win->wattr |= __BLINK;
|
||||
if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
|
||||
win->wattr |= __BOLD;
|
||||
if (attr & __DIM && t_enter_dim_mode(t) != NULL)
|
||||
win->wattr |= __DIM;
|
||||
if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
|
||||
win->wattr |= __BLANK;
|
||||
if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
|
||||
win->wattr |= __PROTECT;
|
||||
if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
|
||||
win->wattr |= __REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LOW;
|
||||
if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_TOP;
|
||||
if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LEFT;
|
||||
if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
|
||||
t_exit_standout_mode(t) != NULL)
|
||||
wstandout(win);
|
||||
if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
|
||||
t_exit_underline_mode(t) != NULL)
|
||||
wunderscore(win);
|
||||
if (attr & __COLOR)
|
||||
__wcolor_set(win, attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
__wattr_off(WINDOW *win, attr_t attr)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can do exit modes, unset the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK)
|
||||
win->wattr &= ~__BLINK;
|
||||
if (attr & __BOLD)
|
||||
win->wattr &= ~__BOLD;
|
||||
if (attr & __DIM)
|
||||
win->wattr &= ~__DIM;
|
||||
if (attr & __BLANK)
|
||||
win->wattr &= ~__BLANK;
|
||||
if (attr & __PROTECT)
|
||||
win->wattr &= ~__PROTECT;
|
||||
if (attr & __REVERSE)
|
||||
win->wattr &= ~__REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW)
|
||||
win->wattr &= ~WA_LOW;
|
||||
if (attr & WA_TOP)
|
||||
win->wattr &= ~WA_TOP;
|
||||
if (attr & WA_LEFT)
|
||||
win->wattr &= ~WA_LEFT;
|
||||
if (attr & WA_RIGHT)
|
||||
win->wattr &= ~WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL)
|
||||
win->wattr &= ~WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL)
|
||||
win->wattr &= ~WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT)
|
||||
wstandend(win);
|
||||
if (attr & __UNDERSCORE)
|
||||
wunderend(win);
|
||||
if (attr & __COLOR) {
|
||||
if (max_colors != 0)
|
||||
win->wattr &= ~__COLOR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
__wcolor_set(WINDOW *win, attr_t attr)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue