aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/libcurses/addch.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/libcurses/addch.c')
-rw-r--r--scripts/kconfig/libcurses/addch.c408
1 files changed, 408 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/addch.c b/scripts/kconfig/libcurses/addch.c
new file mode 100644
index 000000000..f3c25d389
--- /dev/null
+++ b/scripts/kconfig/libcurses/addch.c
@@ -0,0 +1,408 @@
1/* PDCurses */
2
3#include "curspriv.h"
4
5/*man-start**************************************************************
6
7addch
8-----
9
10### Synopsis
11
12 int addch(const chtype ch);
13 int waddch(WINDOW *win, const chtype ch);
14 int mvaddch(int y, int x, const chtype ch);
15 int mvwaddch(WINDOW *win, int y, int x, const chtype ch);
16 int echochar(const chtype ch);
17 int wechochar(WINDOW *win, const chtype ch);
18
19 int addrawch(chtype ch);
20 int waddrawch(WINDOW *win, chtype ch);
21 int mvaddrawch(int y, int x, chtype ch);
22 int mvwaddrawch(WINDOW *win, int y, int x, chtype ch);
23
24 int add_wch(const cchar_t *wch);
25 int wadd_wch(WINDOW *win, const cchar_t *wch);
26 int mvadd_wch(int y, int x, const cchar_t *wch);
27 int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch);
28 int echo_wchar(const cchar_t *wch);
29 int wecho_wchar(WINDOW *win, const cchar_t *wch);
30
31### Description
32
33 addch() adds the chtype ch to the default window (stdscr) at the
34 current cursor position, and advances the cursor. Note that chtypes
35 can convey both text (a single character) and attributes, including a
36 color pair. add_wch() is the wide-character version of this function,
37 taking a pointer to a cchar_t instead of a chtype.
38
39 waddch() is like addch(), but also lets you specify the window. (This
40 is in fact the core output routine.) wadd_wch() is the wide version.
41
42 mvaddch() moves the cursor to the specified (y, x) position, and adds
43 ch to stdscr. mvadd_wch() is the wide version.
44
45 mvwaddch() moves the cursor to the specified position and adds ch to
46 the specified window. mvwadd_wch() is the wide version.
47
48 echochar() adds ch to stdscr at the current cursor position and calls
49 refresh(). echo_wchar() is the wide version.
50
51 wechochar() adds ch to the specified window and calls wrefresh().
52 wecho_wchar() is the wide version.
53
54 addrawch(), waddrawch(), mvaddrawch() and mvwaddrawch() are PDCurses-
55 specific wrappers for addch() etc. that disable the translation of
56 control characters.
57
58 The following applies to all these functions:
59
60 If the cursor moves on to the right margin, an automatic newline is
61 performed. If scrollok is enabled, and a character is added to the
62 bottom right corner of the window, the scrolling region will be
63 scrolled up one line. If scrolling is not allowed, ERR will be
64 returned.
65
66 If ch is a tab, newline, or backspace, the cursor will be moved
67 appropriately within the window. If ch is a newline, the clrtoeol
68 routine is called before the cursor is moved to the beginning of the
69 next line. If newline mapping is off, the cursor will be moved to
70 the next line, but the x coordinate will be unchanged. If ch is a
71 tab the cursor is moved to the next tab position within the window.
72 If ch is another control character, it will be drawn in the ^X
73 notation. Calling the inch() routine after adding a control
74 character returns the representation of the control character, not
75 the control character.
76
77 Video attributes can be combined with a character by ORing them into
78 the parameter. Text, including attributes, can be copied from one
79 place to another by using inch() and addch().
80
81 Note that in PDCurses, for now, a cchar_t and a chtype are the same.
82 The text field is 16 bits wide, and is treated as Unicode (UCS-2)
83 when PDCurses is built with wide-character support (define PDC_WIDE).
84 So, in functions that take a chtype, like addch(), both the wide and
85 narrow versions will handle Unicode. But for portability, you should
86 use the wide functions.
87
88### Return Value
89
90 All functions return OK on success and ERR on error.
91
92### Portability
93 X/Open ncurses NetBSD
94 addch Y Y Y
95 waddch Y Y Y
96 mvaddch Y Y Y
97 mvwaddch Y Y Y
98 echochar Y Y Y
99 wechochar Y Y Y
100 add_wch Y Y Y
101 wadd_wch Y Y Y
102 mvadd_wch Y Y Y
103 mvwadd_wch Y Y Y
104 echo_wchar Y Y Y
105 wecho_wchar Y Y Y
106 addrawch - - -
107 waddrawch - - -
108 mvaddrawch - - -
109 mvwaddrawch - - -
110
111**man-end****************************************************************/
112
113int waddch(WINDOW *win, const chtype ch)
114{
115 int x, y;
116 chtype text, attr;
117 bool xlat;
118
119 PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
120 win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
121
122 if (!win || !SP)
123 return ERR;
124
125 x = win->_curx;
126 y = win->_cury;
127
128 if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
129 return ERR;
130
131 xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
132 text = ch & A_CHARTEXT;
133 attr = ch & A_ATTRIBUTES;
134
135 if (xlat && (text < ' ' || text == 0x7f))
136 {
137 int x2;
138
139 switch (text)
140 {
141 case '\t':
142 for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
143 {
144 if (waddch(win, attr | ' ') == ERR)
145 return ERR;
146
147 /* if tab to next line, exit the loop */
148
149 if (!win->_curx)
150 break;
151 }
152 return OK;
153
154 case '\n':
155 /* if lf -> crlf */
156
157 if (!SP->raw_out)
158 x = 0;
159
160 wclrtoeol(win);
161
162 if (++y > win->_bmarg)
163 {
164 y--;
165
166 if (wscrl(win, 1) == ERR)
167 return ERR;
168 }
169
170 break;
171
172 case '\b':
173 /* don't back over left margin */
174
175 if (--x < 0)
176 case '\r':
177 x = 0;
178
179 break;
180
181 case 0x7f:
182 if (waddch(win, attr | '^') == ERR)
183 return ERR;
184
185 return waddch(win, attr | '?');
186
187 default:
188 /* handle control chars */
189
190 if (waddch(win, attr | '^') == ERR)
191 return ERR;
192
193 return waddch(win, ch + '@');
194 }
195 }
196 else
197 {
198 /* If the incoming character doesn't have its own attribute,
199 then use the current attributes for the window. If it has
200 attributes but not a color component, OR the attributes to
201 the current attributes for the window. If it has a color
202 component, use the attributes solely from the incoming
203 character. */
204
205 if (!(attr & A_COLOR))
206 attr |= win->_attrs;
207
208 /* wrs (4/10/93): Apply the same sort of logic for the window
209 background, in that it only takes precedence if other color
210 attributes are not there and that the background character
211 will only print if the printing character is blank. */
212
213 if (!(attr & A_COLOR))
214 attr |= win->_bkgd & A_ATTRIBUTES;
215 else
216 attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
217
218 if (text == ' ')
219 text = win->_bkgd & A_CHARTEXT;
220
221 /* Add the attribute back into the character. */
222
223 text |= attr;
224
225 /* Only change _firstch/_lastch if the character to be added is
226 different from the character/attribute that is already in
227 that position in the window. */
228
229 if (win->_y[y][x] != text)
230 {
231 if (win->_firstch[y] == _NO_CHANGE)
232 win->_firstch[y] = win->_lastch[y] = x;
233 else
234 if (x < win->_firstch[y])
235 win->_firstch[y] = x;
236 else
237 if (x > win->_lastch[y])
238 win->_lastch[y] = x;
239
240 win->_y[y][x] = text;
241 }
242
243 if (++x >= win->_maxx)
244 {
245 /* wrap around test */
246
247 x = 0;
248
249 if (++y > win->_bmarg)
250 {
251 y--;
252
253 if (wscrl(win, 1) == ERR)
254 {
255 PDC_sync(win);
256 return ERR;
257 }
258 }
259 }
260 }
261
262 win->_curx = x;
263 win->_cury = y;
264
265 if (win->_immed)
266 wrefresh(win);
267 if (win->_sync)
268 wsyncup(win);
269
270 return OK;
271}
272
273int addch(const chtype ch)
274{
275 PDC_LOG(("addch() - called: ch=%x\n", ch));
276
277 return waddch(stdscr, ch);
278}
279
280int mvaddch(int y, int x, const chtype ch)
281{
282 PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y, x, ch));
283
284 if (move(y,x) == ERR)
285 return ERR;
286
287 return waddch(stdscr, ch);
288}
289
290int mvwaddch(WINDOW *win, int y, int x, const chtype ch)
291{
292 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win, y, x, ch));
293
294 if (wmove(win, y, x) == ERR)
295 return ERR;
296
297 return waddch(win, ch);
298}
299
300int echochar(const chtype ch)
301{
302 PDC_LOG(("echochar() - called: ch=%x\n", ch));
303
304 return wechochar(stdscr, ch);
305}
306
307int wechochar(WINDOW *win, const chtype ch)
308{
309 PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win, ch));
310
311 if (waddch(win, ch) == ERR)
312 return ERR;
313
314 return wrefresh(win);
315}
316
317int waddrawch(WINDOW *win, chtype ch)
318{
319 PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
320 win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
321
322 if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
323 ch |= A_ALTCHARSET;
324
325 return waddch(win, ch);
326}
327
328int addrawch(chtype ch)
329{
330 PDC_LOG(("addrawch() - called: ch=%x\n", ch));
331
332 return waddrawch(stdscr, ch);
333}
334
335int mvaddrawch(int y, int x, chtype ch)
336{
337 PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y, x, ch));
338
339 if (move(y, x) == ERR)
340 return ERR;
341
342 return waddrawch(stdscr, ch);
343}
344
345int mvwaddrawch(WINDOW *win, int y, int x, chtype ch)
346{
347 PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n",
348 win, y, x, ch));
349
350 if (wmove(win, y, x) == ERR)
351 return ERR;
352
353 return waddrawch(win, ch);
354}
355
356#ifdef PDC_WIDE
357int wadd_wch(WINDOW *win, const cchar_t *wch)
358{
359 PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch));
360
361 return wch ? waddch(win, *wch) : ERR;
362}
363
364int add_wch(const cchar_t *wch)
365{
366 PDC_LOG(("add_wch() - called: wch=%x\n", *wch));
367
368 return wadd_wch(stdscr, wch);
369}
370
371int mvadd_wch(int y, int x, const cchar_t *wch)
372{
373 PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y, x, *wch));
374
375 if (move(y,x) == ERR)
376 return ERR;
377
378 return wadd_wch(stdscr, wch);
379}
380
381int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch)
382{
383 PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n",
384 win, y, x, *wch));
385
386 if (wmove(win, y, x) == ERR)
387 return ERR;
388
389 return wadd_wch(win, wch);
390}
391
392int echo_wchar(const cchar_t *wch)
393{
394 PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch));
395
396 return wecho_wchar(stdscr, wch);
397}
398
399int wecho_wchar(WINDOW *win, const cchar_t *wch)
400{
401 PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win, *wch));
402
403 if (!wch || (wadd_wch(win, wch) == ERR))
404 return ERR;
405
406 return wrefresh(win);
407}
408#endif