diff options
Diffstat (limited to 'scripts/kconfig/libcurses/addch.c')
| -rw-r--r-- | scripts/kconfig/libcurses/addch.c | 410 |
1 files changed, 410 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/addch.c b/scripts/kconfig/libcurses/addch.c new file mode 100644 index 000000000..3d1f9c04b --- /dev/null +++ b/scripts/kconfig/libcurses/addch.c | |||
| @@ -0,0 +1,410 @@ | |||
| 1 | /* PDCurses */ | ||
| 2 | |||
| 3 | #include "curspriv.h" | ||
| 4 | |||
| 5 | /*man-start************************************************************** | ||
| 6 | |||
| 7 | addch | ||
| 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 | |||
| 94 | Function | X/Open | ncurses | NetBSD | ||
| 95 | :---------------------|:------:|:-------:|:------: | ||
| 96 | addch | Y | Y | Y | ||
| 97 | waddch | Y | Y | Y | ||
| 98 | mvaddch | Y | Y | Y | ||
| 99 | mvwaddch | Y | Y | Y | ||
| 100 | echochar | Y | Y | Y | ||
| 101 | wechochar | Y | Y | Y | ||
| 102 | add_wch | Y | Y | Y | ||
| 103 | wadd_wch | Y | Y | Y | ||
| 104 | mvadd_wch | Y | Y | Y | ||
| 105 | mvwadd_wch | Y | Y | Y | ||
| 106 | echo_wchar | Y | Y | Y | ||
| 107 | wecho_wchar | Y | Y | Y | ||
| 108 | addrawch | - | - | - | ||
| 109 | waddrawch | - | - | - | ||
| 110 | mvaddrawch | - | - | - | ||
| 111 | mvwaddrawch | - | - | - | ||
| 112 | |||
| 113 | **man-end****************************************************************/ | ||
| 114 | |||
| 115 | int waddch(WINDOW *win, const chtype ch) | ||
| 116 | { | ||
| 117 | int x, y; | ||
| 118 | chtype text, attr; | ||
| 119 | bool xlat; | ||
| 120 | |||
| 121 | PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", | ||
| 122 | win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); | ||
| 123 | |||
| 124 | if (!win || !SP) | ||
| 125 | return ERR; | ||
| 126 | |||
| 127 | x = win->_curx; | ||
| 128 | y = win->_cury; | ||
| 129 | |||
| 130 | if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) | ||
| 131 | return ERR; | ||
| 132 | |||
| 133 | xlat = !SP->raw_out && !(ch & A_ALTCHARSET); | ||
| 134 | text = ch & A_CHARTEXT; | ||
| 135 | attr = ch & A_ATTRIBUTES; | ||
| 136 | |||
| 137 | if (xlat && (text < ' ' || text == 0x7f)) | ||
| 138 | { | ||
| 139 | int x2; | ||
| 140 | |||
| 141 | switch (text) | ||
| 142 | { | ||
| 143 | case '\t': | ||
| 144 | for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) | ||
| 145 | { | ||
| 146 | if (waddch(win, attr | ' ') == ERR) | ||
| 147 | return ERR; | ||
| 148 | |||
| 149 | /* if tab to next line, exit the loop */ | ||
| 150 | |||
| 151 | if (!win->_curx) | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | return OK; | ||
| 155 | |||
| 156 | case '\n': | ||
| 157 | /* if lf -> crlf */ | ||
| 158 | |||
| 159 | if (!SP->raw_out) | ||
| 160 | x = 0; | ||
| 161 | |||
| 162 | wclrtoeol(win); | ||
| 163 | |||
| 164 | if (++y > win->_bmarg) | ||
| 165 | { | ||
| 166 | y--; | ||
| 167 | |||
| 168 | if (wscrl(win, 1) == ERR) | ||
| 169 | return ERR; | ||
| 170 | } | ||
| 171 | |||
| 172 | break; | ||
| 173 | |||
| 174 | case '\b': | ||
| 175 | /* don't back over left margin */ | ||
| 176 | |||
| 177 | if (--x < 0) | ||
| 178 | case '\r': | ||
| 179 | x = 0; | ||
| 180 | |||
| 181 | break; | ||
| 182 | |||
| 183 | case 0x7f: | ||
| 184 | if (waddch(win, attr | '^') == ERR) | ||
| 185 | return ERR; | ||
| 186 | |||
| 187 | return waddch(win, attr | '?'); | ||
| 188 | |||
| 189 | default: | ||
| 190 | /* handle control chars */ | ||
| 191 | |||
| 192 | if (waddch(win, attr | '^') == ERR) | ||
| 193 | return ERR; | ||
| 194 | |||
| 195 | return waddch(win, ch + '@'); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | else | ||
| 199 | { | ||
| 200 | /* If the incoming character doesn't have its own attribute, | ||
| 201 | then use the current attributes for the window. If it has | ||
| 202 | attributes but not a color component, OR the attributes to | ||
| 203 | the current attributes for the window. If it has a color | ||
| 204 | component, use the attributes solely from the incoming | ||
| 205 | character. */ | ||
| 206 | |||
| 207 | if (!(attr & A_COLOR)) | ||
| 208 | attr |= win->_attrs; | ||
| 209 | |||
| 210 | /* wrs (4/10/93): Apply the same sort of logic for the window | ||
| 211 | background, in that it only takes precedence if other color | ||
| 212 | attributes are not there and that the background character | ||
| 213 | will only print if the printing character is blank. */ | ||
| 214 | |||
| 215 | if (!(attr & A_COLOR)) | ||
| 216 | attr |= win->_bkgd & A_ATTRIBUTES; | ||
| 217 | else | ||
| 218 | attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); | ||
| 219 | |||
| 220 | if (text == ' ') | ||
| 221 | text = win->_bkgd & A_CHARTEXT; | ||
| 222 | |||
| 223 | /* Add the attribute back into the character. */ | ||
| 224 | |||
| 225 | text |= attr; | ||
| 226 | |||
| 227 | /* Only change _firstch/_lastch if the character to be added is | ||
| 228 | different from the character/attribute that is already in | ||
| 229 | that position in the window. */ | ||
| 230 | |||
| 231 | if (win->_y[y][x] != text) | ||
| 232 | { | ||
| 233 | if (win->_firstch[y] == _NO_CHANGE) | ||
| 234 | win->_firstch[y] = win->_lastch[y] = x; | ||
| 235 | else | ||
| 236 | if (x < win->_firstch[y]) | ||
| 237 | win->_firstch[y] = x; | ||
| 238 | else | ||
| 239 | if (x > win->_lastch[y]) | ||
| 240 | win->_lastch[y] = x; | ||
| 241 | |||
| 242 | win->_y[y][x] = text; | ||
| 243 | } | ||
| 244 | |||
| 245 | if (++x >= win->_maxx) | ||
| 246 | { | ||
| 247 | /* wrap around test */ | ||
| 248 | |||
| 249 | x = 0; | ||
| 250 | |||
| 251 | if (++y > win->_bmarg) | ||
| 252 | { | ||
| 253 | y--; | ||
| 254 | |||
| 255 | if (wscrl(win, 1) == ERR) | ||
| 256 | { | ||
| 257 | PDC_sync(win); | ||
| 258 | return ERR; | ||
| 259 | } | ||
| 260 | } | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | win->_curx = x; | ||
| 265 | win->_cury = y; | ||
| 266 | |||
| 267 | if (win->_immed) | ||
| 268 | wrefresh(win); | ||
| 269 | if (win->_sync) | ||
| 270 | wsyncup(win); | ||
| 271 | |||
| 272 | return OK; | ||
| 273 | } | ||
| 274 | |||
| 275 | int addch(const chtype ch) | ||
| 276 | { | ||
| 277 | PDC_LOG(("addch() - called: ch=%x\n", ch)); | ||
| 278 | |||
| 279 | return waddch(stdscr, ch); | ||
| 280 | } | ||
| 281 | |||
| 282 | int mvaddch(int y, int x, const chtype ch) | ||
| 283 | { | ||
| 284 | PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y, x, ch)); | ||
| 285 | |||
| 286 | if (move(y,x) == ERR) | ||
| 287 | return ERR; | ||
| 288 | |||
| 289 | return waddch(stdscr, ch); | ||
| 290 | } | ||
| 291 | |||
| 292 | int mvwaddch(WINDOW *win, int y, int x, const chtype ch) | ||
| 293 | { | ||
| 294 | PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win, y, x, ch)); | ||
| 295 | |||
| 296 | if (wmove(win, y, x) == ERR) | ||
| 297 | return ERR; | ||
| 298 | |||
| 299 | return waddch(win, ch); | ||
| 300 | } | ||
| 301 | |||
| 302 | int echochar(const chtype ch) | ||
| 303 | { | ||
| 304 | PDC_LOG(("echochar() - called: ch=%x\n", ch)); | ||
| 305 | |||
| 306 | return wechochar(stdscr, ch); | ||
| 307 | } | ||
| 308 | |||
| 309 | int wechochar(WINDOW *win, const chtype ch) | ||
| 310 | { | ||
| 311 | PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win, ch)); | ||
| 312 | |||
| 313 | if (waddch(win, ch) == ERR) | ||
| 314 | return ERR; | ||
| 315 | |||
| 316 | return wrefresh(win); | ||
| 317 | } | ||
| 318 | |||
| 319 | int waddrawch(WINDOW *win, chtype ch) | ||
| 320 | { | ||
| 321 | PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", | ||
| 322 | win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); | ||
| 323 | |||
| 324 | if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) | ||
| 325 | ch |= A_ALTCHARSET; | ||
| 326 | |||
| 327 | return waddch(win, ch); | ||
| 328 | } | ||
| 329 | |||
| 330 | int addrawch(chtype ch) | ||
| 331 | { | ||
| 332 | PDC_LOG(("addrawch() - called: ch=%x\n", ch)); | ||
| 333 | |||
| 334 | return waddrawch(stdscr, ch); | ||
| 335 | } | ||
| 336 | |||
| 337 | int mvaddrawch(int y, int x, chtype ch) | ||
| 338 | { | ||
| 339 | PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y, x, ch)); | ||
| 340 | |||
| 341 | if (move(y, x) == ERR) | ||
| 342 | return ERR; | ||
| 343 | |||
| 344 | return waddrawch(stdscr, ch); | ||
| 345 | } | ||
| 346 | |||
| 347 | int mvwaddrawch(WINDOW *win, int y, int x, chtype ch) | ||
| 348 | { | ||
| 349 | PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n", | ||
| 350 | win, y, x, ch)); | ||
| 351 | |||
| 352 | if (wmove(win, y, x) == ERR) | ||
| 353 | return ERR; | ||
| 354 | |||
| 355 | return waddrawch(win, ch); | ||
| 356 | } | ||
| 357 | |||
| 358 | #ifdef PDC_WIDE | ||
| 359 | int wadd_wch(WINDOW *win, const cchar_t *wch) | ||
| 360 | { | ||
| 361 | PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch)); | ||
| 362 | |||
| 363 | return wch ? waddch(win, *wch) : ERR; | ||
| 364 | } | ||
| 365 | |||
| 366 | int add_wch(const cchar_t *wch) | ||
| 367 | { | ||
| 368 | PDC_LOG(("add_wch() - called: wch=%x\n", *wch)); | ||
| 369 | |||
| 370 | return wadd_wch(stdscr, wch); | ||
| 371 | } | ||
| 372 | |||
| 373 | int mvadd_wch(int y, int x, const cchar_t *wch) | ||
| 374 | { | ||
| 375 | PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y, x, *wch)); | ||
| 376 | |||
| 377 | if (move(y,x) == ERR) | ||
| 378 | return ERR; | ||
| 379 | |||
| 380 | return wadd_wch(stdscr, wch); | ||
| 381 | } | ||
| 382 | |||
| 383 | int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch) | ||
| 384 | { | ||
| 385 | PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n", | ||
| 386 | win, y, x, *wch)); | ||
| 387 | |||
| 388 | if (wmove(win, y, x) == ERR) | ||
| 389 | return ERR; | ||
| 390 | |||
| 391 | return wadd_wch(win, wch); | ||
| 392 | } | ||
| 393 | |||
| 394 | int echo_wchar(const cchar_t *wch) | ||
| 395 | { | ||
| 396 | PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch)); | ||
| 397 | |||
| 398 | return wecho_wchar(stdscr, wch); | ||
| 399 | } | ||
| 400 | |||
| 401 | int wecho_wchar(WINDOW *win, const cchar_t *wch) | ||
| 402 | { | ||
| 403 | PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win, *wch)); | ||
| 404 | |||
| 405 | if (!wch || (wadd_wch(win, wch) == ERR)) | ||
| 406 | return ERR; | ||
| 407 | |||
| 408 | return wrefresh(win); | ||
| 409 | } | ||
| 410 | #endif | ||
