1994-10-07 08:58:58 +00:00
|
|
|
|
|
|
|
/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for *
|
|
|
|
* details. If they are missing then this copy is in violation of *
|
|
|
|
* the copyright conditions. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
** lib_addch.c
|
|
|
|
**
|
|
|
|
** The routine waddch().
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "curses.priv.h"
|
|
|
|
#include "unctrl.h"
|
|
|
|
|
1994-12-02 06:40:24 +00:00
|
|
|
static int
|
|
|
|
wladdch(WINDOW *win, chtype c, bool literal)
|
1994-10-07 08:58:58 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int newx;
|
|
|
|
chtype ch = c;
|
|
|
|
|
|
|
|
x = win->_curx;
|
|
|
|
y = win->_cury;
|
|
|
|
|
|
|
|
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
|
|
|
|
return(ERR);
|
|
|
|
|
1994-12-02 06:40:24 +00:00
|
|
|
/* ugly, but necessary --- and, bizarrely enough, even portable! */
|
|
|
|
if (literal)
|
|
|
|
goto noctrl;
|
|
|
|
|
1994-10-07 08:58:58 +00:00
|
|
|
switch (ch&A_CHARTEXT) {
|
|
|
|
case '\t':
|
|
|
|
for (newx = x + (8 - (x & 07)); x < newx; x++)
|
|
|
|
if (waddch(win, ' ') == ERR)
|
|
|
|
return(ERR);
|
|
|
|
return(OK);
|
|
|
|
case '\n':
|
|
|
|
wclrtoeol(win);
|
1994-12-02 06:40:24 +00:00
|
|
|
x = 0;
|
1994-10-07 08:58:58 +00:00
|
|
|
goto newline;
|
|
|
|
case '\r':
|
|
|
|
x = 0;
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
if (--x < 0)
|
|
|
|
x = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ch < ' ')
|
|
|
|
return(waddstr(win, unctrl(ch)));
|
|
|
|
|
1994-12-02 06:40:24 +00:00
|
|
|
/* FALL THROUGH */
|
|
|
|
noctrl:
|
|
|
|
T(("win attr = %x", win->_attrs));
|
1994-10-07 08:58:58 +00:00
|
|
|
ch |= win->_attrs;
|
|
|
|
|
1995-01-16 17:33:33 +00:00
|
|
|
if (win->_line[y][x]&A_CHARTEXT == ' ')
|
|
|
|
ch |= win->_bkgd;
|
1994-12-02 06:40:24 +00:00
|
|
|
else
|
|
|
|
ch |= (win->_bkgd&A_ATTRIBUTES);
|
|
|
|
T(("bkg = %x -> ch = %x", win->_bkgd, ch));
|
|
|
|
|
1994-10-07 08:58:58 +00:00
|
|
|
if (win->_line[y][x] != ch) {
|
|
|
|
if (win->_firstchar[y] == _NOCHANGE)
|
|
|
|
win->_firstchar[y] = win->_lastchar[y] = x;
|
|
|
|
else if (x < win->_firstchar[y])
|
|
|
|
win->_firstchar[y] = x;
|
|
|
|
else if (x > win->_lastchar[y])
|
|
|
|
win->_lastchar[y] = x;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1994-12-02 06:40:24 +00:00
|
|
|
T(("char %d of line %d is %x", x, y, ch));
|
1994-10-07 08:58:58 +00:00
|
|
|
win->_line[y][x++] = ch;
|
|
|
|
if (x > win->_maxx) {
|
|
|
|
x = 0;
|
|
|
|
newline:
|
|
|
|
y++;
|
|
|
|
if (y > win->_regbottom) {
|
|
|
|
y--;
|
|
|
|
if (win->_scroll)
|
|
|
|
scroll(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
win->_curx = x;
|
|
|
|
win->_cury = y;
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
1994-12-02 06:40:24 +00:00
|
|
|
|
|
|
|
int waddch(WINDOW *win, chtype ch)
|
|
|
|
{
|
|
|
|
TR(TRACE_CHARPUT, ("waddch(%x,%c (%x)) called", win, ch&A_CHARTEXT, ch));
|
|
|
|
return wladdch(win, ch, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int wechochar(WINDOW *win, chtype ch)
|
|
|
|
{
|
|
|
|
T(("wechochar(%x,%c (%x)) called", win, ch&A_CHARTEXT, ch));
|
|
|
|
|
|
|
|
return wladdch(win, ch, TRUE);
|
|
|
|
}
|