#include <curspriv.h>
#include <string.h>
int winsch(WINDOW *win, chtype ch)
{
int x, y;
chtype attr;
bool xlat;
PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if (!win)
return ERR;
x = win->_curx;
y = win->_cury;
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
return ERR;
xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
attr = ch & A_ATTRIBUTES;
ch &= A_CHARTEXT;
if (xlat && (ch < ' ' || ch == 0x7f))
{
int x2;
switch ((int)ch)
{
case '\t':
for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
{
if (winsch(win, attr | ' ') == ERR)
return ERR;
}
return OK;
case '\n':
wclrtoeol(win);
break;
case 0x7f:
if (winsch(win, attr | '?') == ERR)
return ERR;
return winsch(win, attr | '^');
default:
if (winsch(win, attr | (ch + '@')) == ERR)
return ERR;
return winsch(win, attr | '^');
}
}
else
{
int maxx;
chtype *temp;
if (!(attr & A_COLOR))
attr |= win->_attrs;
if (!(attr & A_COLOR))
attr |= win->_bkgd & A_ATTRIBUTES;
else
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
if (ch == ' ')
ch = win->_bkgd & A_CHARTEXT;
ch |= attr;
maxx = win->_maxx;
temp = &win->_y[y][x];
memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype));
win->_lastch[y] = maxx - 1;
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
win->_firstch[y] = x;
*temp = ch;
}
PDC_sync(win);
return OK;
}
int insch(chtype ch)
{
PDC_LOG(("insch() - called\n"));
return winsch(stdscr, ch);
}
int mvinsch(int y, int x, chtype ch)
{
PDC_LOG(("mvinsch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winsch(stdscr, ch);
}
int mvwinsch(WINDOW *win, int y, int x, chtype ch)
{
PDC_LOG(("mvwinsch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winsch(win, ch);
}
int winsrawch(WINDOW *win, chtype ch)
{
PDC_LOG(("winsrawch() - called: win=%p ch=%x "
"(char=%c attr=0x%x)\n", win, ch,
ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
ch |= A_ALTCHARSET;
return winsch(win, ch);
}
int insrawch(chtype ch)
{
PDC_LOG(("insrawch() - called\n"));
return winsrawch(stdscr, ch);
}
int mvinsrawch(int y, int x, chtype ch)
{
PDC_LOG(("mvinsrawch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winsrawch(stdscr, ch);
}
int mvwinsrawch(WINDOW *win, int y, int x, chtype ch)
{
PDC_LOG(("mvwinsrawch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winsrawch(win, ch);
}
#ifdef PDC_WIDE
int wins_wch(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wins_wch() - called\n"));
return wch ? winsch(win, *wch) : ERR;
}
int ins_wch(const cchar_t *wch)
{
PDC_LOG(("ins_wch() - called\n"));
return wins_wch(stdscr, wch);
}
int mvins_wch(int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvins_wch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wins_wch(stdscr, wch);
}
int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvwins_wch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wins_wch(win, wch);
}
#endif