summaryrefslogtreecommitdiff
path: root/lib/libcurses/lib_addch.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-12-03 05:21:47 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-12-03 05:21:47 +0000
commit211326e37501ac01a66994a221020b75ab5f63f0 (patch)
tree6d6c7182f1034b1b04c98386a1c3ba44e8accd5f /lib/libcurses/lib_addch.c
parent7c742f381e7808d0b12c17b534305751f3ebb0cb (diff)
Merge of ncurses-4.1-971129
Diffstat (limited to 'lib/libcurses/lib_addch.c')
-rw-r--r--lib/libcurses/lib_addch.c161
1 files changed, 79 insertions, 82 deletions
diff --git a/lib/libcurses/lib_addch.c b/lib/libcurses/lib_addch.c
index 5ad512c0dd1..cd22cff9a38 100644
--- a/lib/libcurses/lib_addch.c
+++ b/lib/libcurses/lib_addch.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: lib_addch.c,v 1.3 1997/12/03 05:21:10 millert Exp $ */
+
/***************************************************************************
* COPYRIGHT NOTICE *
@@ -22,30 +24,14 @@
/*
** lib_addch.c
**
-** The routines waddch(), wattr_on(), wattr_off(), wchgat().
+** The routines waddch(), wchgat().
**
*/
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("Id: lib_addch.c,v 1.30 1997/04/12 17:45:55 tom Exp $")
-
-int wattr_on(WINDOW *win, const attr_t at)
-{
- T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at)));
- T(("... current %s", _traceattr(win->_attrs)));
- toggle_attr_on(win->_attrs,at);
- returnCode(OK);
-}
-
-int wattr_off(WINDOW *win, const attr_t at)
-{
- T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at)));
- T(("... current %s", _traceattr(win->_attrs)));
- toggle_attr_off(win->_attrs,at);
- returnCode(OK);
-}
+MODULE_ID("Id: lib_addch.c,v 1.36 1997/10/08 09:38:17 jtc Exp $")
int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED)
{
@@ -53,13 +39,17 @@ int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UN
T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
- toggle_attr_on(attr,COLOR_PAIR(color));
+ if (win) {
+ toggle_attr_on(attr,COLOR_PAIR(color));
- for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++)
+ for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++)
win->_line[win->_cury].text[i]
- = ch_or_attr(TextOf(win->_line[win->_cury].text[i]),attr);
+ = TextOf(win->_line[win->_cury].text[i]) | attr;
- returnCode(OK);
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
/*
@@ -72,14 +62,29 @@ int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UN
* window sync hook, for use by string-put functions.
*/
+/* Return bit mask for clearing color pair number if given ch has color */
+#define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0))
+
static inline chtype render_char(WINDOW *win, chtype ch)
/* compute a rendition of the given char correct for the current context */
{
- if (TextOf(ch) == ' ')
- ch = ch_or_attr(ch, win->_bkgd);
- else if (!(ch & A_ATTRIBUTES))
- ch = ch_or_attr(ch, (win->_bkgd & A_ATTRIBUTES));
- TR(TRACE_VIRTPUT, ("bkg = %#lx -> ch = %#lx", win->_bkgd, ch));
+ chtype a = win->_attrs;
+
+ if (ch == ' ')
+ {
+ /* color in attrs has precedence over bkgd */
+ ch = a | (win->_bkgd & COLOR_MASK(a));
+ }
+ else
+ {
+ /* color in attrs has precedence over bkgd */
+ a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a);
+ /* color in ch has precedence */
+ ch |= (a & COLOR_MASK(ch));
+ }
+
+ TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd,
+ win->_attrs, ch));
return(ch);
}
@@ -87,18 +92,17 @@ static inline chtype render_char(WINDOW *win, chtype ch)
chtype _nc_background(WINDOW *win)
/* make render_char() visible while still allowing us to inline it below */
{
- return(render_char(win, BLANK));
+ return (win->_bkgd);
}
chtype _nc_render(WINDOW *win, chtype ch)
/* make render_char() visible while still allowing us to inline it below */
{
- chtype c = render_char(win,ch);
- return (ch_or_attr(c,win->_attrs));
+ return render_char(win, ch);
}
/* check if position is legal; if not, return error */
-#ifdef NDEBUG /* treat this like an assertion */
+#ifndef NDEBUG /* treat this like an assertion */
#define CHECK_POSITION(win, x, y) \
if (y > win->_maxy \
|| x > win->_maxx \
@@ -116,12 +120,12 @@ chtype _nc_render(WINDOW *win, chtype ch)
static inline
int waddch_literal(WINDOW *win, chtype ch)
{
-register int x, y;
+ int x;
+ struct ldat *line;
x = win->_curx;
- y = win->_cury;
- CHECK_POSITION(win, x, y);
+ CHECK_POSITION(win, x, win->_cury);
/*
* If we're trying to add a character at the lower-right corner more
@@ -134,21 +138,20 @@ register int x, y;
}
ch = render_char(win, ch);
- ch = ch_or_attr(ch,win->_attrs);
TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs)));
- if (win->_line[y].text[x] != ch) {
- if (win->_line[y].firstchar == _NOCHANGE)
- win->_line[y].firstchar = win->_line[y].lastchar = x;
- else if (x < win->_line[y].firstchar)
- win->_line[y].firstchar = x;
- else if (x > win->_line[y].lastchar)
- win->_line[y].lastchar = x;
-
- }
-
- win->_line[y].text[x++] = ch;
- TR(TRACE_VIRTPUT, ("(%d, %d) = %s", y, x, _tracechtype(ch)));
+ line = win->_line+win->_cury;
+
+ if (line->firstchar == _NOCHANGE)
+ line->firstchar = line->lastchar = x;
+ else if (x < line->firstchar)
+ line->firstchar = x;
+ else if (x > line->lastchar)
+ line->lastchar = x;
+
+ line->text[x++] = ch;
+
+ TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch)));
if (x > win->_maxx) {
/*
* The _WRAPPED flag is useful only for telling an application
@@ -161,42 +164,40 @@ register int x, y;
* add a character to the lower-right corner.
*/
win->_flags |= _WRAPPED;
- if (++y > win->_regbottom) {
- y = win->_regbottom;
- x = win->_maxx;
- if (win->_scroll)
- scroll(win);
- else {
- win->_curx = x;
- win->_cury = y;
+ if (++win->_cury > win->_regbottom) {
+ win->_cury = win->_regbottom;
+ win->_curx = win->_maxx;
+ if (!win->_scroll)
return (ERR);
- }
+ scroll(win);
}
- x = 0;
+ win->_curx = 0;
+ return (OK);
}
-
win->_curx = x;
- win->_cury = y;
-
return OK;
}
static inline
-int waddch_nosync(WINDOW *win, const chtype c)
+int waddch_nosync(WINDOW *win, const chtype ch)
/* the workhorse function -- add a character to the given window */
{
-register chtype ch = c;
-register int x, y;
+ int x, y;
+ int t;
+ const char *s;
+
+ if (ch & A_ALTCHARSET)
+ return waddch_literal(win, ch);
+ t = TextOf(ch);
+ s = unctrl(t);
+ if (s[1] == 0) /* not a control char */
+ return waddch_literal(win, ch);
+
x = win->_curx;
y = win->_cury;
- CHECK_POSITION(win, x, y);
-
- if (ch & A_ALTCHARSET)
- goto noctrl;
-
- switch ((int)TextOf(ch)) {
+ switch (t) {
case '\t':
x += (TABSIZE-(x%TABSIZE));
@@ -206,8 +207,9 @@ register int x, y;
*/
if ((! win->_scroll && (y == win->_regbottom))
|| (x <= win->_maxx)) {
+ chtype blank = (' ' | AttrOf(ch));
while (win->_curx < x) {
- if (waddch_literal(win, (' ' | AttrOf(ch))) == ERR)
+ if (waddch_literal(win, blank) == ERR)
return(ERR);
}
break;
@@ -241,18 +243,13 @@ register int x, y;
win->_flags &= ~_WRAPPED;
break;
case '\b':
- if (x > 0) {
- x--;
- win->_flags &= ~_WRAPPED;
- }
+ if (x == 0)
+ return (OK);
+ x--;
+ win->_flags &= ~_WRAPPED;
break;
default:
- if (is7bits(TextOf(ch)) && iscntrl(TextOf(ch)))
- return(waddstr(win, unctrl((unsigned char)ch)));
-
- /* FALLTHRU */
- noctrl:
- return waddch_literal(win, ch);
+ return(waddstr(win, s));
}
win->_curx = x;
@@ -281,7 +278,7 @@ int waddch(WINDOW *win, const chtype ch)
TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch)));
- if (waddch_nosync(win, ch) != ERR)
+ if (win && (waddch_nosync(win, ch) != ERR))
{
_nc_synchook(win);
code = OK;
@@ -297,7 +294,7 @@ int wechochar(WINDOW *win, const chtype ch)
TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch)));
- if (waddch_literal(win, ch) != ERR)
+ if (win && (waddch_nosync(win, ch) != ERR))
{
bool save_immed = win->_immed;
win->_immed = TRUE;