soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / insch.c
blob67b9f4784b9ca11294201d2ce9ac2c3c37f210a9
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: insch.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: insch
11 Synopsis:
12 int insch(chtype ch);
13 int winsch(WINDOW *win, chtype ch);
14 int mvinsch(int y, int x, chtype ch);
15 int mvwinsch(WINDOW *win, int y, int x, chtype ch);
17 int insrawch(chtype ch);
18 int winsrawch(WINDOW *win, chtype ch);
19 int mvinsrawch(int y, int x, chtype ch);
20 int mvwinsrawch(WINDOW *win, int y, int x, chtype ch);
22 int ins_wch(const cchar_t *wch);
23 int wins_wch(WINDOW *win, const cchar_t *wch);
24 int mvins_wch(int y, int x, const cchar_t *wch);
25 int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch);
27 Description:
28 The insch() functions insert a chtype into the window at the
29 current or specified cursor position. The cursor is NOT
30 advanced. A newline is equivalent to clrtoeol(); tabs are
31 expanded; other control characters are converted as with
32 unctrl().
34 The ins_wch() functions are the wide-character
35 equivalents, taking cchar_t pointers rather than chtypes.
37 Video attributes can be combined with a character by ORing
38 them into the parameter. Text, including attributes, can be
39 copied from one place to another using inch() and insch().
41 insrawch() etc. are PDCurses-specific wrappers for insch() etc.
42 that disable the translation of control characters.
44 Return Value:
45 All functions return OK on success and ERR on error.
47 Portability X/Open BSD SYS V
48 insch Y Y Y
49 winsch Y Y Y
50 mvinsch Y Y Y
51 mvwinsch Y Y Y
52 insrawch - - -
53 winsrawch - - -
54 ins_wch Y
55 wins_wch Y
56 mvins_wch Y
57 mvwins_wch Y
59 **man-end****************************************************************/
61 #include <string.h>
63 int winsch(WINDOW *win, chtype ch)
65 int x, y;
66 chtype attr;
67 bool xlat;
69 PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
70 win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
72 if (!win)
73 return ERR;
75 x = win->_curx;
76 y = win->_cury;
78 if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
79 return ERR;
81 xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
82 attr = ch & A_ATTRIBUTES;
83 ch &= A_CHARTEXT;
85 if (xlat && (ch < ' ' || ch == 0x7f))
87 int x2;
89 switch (ch)
91 case '\t':
92 for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
94 if (winsch(win, attr | ' ') == ERR)
95 return ERR;
97 return OK;
99 case '\n':
100 wclrtoeol(win);
101 break;
103 case 0x7f:
104 if (winsch(win, attr | '?') == ERR)
105 return ERR;
107 return winsch(win, attr | '^');
109 default:
110 /* handle control chars */
112 if (winsch(win, attr | (ch + '@')) == ERR)
113 return ERR;
115 return winsch(win, attr | '^');
118 else
120 int maxx;
121 chtype *temp;
123 /* If the incoming character doesn't have its own attribute,
124 then use the current attributes for the window. If it has
125 attributes but not a color component, OR the attributes to
126 the current attributes for the window. If it has a color
127 component, use the attributes solely from the incoming
128 character. */
130 if (!(attr & A_COLOR))
131 attr |= win->_attrs;
133 /* wrs (4/10/93): Apply the same sort of logic for the window
134 background, in that it only takes precedence if other color
135 attributes are not there and that the background character
136 will only print if the printing character is blank. */
138 if (!(attr & A_COLOR))
139 attr |= win->_bkgd & A_ATTRIBUTES;
140 else
141 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
143 if (ch == ' ')
144 ch = win->_bkgd & A_CHARTEXT;
146 /* Add the attribute back into the character. */
148 ch |= attr;
150 maxx = win->_maxx;
151 temp = &win->_y[y][x];
153 memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype));
155 win->_lastch[y] = maxx - 1;
157 if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
158 win->_firstch[y] = x;
160 *temp = ch;
163 PDC_sync(win);
165 return OK;
168 int insch(chtype ch)
170 PDC_LOG(("insch() - called\n"));
172 return winsch(stdscr, ch);
175 int mvinsch(int y, int x, chtype ch)
177 PDC_LOG(("mvinsch() - called\n"));
179 if (move(y, x) == ERR)
180 return ERR;
182 return winsch(stdscr, ch);
185 int mvwinsch(WINDOW *win, int y, int x, chtype ch)
187 PDC_LOG(("mvwinsch() - called\n"));
189 if (wmove(win, y, x) == ERR)
190 return ERR;
192 return winsch(win, ch);
195 int winsrawch(WINDOW *win, chtype ch)
197 PDC_LOG(("winsrawch() - called: win=%p ch=%x "
198 "(char=%c attr=0x%x)\n", win, ch,
199 ch & A_CHARTEXT, ch & A_ATTRIBUTES));
201 if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
202 ch |= A_ALTCHARSET;
204 return winsch(win, ch);
207 int insrawch(chtype ch)
209 PDC_LOG(("insrawch() - called\n"));
211 return winsrawch(stdscr, ch);
214 int mvinsrawch(int y, int x, chtype ch)
216 PDC_LOG(("mvinsrawch() - called\n"));
218 if (move(y, x) == ERR)
219 return ERR;
221 return winsrawch(stdscr, ch);
224 int mvwinsrawch(WINDOW *win, int y, int x, chtype ch)
226 PDC_LOG(("mvwinsrawch() - called\n"));
228 if (wmove(win, y, x) == ERR)
229 return ERR;
231 return winsrawch(win, ch);
234 #ifdef PDC_WIDE
235 int wins_wch(WINDOW *win, const cchar_t *wch)
237 PDC_LOG(("wins_wch() - called\n"));
239 return wch ? winsch(win, *wch) : ERR;
242 int ins_wch(const cchar_t *wch)
244 PDC_LOG(("ins_wch() - called\n"));
246 return wins_wch(stdscr, wch);
249 int mvins_wch(int y, int x, const cchar_t *wch)
251 PDC_LOG(("mvins_wch() - called\n"));
253 if (move(y, x) == ERR)
254 return ERR;
256 return wins_wch(stdscr, wch);
259 int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch)
261 PDC_LOG(("mvwins_wch() - called\n"));
263 if (wmove(win, y, x) == ERR)
264 return ERR;
266 return wins_wch(win, wch);
268 #endif