1 /****************************************************************************
2 * Copyright (c) 2008-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer *
31 * and: Thomas E. Dickey *
32 ****************************************************************************/
34 #include <curses.priv.h>
35 #define CUR TerminalType((TERMINAL*)TCB).
37 #include <termcap.h> /* ospeed */
42 #include <sys/time.h> /* needed for MacOS X DP3 */
47 # if !defined(sun) || !TERMIOS
49 # include <sys/ioctl.h>
54 MODULE_ID("$Id: tinfo_driver.c,v 1.59 2017/09/10 21:08:46 tom Exp $")
57 * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
58 * Solaris, IRIX) define TIOCGWINSZ and struct winsize.
61 # define IOCTL_WINSIZE TIOCGSIZE
62 # define STRUCT_WINSIZE struct ttysize
63 # define WINSIZE_ROWS(n) (int)n.ts_lines
64 # define WINSIZE_COLS(n) (int)n.ts_cols
67 # define IOCTL_WINSIZE TIOCGWINSZ
68 # define STRUCT_WINSIZE struct winsize
69 # define WINSIZE_ROWS(n) (int)n.ws_row
70 # define WINSIZE_COLS(n) (int)n.ws_col
75 * These should be screen structure members. They need to be globals for
76 * historical reasons. So we assign them in start_color() and also in
77 * set_term()'s screen-switching logic.
81 NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
83 return CURRENT_SCREEN ? CURRENT_SCREEN->_pair_count : -1;
86 NCURSES_PUBLIC_VAR(COLORS) (void)
88 return CURRENT_SCREEN ? CURRENT_SCREEN->_color_count : -1;
91 NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
92 NCURSES_EXPORT_VAR(int) COLORS = 0;
95 #define TCBMAGIC NCDRV_MAGIC(NCDRV_TINFO)
96 #define AssertTCB() assert(TCB!=0 && TCB->magic==TCBMAGIC)
97 #define SetSP() assert(TCB->csp!=0); sp = TCB->csp; (void) sp
100 * This routine needs to do all the work to make curscr look
104 drv_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
107 return TINFO_DOUPDATE(TCB->csp);
111 drv_Name(TERMINAL_CONTROL_BLOCK * TCB)
118 get_baudrate(TERMINAL *termp)
122 if (GET_TTY(termp->Filedes, &termp->Nttyb) == OK) {
124 termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
126 termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
130 result = (int) cfgetospeed(&(termp->Nttyb));
131 my_ospeed = (NCURSES_OSPEED) _nc_ospeed(result);
132 #else /* !USE_OLD_TTY */
134 my_ospeed = (NCURSES_OSPEED) cfgetospeed(&(termp->Nttyb));
136 my_ospeed = (NCURSES_OSPEED) termp->Nttyb.sg_ospeed;
138 result = _nc_baudrate(my_ospeed);
140 termp->_baudrate = result;
141 ospeed = (NCURSES_OSPEED) my_ospeed;
145 #define SETUP_FAIL FALSE
148 drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
156 T((T_CALLED("tinfo::drv_CanHandle(%p)"), (void *) TCB));
158 assert(TCB != 0 && tname != 0);
159 termp = (TERMINAL *) TCB;
161 TCB->magic = TCBMAGIC;
163 #if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
164 status = _nc_setup_tinfo(tname, &TerminalType(termp));
169 /* try fallback list if entry on disk */
170 if (status != TGETENT_YES) {
171 const TERMTYPE2 *fallback = _nc_fallback2(tname);
174 TerminalType(termp) = *fallback;
175 status = TGETENT_YES;
179 if (status != TGETENT_YES) {
180 NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx termp);
181 if (status == TGETENT_ERR) {
182 ret_error0(status, "terminals database is inaccessible\n");
183 } else if (status == TGETENT_NO) {
184 ret_error1(status, "unknown terminal type.\n", tname);
188 #if NCURSES_EXT_NUMBERS
189 _nc_export_termtype2(&termp->type, &TerminalType(termp));
195 if (command_character)
196 _nc_tinfo_cmdch(termp, *command_character);
199 * If an application calls setupterm() rather than initscr() or
200 * newterm(), we will not have the def_prog_mode() call in
201 * _nc_setupscreen(). Do it now anyway, so we can initialize the
204 if (sp == 0 && NC_ISATTY(termp->Filedes)) {
207 #if NCURSES_EXT_NUMBERS
208 #define cleanup_termtype() \
209 _nc_free_termtype2(&TerminalType(termp)); \
210 _nc_free_termtype(&termp->type)
212 #define cleanup_termtype() \
213 _nc_free_termtype2(&TerminalType(termp))
218 * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity
219 * check before giving up.
221 if ((VALID_STRING(cursor_address)
222 || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
223 && VALID_STRING(clear_screen)) {
225 ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
228 ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
233 ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
240 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
248 /* FIXME: should make sure that we are not in altchar mode */
251 res = NCURSES_PUTP2("bell", bell);
252 NCURSES_SP_NAME(_nc_flush) (sp);
253 } else if (flash_screen) {
254 res = NCURSES_PUTP2("flash_screen", flash_screen);
255 NCURSES_SP_NAME(_nc_flush) (sp);
259 res = NCURSES_PUTP2("flash_screen", flash_screen);
260 NCURSES_SP_NAME(_nc_flush) (sp);
262 res = NCURSES_PUTP2("bell", bell);
263 NCURSES_SP_NAME(_nc_flush) (sp);
270 * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
271 * to maintain compatibility with a pre-ANSI scheme. The same scheme is
272 * also used in the FreeBSD syscons.
275 toggled_colors(int c)
278 static const int table[] =
279 {0, 4, 2, 6, 1, 5, 3, 7,
280 8, 12, 10, 14, 9, 13, 11, 15};
287 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
293 #if NCURSES_EXT_FUNCS
294 return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
301 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
309 if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
310 #if NCURSES_EXT_FUNCS
311 sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
312 sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
315 sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
316 sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
317 if (sp->_color_pairs != 0) {
318 bool save = sp->_default_color;
319 sp->_default_color = TRUE;
320 NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
324 sp->_default_color = save;
333 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
336 NCURSES_SP_OUTC outc)
344 if (set_a_foreground) {
345 TPUTS_TRACE("set_a_foreground");
346 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
347 TPARM_1(set_a_foreground, color), 1, outc);
349 TPUTS_TRACE("set_foreground");
350 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
351 TPARM_1(set_foreground,
352 toggled_colors(color)), 1, outc);
355 if (set_a_background) {
356 TPUTS_TRACE("set_a_background");
357 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
358 TPARM_1(set_a_background, color), 1, outc);
360 TPUTS_TRACE("set_background");
361 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
362 TPARM_1(set_background,
363 toggled_colors(color)), 1, outc);
369 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
377 if (orig_pair != 0) {
378 NCURSES_PUTP2("orig_pair", orig_pair);
385 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
393 if (orig_colors != 0) {
394 NCURSES_PUTP2("orig_colors", orig_colors);
401 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
405 bool useTioctl = TRUE;
408 sp = TCB->csp; /* can be null here */
411 useEnv = sp->_use_env;
412 useTioctl = sp->use_tioctl;
414 useEnv = _nc_prescreen.use_env;
415 useTioctl = _nc_prescreen.use_tioctl;
418 /* figure out the size of the screen */
419 T(("screen size: terminfo lines = %d columns = %d", lines, columns));
421 *linep = (int) lines;
422 *colp = (int) columns;
424 if (useEnv || useTioctl) {
430 _scrsize(screendata);
431 *colp = screendata[0];
432 *linep = ((sp != 0 && sp->_filtered)
435 T(("EMX screen size: environment LINES = %d COLUMNS = %d",
440 /* try asking the OS */
442 TERMINAL *termp = (TERMINAL *) TCB;
443 if (NC_ISATTY(termp->Filedes)) {
448 if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
449 *linep = ((sp != 0 && sp->_filtered)
451 : WINSIZE_ROWS(size));
452 *colp = WINSIZE_COLS(size);
453 T(("SYS screen size: environment LINES = %d COLUMNS = %d",
461 #endif /* HAVE_SIZECHANGE */
466 * If environment variables are used, update them.
468 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
469 _nc_setenv_num("LINES", *linep);
471 if (_nc_getenv_num("COLUMNS") > 0) {
472 _nc_setenv_num("COLUMNS", *colp);
477 * Finally, look for environment variables.
479 * Solaris lets users override either dimension with an environment
482 if ((value = _nc_getenv_num("LINES")) > 0) {
484 T(("screen size: environment LINES = %d", *linep));
486 if ((value = _nc_getenv_num("COLUMNS")) > 0) {
488 T(("screen size: environment COLUMNS = %d", *colp));
492 /* if we can't get dynamic info about the size, use static */
494 *linep = (int) lines;
497 *colp = (int) columns;
500 /* the ultimate fallback, assume fixed 24x80 size */
509 * Put the derived values back in the screen-size caps, so
510 * tigetnum() and tgetnum() will do the right thing.
512 lines = (short) (*linep);
513 columns = (short) (*colp);
516 T(("screen size is %dx%d", *linep, *colp));
521 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
524 assert(l != 0 && c != 0);
531 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
540 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
542 SCREEN *sp = TCB->csp;
543 TERMINAL *_term = (TERMINAL *) TCB;
549 if (SET_TTY(_term->Filedes, buf) != 0) {
552 if (errno == ENOTTY) {
562 if (GET_TTY(_term->Filedes, buf) != 0) {
574 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
577 TERMINAL *_term = (TERMINAL *) TCB;
583 if (progFlag) /* prog mode */
588 * Turn off the XTABS bit in the tty structure if it was on.
590 if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
592 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
594 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
599 /* reset_prog_mode */
600 if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
603 _nc_keypad(sp, TRUE);
608 } else { /* shell mode */
612 * If XTABS was on, remove the tab and backtab capabilities.
614 if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
616 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
617 tab = back_tab = NULL;
619 if (_term->Ottyb.sg_flags & XTABS)
620 tab = back_tab = NULL;
625 /* reset_shell_mode */
627 _nc_keypad(sp, FALSE);
628 NCURSES_SP_NAME(_nc_flush) (sp);
630 code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
641 NCURSES_SP_NAME(_nc_screen_wrap) (sp);
642 NCURSES_SP_NAME(_nc_mvcur_wrap) (sp); /* wrap up cursor addressing */
647 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
651 # define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
654 drv_screen_init(SCREEN *sp)
656 TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
661 * Check for mismatched graphic-rendition capabilities. Most SVr4
662 * terminfo trees contain entries that have rmul or rmso equated to
663 * sgr0 (Solaris curses copes with those entries). We do this only
664 * for curses, since many termcap applications assume that
665 * smso/rmso and smul/rmul are paired, and will not function
666 * properly if we remove rmso or rmul. Curses applications
667 * shouldn't be looking at this detail.
669 sp->_use_rmso = SGR0_TEST(exit_standout_mode);
670 sp->_use_rmul = SGR0_TEST(exit_underline_mode);
673 * Check whether we can optimize scrolling under dumb terminals in
674 * case we do not have any of these capabilities, scrolling
675 * optimization will be useless.
677 sp->_scrolling = ((scroll_forward && scroll_reverse) ||
685 NCURSES_SP_NAME(baudrate) (sp);
687 NCURSES_SP_NAME(_nc_mvcur_init) (sp);
688 /* initialize terminal to a sane state */
689 NCURSES_SP_NAME(_nc_screen_init) (sp);
693 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
699 trm = (TERMINAL *) TCB;
701 TCB->info.initcolor = VALID_STRING(initialize_color);
702 TCB->info.canchange = can_change;
703 TCB->info.hascolor = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
704 && (((set_foreground != NULL)
705 && (set_background != NULL))
706 || ((set_a_foreground != NULL)
707 && (set_a_background != NULL))
708 || set_color_pair)) ? TRUE : FALSE);
710 TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
712 TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
713 TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
714 TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
715 TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
716 TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
717 TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
719 TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
721 TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
724 * If an application calls setupterm() rather than initscr() or
725 * newterm(), we will not have the def_prog_mode() call in
726 * _nc_setupscreen(). Do it now anyway, so we can initialize the
729 if (NC_ISATTY(trm->Filedes)) {
730 TCB->drv->td_mode(TCB, TRUE, TRUE);
734 #define MAX_PALETTE 8
735 #define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
738 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
745 if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
746 const color_t *tp = InfoOf(sp).defaultPalette;
749 ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
751 tp[f].red, tp[f].green, tp[f].blue,
752 tp[b].red, tp[b].green, tp[b].blue));
754 NCURSES_PUTP2("initialize_pair",
755 TPARM_7(initialize_pair,
757 tp[f].red, tp[f].green, tp[f].blue,
758 tp[b].red, tp[b].green, tp[b].blue));
763 default_fg(SCREEN *sp)
765 #if NCURSES_EXT_FUNCS
766 return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
773 default_bg(SCREEN *sp)
775 #if NCURSES_EXT_FUNCS
776 return sp != 0 ? sp->_default_bg : COLOR_BLACK;
783 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
784 int color, int r, int g, int b)
786 SCREEN *sp = TCB->csp;
789 if (initialize_color != NULL) {
790 NCURSES_PUTP2("initialize_color",
791 TPARM_4(initialize_color, color, r, g, b));
796 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
800 NCURSES_SP_OUTC outc)
802 SCREEN *sp = TCB->csp;
803 int fg = COLOR_DEFAULT;
804 int bg = COLOR_DEFAULT;
811 if (pair < 0 || pair >= COLOR_PAIRS) {
813 } else if (pair != 0) {
814 if (set_color_pair) {
815 TPUTS_TRACE("set_color_pair");
816 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
817 TPARM_1(set_color_pair, pair), 1, outc);
819 } else if (sp != 0) {
820 _nc_pair_content(SP_PARM, pair, &fg, &bg);
826 && _nc_pair_content(SP_PARM, old_pair, &old_fg, &old_bg) != ERR) {
827 if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
828 || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
829 #if NCURSES_EXT_FUNCS
831 * A minor optimization - but extension. If "AX" is specified in
832 * the terminal description, treat it as screen's indicator of ECMA
833 * SGR 39 and SGR 49, and assume the two sequences are independent.
835 if (sp->_has_sgr_39_49
836 && isDefaultColor(old_bg)
837 && !isDefaultColor(old_fg)) {
838 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
839 } else if (sp->_has_sgr_39_49
840 && isDefaultColor(old_fg)
841 && !isDefaultColor(old_bg)) {
842 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
853 #if NCURSES_EXT_FUNCS
854 if (isDefaultColor(fg))
856 if (isDefaultColor(bg))
866 TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
869 if (!isDefaultColor(fg)) {
870 drv_setcolor(TCB, TRUE, fg, outc);
872 if (!isDefaultColor(bg)) {
873 drv_setcolor(TCB, FALSE, bg, outc);
877 #define xterm_kmous "\033[M"
879 init_xterm_mouse(SCREEN *sp)
881 sp->_mouse_type = M_XTERM;
882 sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
883 if (!VALID_STRING(sp->_mouse_xtermcap))
884 sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
888 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
895 /* we know how to recognize mouse events under "xterm" */
897 if (key_mouse != 0) {
898 if (!strcmp(key_mouse, xterm_kmous)
899 || strstr(SP_TERMTYPE term_names, "xterm") != 0) {
900 init_xterm_mouse(sp);
902 } else if (strstr(SP_TERMTYPE term_names, "xterm") != 0) {
903 if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
904 init_xterm_mouse(sp);
910 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
912 EVENTLIST_2nd(_nc_eventlist * evl))
921 if ((sp->_mouse_type == M_SYSMOUSE)
922 && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
927 rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
933 if ((sp->_mouse_type == M_SYSMOUSE)
934 && (sp->_sysmouse_head < sp->_sysmouse_tail)
936 && (errno == EINTR)) {
945 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
947 SCREEN *sp = TCB->csp;
949 return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
953 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
955 SCREEN *sp = TCB->csp;
958 if (labnum > 0 && labnum <= num_labels) {
959 NCURSES_PUTP2("plab_norm",
960 TPARM_2(plab_norm, labnum, text));
965 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
967 SCREEN *sp = TCB->csp;
971 NCURSES_PUTP2("label_on", label_on);
973 NCURSES_PUTP2("label_off", label_off);
978 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
980 SCREEN *sp = TCB->csp;
981 chtype attrs = A_NORMAL;
984 if (enter_alt_charset_mode)
985 attrs |= A_ALTCHARSET;
987 if (enter_blink_mode)
996 if (enter_reverse_mode)
999 if (enter_standout_mode)
1000 attrs |= A_STANDOUT;
1002 if (enter_protected_mode)
1005 if (enter_secure_mode)
1008 if (enter_underline_mode)
1009 attrs |= A_UNDERLINE;
1011 if (sp && sp->_coloron)
1015 if (enter_italics_mode)
1023 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1028 clear_screen = ABSENT_STRING;
1029 cursor_address = ABSENT_STRING;
1030 cursor_down = ABSENT_STRING;
1031 cursor_up = ABSENT_STRING;
1032 parm_down_cursor = ABSENT_STRING;
1033 parm_up_cursor = ABSENT_STRING;
1034 row_address = ABSENT_STRING;
1035 cursor_home = carriage_return;
1037 if (back_color_erase)
1038 clr_eos = ABSENT_STRING;
1042 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1044 SCREEN *sp = TCB->csp;
1048 if (ena_acs != NULL) {
1049 NCURSES_PUTP2("ena_acs", ena_acs);
1051 #if NCURSES_EXT_FUNCS
1053 * Linux console "supports" the "PC ROM" character set by the coincidence
1054 * that smpch/rmpch and smacs/rmacs have the same values. ncurses has
1055 * no codepage support (see SCO Merge for an example). Outside of the
1056 * values defined in acsc, there are no definitions for the "PC ROM"
1057 * character set (assumed by some applications to be codepage 437), but we
1058 * allow those applications to use those codepoints.
1060 * test/blue.c uses this feature.
1062 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1063 if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
1064 PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
1066 for (i = 1; i < ACS_LEN; ++i) {
1067 if (real_map[i] == 0) {
1068 real_map[i] = (chtype) i;
1069 if (real_map != fake_map) {
1071 sp->_screen_acs_map[i] = TRUE;
1078 if (acs_chars != NULL) {
1080 size_t length = strlen(acs_chars);
1082 while (i + 1 < length) {
1083 if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
1084 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
1086 sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1092 /* Show the equivalent mapping, noting if it does not match the
1093 * given attribute, whether by re-ordering or duplication.
1095 if (USE_TRACEF(TRACE_CALLS)) {
1097 char show[ACS_LEN * 2 + 1];
1098 for (n = 1, m = 0; n < ACS_LEN; n++) {
1099 if (real_map[n] != 0) {
1100 show[m++] = (char) n;
1101 show[m++] = (char) ChCharOf(real_map[n]);
1105 if (acs_chars == NULL || strcmp(acs_chars, show))
1106 _tracef("%s acs_chars %s",
1107 (acs_chars == NULL) ? "NULL" : "READ",
1108 _nc_visbuf(acs_chars));
1109 _tracef("%s acs_chars %s",
1112 : (strcmp(acs_chars, show)
1117 _nc_unlock_global(tracef);
1122 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1124 NCURSES_EXPORT(void)
1125 _nc_cookie_init(SCREEN *sp)
1127 bool support_cookies = USE_XMC_SUPPORT;
1128 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1130 if (sp == 0 || !ENSURE_TINFO(sp))
1135 * If we have no magic-cookie support compiled-in, or if it is suppressed
1136 * in the environment, reset the support-flag.
1138 if (magic_cookie_glitch >= 0) {
1139 if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1140 support_cookies = FALSE;
1145 if (!support_cookies && magic_cookie_glitch >= 0) {
1146 T(("will disable attributes to work w/o magic cookies"));
1149 if (magic_cookie_glitch > 0) { /* tvi, wyse */
1151 sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1154 * We "should" treat colors as an attribute. The wyse350 (and its
1155 * clones) appear to be the only ones that have both colors and magic
1159 sp->_xmc_triggers |= A_COLOR;
1162 sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1164 T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1166 * Supporting line-drawing may be possible. But make the regular
1167 * video attributes work first.
1169 acs_chars = ABSENT_STRING;
1170 ena_acs = ABSENT_STRING;
1171 enter_alt_charset_mode = ABSENT_STRING;
1172 exit_alt_charset_mode = ABSENT_STRING;
1175 * To keep the cookie support simple, suppress all of the optimization
1176 * hooks except for clear_screen and the cursor addressing.
1178 if (support_cookies) {
1179 clr_eol = ABSENT_STRING;
1180 clr_eos = ABSENT_STRING;
1181 set_attributes = ABSENT_STRING;
1184 } else if (magic_cookie_glitch == 0) { /* hpterm */
1188 * If magic cookies are not supported, cancel the strings that set
1191 if (!support_cookies && magic_cookie_glitch >= 0) {
1192 magic_cookie_glitch = ABSENT_NUMERIC;
1193 set_attributes = ABSENT_STRING;
1194 enter_blink_mode = ABSENT_STRING;
1195 enter_bold_mode = ABSENT_STRING;
1196 enter_dim_mode = ABSENT_STRING;
1197 enter_reverse_mode = ABSENT_STRING;
1198 enter_standout_mode = ABSENT_STRING;
1199 enter_underline_mode = ABSENT_STRING;
1202 /* initialize normal acs before wide, since we use mapping in the latter */
1203 #if !USE_WIDEC_SUPPORT
1204 if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
1207 enter_alt_charset_mode = NULL;
1208 exit_alt_charset_mode = NULL;
1209 set_attributes = NULL;
1215 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1219 EVENTLIST_2nd(_nc_eventlist * evl))
1226 return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1230 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1233 unsigned char c2 = 0;
1240 # if USE_PTHREADS_EINTR
1241 if ((pthread_self) && (pthread_kill) && (pthread_equal))
1242 _nc_globals.read_thread = pthread_self();
1244 n = (int) read(sp->_ifd, &c2, (size_t) 1);
1245 #if USE_PTHREADS_EINTR
1246 _nc_globals.read_thread = 0;
1253 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1257 struct timespec request, remaining;
1258 request.tv_sec = ms / 1000;
1259 request.tv_nsec = (ms % 1000) * 1000000;
1260 while (nanosleep(&request, &remaining) == -1
1261 && errno == EINTR) {
1262 request = remaining;
1266 _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1272 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1277 rc = NCURSES_PUTP2(name, value);
1283 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1285 int rc = __nc_putp(sp, name, value);
1287 NCURSES_SP_NAME(_nc_flush) (sp);
1293 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1304 (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
1305 } else if (!flag && keypad_local) {
1306 (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
1308 if (flag && !sp->_tried) {
1309 _nc_init_keytry(sp);
1319 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1330 unsigned ch = (unsigned) c;
1332 while ((s = _nc_expand_try(sp->_key_ok,
1333 ch, &count, (size_t) 0)) != 0
1334 && _nc_remove_key(&(sp->_key_ok), ch)) {
1335 code = _nc_add_to_try(&(sp->_keytry), s, ch);
1342 while ((s = _nc_expand_try(sp->_keytry,
1343 ch, &count, (size_t) 0)) != 0
1344 && _nc_remove_key(&(sp->_keytry), ch)) {
1345 code = _nc_add_to_try(&(sp->_key_ok), s, ch);
1357 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1365 T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1367 if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1370 code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1373 code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1376 code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1386 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1392 res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1397 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1399 drv_Name, /* Name */
1400 drv_CanHandle, /* CanHandle */
1401 drv_init, /* init */
1402 drv_release, /* release */
1403 drv_size, /* size */
1404 drv_sgmode, /* sgmode */
1405 drv_conattr, /* conattr */
1406 drv_mvcur, /* hwcur */
1407 drv_mode, /* mode */
1408 drv_rescol, /* rescol */
1409 drv_rescolors, /* rescolors */
1410 drv_setcolor, /* color */
1411 drv_dobeepflash, /* doBeepOrFlash */
1412 drv_initpair, /* initpair */
1413 drv_initcolor, /* initcolor */
1414 drv_do_color, /* docolor */
1415 drv_initmouse, /* initmouse */
1416 drv_testmouse, /* testmouse */
1417 drv_setfilter, /* setfilter */
1418 drv_hwlabel, /* hwlabel */
1419 drv_hwlabelOnOff, /* hwlabelOnOff */
1420 drv_doupdate, /* update */
1421 drv_defaultcolors, /* defaultcolors */
1422 drv_print, /* print */
1423 drv_getsize, /* getsize */
1424 drv_setsize, /* setsize */
1425 drv_initacs, /* initacs */
1426 drv_screen_init, /* scinit */
1427 drv_wrap, /* scexit */
1428 drv_twait, /* twait */
1429 drv_read, /* read */
1431 drv_kpad, /* kpad */
1432 drv_keyok, /* kyOk */
1433 drv_kyExist, /* kyExist */
1434 drv_cursorSet /* cursorSet */