summaryrefslogtreecommitdiffstats
path: root/lib/libcurses/lib_addch.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-11-26 04:01:02 +0000
committermillert <millert@openbsd.org>1997-11-26 04:01:02 +0000
commit010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b (patch)
tree5ee5e7213ad9b412a927de7effdcb7c8ce4b489e /lib/libcurses/lib_addch.c
parentlibform from ncurses 4.1. Post 4.1 patches to be applied in a separate commit. (diff)
downloadwireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.tar.xz
wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.zip
ncurses 4.1 + changes to work with our terminfo libs (instead of
the ncurses ones). Changes are #ifdef EXTERN_TERMINFO. Post 4.1 patches will be applied in a separate commit.
Diffstat (limited to 'lib/libcurses/lib_addch.c')
-rw-r--r--lib/libcurses/lib_addch.c265
1 files changed, 144 insertions, 121 deletions
diff --git a/lib/libcurses/lib_addch.c b/lib/libcurses/lib_addch.c
index 005c5bfbd22..5ad512c0dd1 100644
--- a/lib/libcurses/lib_addch.c
+++ b/lib/libcurses/lib_addch.c
@@ -26,56 +26,40 @@
**
*/
-#include "curses.priv.h"
+#include <curses.priv.h>
#include <ctype.h>
-#include "unctrl.h"
-#define ALL_BUT_COLOR ((chtype)~(A_COLOR))
+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(("wattr_on(%p,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs)));
- if (PAIR_NUMBER(at) > 0x00) {
- win->_attrs = (win->_attrs & ALL_BUT_COLOR) | at ;
- T(("new attribute is %s", _traceattr(win->_attrs)));
- } else {
- win->_attrs |= at;
- T(("new attribute is %s", _traceattr(win->_attrs)));
- }
- return OK;
+ 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)
{
-#define IGNORE_COLOR_OFF FALSE
-
- T(("wattr_off(%p,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs)));
- if (IGNORE_COLOR_OFF == TRUE) {
- if (PAIR_NUMBER(at) == 0xff) /* turn off color */
- win->_attrs &= ~at;
- else /* leave color alone */
- win->_attrs &= ~(at|ALL_BUT_COLOR);
- } else {
- if (PAIR_NUMBER(at) > 0x00) /* turn off color */
- win->_attrs &= ~at;
- else /* leave color alone */
- win->_attrs &= ~(at|ALL_BUT_COLOR);
- }
- T(("new attribute is %s", _traceattr(win->_attrs)));
- return OK;
+ T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at)));
+ T(("... current %s", _traceattr(win->_attrs)));
+ toggle_attr_off(win->_attrs,at);
+ returnCode(OK);
}
-int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
+int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED)
{
int i;
+ T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color));
+
+ toggle_attr_on(attr,COLOR_PAIR(color));
+
for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++)
win->_line[win->_cury].text[i]
- = (win->_line[win->_cury].text[i] & A_CHARTEXT)
- | attr
- | COLOR_PAIR(color);
+ = ch_or_attr(TextOf(win->_line[win->_cury].text[i]),attr);
- return OK;
+ returnCode(OK);
}
/*
@@ -88,46 +72,48 @@ int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
* window sync hook, for use by string-put functions.
*/
-static __inline chtype render_char(WINDOW *win, chtype oldch, chtype newch)
+static inline chtype render_char(WINDOW *win, chtype ch)
/* compute a rendition of the given char correct for the current context */
{
- if ((oldch & A_CHARTEXT) == ' ')
- newch |= win->_bkgd;
- else if (!(newch & A_ATTRIBUTES))
- newch |= (win->_bkgd & A_ATTRIBUTES);
- TR(TRACE_VIRTPUT, ("bkg = %lx -> ch = %lx", win->_bkgd, newch));
+ 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));
- return(newch);
+ return(ch);
}
-chtype _nc_render(WINDOW *win, chtype oldch, chtype newch)
+chtype _nc_background(WINDOW *win)
/* make render_char() visible while still allowing us to inline it below */
{
- return(render_char(win, oldch, newch));
+ return(render_char(win, BLANK));
}
-/* actions needed to process a newline within addch_nosync() */
-#define DO_NEWLINE x = 0; \
- win->_flags &= ~_NEED_WRAP; \
- y++; \
- if (y > win->_regbottom) { \
- y--; \
- if (win->_scroll) \
- scroll(win); \
- }
+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));
+}
/* check if position is legal; if not, return error */
+#ifdef NDEBUG /* treat this like an assertion */
#define CHECK_POSITION(win, x, y) \
- if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) { \
+ if (y > win->_maxy \
+ || x > win->_maxx \
+ || y < 0 \
+ || x < 0) { \
TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \
"(_maxx = %d, _maxy = %d)", win, x, y, \
win->_maxx, win->_maxy)); \
- win->_curx = win->_cury = 0; \
- win->_flags &= ~_NEED_WRAP; \
- return(ERR); \
+ return(ERR); \
}
+#else
+#define CHECK_POSITION(win, x, y) /* nothing */
+#endif
-static __inline
+static inline
int waddch_literal(WINDOW *win, chtype ch)
{
register int x, y;
@@ -137,21 +123,19 @@ register int x, y;
CHECK_POSITION(win, x, y);
- if (win->_flags & _NEED_WRAP) {
- TR(TRACE_MOVE, ("new char when NEED_WRAP set at %d,%d",y,x));
- DO_NEWLINE
- }
-
/*
- * We used to pass in
- * win->_line[y].text[x]
- * as a second argument, but the value of the old character
- * is not relevant here.
+ * If we're trying to add a character at the lower-right corner more
+ * than once, fail. (Moving the cursor will clear the flag).
*/
- ch = render_char(win, 0, ch);
+ if (win->_flags & _WRAPPED) {
+ if (x >= win->_maxx)
+ return (ERR);
+ win->_flags &= ~_WRAPPED;
+ }
+ ch = render_char(win, ch);
+ ch = ch_or_attr(ch,win->_attrs);
TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs)));
- ch |= win->_attrs;
if (win->_line[y].text[x] != ch) {
if (win->_line[y].firstchar == _NOCHANGE)
@@ -164,14 +148,31 @@ register int x, y;
}
win->_line[y].text[x++] = ch;
- TR(TRACE_VIRTPUT, ("(%d, %d) = %s | %s",
- y, x,
- _tracechar((unsigned char)(ch & A_CHARTEXT)),
- _traceattr((ch & (chtype)A_ATTRIBUTES))));
+ TR(TRACE_VIRTPUT, ("(%d, %d) = %s", y, x, _tracechtype(ch)));
if (x > win->_maxx) {
- TR(TRACE_MOVE, ("NEED_WRAP set at %d,%d",y,x));
- win->_flags |= _NEED_WRAP;
- x--;
+ /*
+ * The _WRAPPED flag is useful only for telling an application
+ * that we've just wrapped the cursor. We don't do anything
+ * with this flag except set it when wrapping, and clear it
+ * whenever we move the cursor. If we try to wrap at the
+ * lower-right corner of a window, we cannot move the cursor
+ * (since that wouldn't be legal). So we return an error
+ * (which is what SVr4 does). Unlike SVr4, we can successfully
+ * 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;
+ return (ERR);
+ }
+ }
+ x = 0;
}
win->_curx = x;
@@ -180,13 +181,12 @@ register int x, y;
return OK;
}
-static __inline
+static inline
int waddch_nosync(WINDOW *win, const chtype c)
/* the workhorse function -- add a character to the given window */
{
register chtype ch = c;
register int x, y;
-int newx;
x = win->_curx;
y = win->_cury;
@@ -196,40 +196,63 @@ int newx;
if (ch & A_ALTCHARSET)
goto noctrl;
- switch ((int)(ch&A_CHARTEXT)) {
- case '\t':
- if (win->_flags & _NEED_WRAP) {
- x = 0;
- newx = min(TABSIZE, win->_maxx+1);
- } else
- newx = min(x + (TABSIZE-(x%TABSIZE)), win->_maxx+1);
- while (win->_curx < newx) {
- if (waddch_literal(win, ' ' | (ch&A_ATTRIBUTES)) == ERR)
- return(ERR);
+ switch ((int)TextOf(ch)) {
+ case '\t':
+ x += (TABSIZE-(x%TABSIZE));
+
+ /*
+ * Space-fill the tab on the bottom line so that we'll get the
+ * "correct" cursor position.
+ */
+ if ((! win->_scroll && (y == win->_regbottom))
+ || (x <= win->_maxx)) {
+ while (win->_curx < x) {
+ if (waddch_literal(win, (' ' | AttrOf(ch))) == ERR)
+ return(ERR);
+ }
+ break;
+ } else {
+ wclrtoeol(win);
+ win->_flags |= _WRAPPED;
+ if (++y > win->_regbottom) {
+ x = win->_maxx;
+ y--;
+ if (win->_scroll) {
+ scroll(win);
+ x = 0;
+ }
+ } else {
+ x = 0;
+ }
}
- return(OK);
- case '\n':
- wclrtoeol(win);
- DO_NEWLINE
break;
- case '\r':
+ case '\n':
+ wclrtoeol(win);
+ if (++y > win->_regbottom) {
+ y--;
+ if (win->_scroll)
+ scroll(win);
+ else
+ return (ERR);
+ }
+ /* FALLTHRU */
+ case '\r':
x = 0;
- win->_flags &= ~_NEED_WRAP;
+ win->_flags &= ~_WRAPPED;
break;
- case '\b':
- if (win->_flags & _NEED_WRAP)
- win->_flags &= ~_NEED_WRAP;
- else if (--x < 0)
- x = 0;
+ case '\b':
+ if (x > 0) {
+ x--;
+ win->_flags &= ~_WRAPPED;
+ }
break;
- default:
- if (is7bits(ch & A_CHARTEXT) && iscntrl(ch & A_CHARTEXT))
- return(waddstr(win, unctrl((unsigned char)ch)));
+ default:
+ if (is7bits(TextOf(ch)) && iscntrl(TextOf(ch)))
+ return(waddstr(win, unctrl((unsigned char)ch)));
/* FALLTHRU */
- noctrl:
- waddch_literal(win, ch);
- return(OK);
+ noctrl:
+ return waddch_literal(win, ch);
}
win->_curx = x;
@@ -238,8 +261,6 @@ int newx;
return(OK);
}
-#undef DO_NEWLINE
-
int _nc_waddch_nosync(WINDOW *win, const chtype c)
/* export copy of waddch_nosync() so the string-put functions can use it */
{
@@ -256,32 +277,34 @@ int _nc_waddch_nosync(WINDOW *win, const chtype c)
int waddch(WINDOW *win, const chtype ch)
{
- TR(TRACE_VIRTPUT, ("waddch(%p, %s | %s) called", win,
- _tracechar((unsigned char)(ch & A_CHARTEXT)),
- _traceattr((ch & (chtype)A_ATTRIBUTES))));
+ int code = ERR;
- if (waddch_nosync(win, ch) == ERR)
- return(ERR);
- else
+ TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch)));
+
+ if (waddch_nosync(win, ch) != ERR)
{
_nc_synchook(win);
- TR(TRACE_VIRTPUT, ("waddch() is done"));
- return(OK);
+ code = OK;
}
+
+ TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code));
+ return(code);
}
int wechochar(WINDOW *win, const chtype ch)
{
- TR(TRACE_VIRTPUT, ("wechochar(%p,%s (%s)) called", win,
- _tracechar((unsigned char)(ch & A_CHARTEXT)),
- _traceattr((ch & (chtype)A_ATTRIBUTES))));
+ int code = ERR;
+
+ TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch)));
- if (waddch_literal(win, ch) == ERR)
- return(ERR);
- else
+ if (waddch_literal(win, ch) != ERR)
{
+ bool save_immed = win->_immed;
+ win->_immed = TRUE;
_nc_synchook(win);
- TR(TRACE_VIRTPUT, ("wechochar() is done"));
- return(OK);
+ win->_immed = save_immed;
+ code = OK;
}
+ TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_RETURN("%d"), code));
+ return(code);
}