/* PDCurses */12#include <curspriv.h>34/*man-start**************************************************************56insch7-----89### Synopsis1011int insch(chtype ch);12int winsch(WINDOW *win, chtype ch);13int mvinsch(int y, int x, chtype ch);14int mvwinsch(WINDOW *win, int y, int x, chtype ch);1516int insrawch(chtype ch);17int winsrawch(WINDOW *win, chtype ch);18int mvinsrawch(int y, int x, chtype ch);19int mvwinsrawch(WINDOW *win, int y, int x, chtype ch);2021int ins_wch(const cchar_t *wch);22int wins_wch(WINDOW *win, const cchar_t *wch);23int mvins_wch(int y, int x, const cchar_t *wch);24int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch);2526### Description2728The insch() functions insert a chtype into the window at the current29or specified cursor position. The cursor is NOT advanced. A newline30is equivalent to clrtoeol(); tabs are expanded; other control31characters are converted as with unctrl().3233The ins_wch() functions are the wide-character equivalents, taking34cchar_t pointers rather than chtypes.3536Video attributes can be combined with a character by ORing them into37the parameter. Text, including attributes, can be copied from one38place to another using inch() and insch().3940insrawch() etc. are PDCurses-specific wrappers for insch() etc. that41disable the translation of control characters.4243### Return Value4445All functions return OK on success and ERR on error.4647### Portability48X/Open ncurses NetBSD49insch Y Y Y50winsch Y Y Y51mvinsch Y Y Y52mvwinsch Y Y Y53ins_wch Y Y Y54wins_wch Y Y Y55mvins_wch Y Y Y56mvwins_wch Y Y Y57insrawch - - -58winsrawch - - -5960**man-end****************************************************************/6162#include <string.h>6364int winsch(WINDOW *win, chtype ch)65{66int x, y;67chtype attr;68bool xlat;6970PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",71win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));7273if (!win)74return ERR;7576x = win->_curx;77y = win->_cury;7879if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)80return ERR;8182xlat = !SP->raw_out && !(ch & A_ALTCHARSET);83attr = ch & A_ATTRIBUTES;84ch &= A_CHARTEXT;8586if (xlat && (ch < ' ' || ch == 0x7f))87{88int x2;8990switch (ch)91{92case '\t':93for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)94{95if (winsch(win, attr | ' ') == ERR)96return ERR;97}98return OK;99100case '\n':101wclrtoeol(win);102break;103104case 0x7f:105if (winsch(win, attr | '?') == ERR)106return ERR;107108return winsch(win, attr | '^');109110default:111/* handle control chars */112113if (winsch(win, attr | (ch + '@')) == ERR)114return ERR;115116return winsch(win, attr | '^');117}118}119else120{121int maxx;122chtype *temp;123124/* If the incoming character doesn't have its own attribute,125then use the current attributes for the window. If it has126attributes but not a color component, OR the attributes to127the current attributes for the window. If it has a color128component, use the attributes solely from the incoming129character. */130131if (!(attr & A_COLOR))132attr |= win->_attrs;133134/* wrs (4/10/93): Apply the same sort of logic for the window135background, in that it only takes precedence if other color136attributes are not there and that the background character137will only print if the printing character is blank. */138139if (!(attr & A_COLOR))140attr |= win->_bkgd & A_ATTRIBUTES;141else142attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);143144if (ch == ' ')145ch = win->_bkgd & A_CHARTEXT;146147/* Add the attribute back into the character. */148149ch |= attr;150151maxx = win->_maxx;152temp = &win->_y[y][x];153154memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype));155156win->_lastch[y] = maxx - 1;157158if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))159win->_firstch[y] = x;160161*temp = ch;162}163164PDC_sync(win);165166return OK;167}168169int insch(chtype ch)170{171PDC_LOG(("insch() - called\n"));172173return winsch(stdscr, ch);174}175176int mvinsch(int y, int x, chtype ch)177{178PDC_LOG(("mvinsch() - called\n"));179180if (move(y, x) == ERR)181return ERR;182183return winsch(stdscr, ch);184}185186int mvwinsch(WINDOW *win, int y, int x, chtype ch)187{188PDC_LOG(("mvwinsch() - called\n"));189190if (wmove(win, y, x) == ERR)191return ERR;192193return winsch(win, ch);194}195196int winsrawch(WINDOW *win, chtype ch)197{198PDC_LOG(("winsrawch() - called: win=%p ch=%x "199"(char=%c attr=0x%x)\n", win, ch,200ch & A_CHARTEXT, ch & A_ATTRIBUTES));201202if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)203ch |= A_ALTCHARSET;204205return winsch(win, ch);206}207208int insrawch(chtype ch)209{210PDC_LOG(("insrawch() - called\n"));211212return winsrawch(stdscr, ch);213}214215int mvinsrawch(int y, int x, chtype ch)216{217PDC_LOG(("mvinsrawch() - called\n"));218219if (move(y, x) == ERR)220return ERR;221222return winsrawch(stdscr, ch);223}224225int mvwinsrawch(WINDOW *win, int y, int x, chtype ch)226{227PDC_LOG(("mvwinsrawch() - called\n"));228229if (wmove(win, y, x) == ERR)230return ERR;231232return winsrawch(win, ch);233}234235#ifdef PDC_WIDE236int wins_wch(WINDOW *win, const cchar_t *wch)237{238PDC_LOG(("wins_wch() - called\n"));239240return wch ? winsch(win, *wch) : ERR;241}242243int ins_wch(const cchar_t *wch)244{245PDC_LOG(("ins_wch() - called\n"));246247return wins_wch(stdscr, wch);248}249250int mvins_wch(int y, int x, const cchar_t *wch)251{252PDC_LOG(("mvins_wch() - called\n"));253254if (move(y, x) == ERR)255return ERR;256257return wins_wch(stdscr, wch);258}259260int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch)261{262PDC_LOG(("mvwins_wch() - called\n"));263264if (wmove(win, y, x) == ERR)265return ERR;266267return wins_wch(win, wch);268}269#endif270271272