1 /****************************************************************************
2 * Copyright (c) 2008-2018,2019 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.64 2019/07/28 18:43:09 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
150 drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
158 T((T_CALLED("tinfo::drv_CanHandle(%p)"), (void *) TCB));
160 assert(TCB != 0 && tname != 0);
161 termp = (TERMINAL *) TCB;
163 TCB->magic = TCBMAGIC;
165 #if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
166 status = _nc_setup_tinfo(tname, &TerminalType(termp));
167 T(("_nc_setup_tinfo returns %d", status));
169 T(("no database available"));
173 /* try fallback list if entry on disk */
174 if (status != TGETENT_YES) {
175 const TERMTYPE2 *fallback = _nc_fallback2(tname);
178 T(("found fallback entry"));
179 TerminalType(termp) = *fallback;
180 status = TGETENT_YES;
184 if (status != TGETENT_YES) {
185 NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx termp);
186 if (status == TGETENT_ERR) {
187 ret_error0(status, "terminals database is inaccessible\n");
188 } else if (status == TGETENT_NO) {
189 ret_error1(status, "unknown terminal type.\n",
194 #if NCURSES_EXT_NUMBERS
195 _nc_export_termtype2(&termp->type, &TerminalType(termp));
201 if (command_character)
202 _nc_tinfo_cmdch(termp, *command_character);
205 * If an application calls setupterm() rather than initscr() or
206 * newterm(), we will not have the def_prog_mode() call in
207 * _nc_setupscreen(). Do it now anyway, so we can initialize the
210 if (sp == 0 && NC_ISATTY(termp->Filedes)) {
213 #if NCURSES_EXT_NUMBERS
214 #define cleanup_termtype() \
215 _nc_free_termtype2(&TerminalType(termp)); \
216 _nc_free_termtype(&termp->type)
218 #define cleanup_termtype() \
219 _nc_free_termtype2(&TerminalType(termp))
224 * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity
225 * check before giving up.
227 if ((VALID_STRING(cursor_address)
228 || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
229 && VALID_STRING(clear_screen)) {
231 ret_error1(TGETENT_YES, "terminal is not really generic.\n",
235 ret_error1(TGETENT_NO, "I need something more specific.\n",
241 ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n",
249 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
257 /* FIXME: should make sure that we are not in altchar mode */
260 res = NCURSES_PUTP2("bell", bell);
261 NCURSES_SP_NAME(_nc_flush) (sp);
262 } else if (flash_screen) {
263 res = NCURSES_PUTP2("flash_screen", flash_screen);
264 NCURSES_SP_NAME(_nc_flush) (sp);
268 res = NCURSES_PUTP2("flash_screen", flash_screen);
269 NCURSES_SP_NAME(_nc_flush) (sp);
271 res = NCURSES_PUTP2("bell", bell);
272 NCURSES_SP_NAME(_nc_flush) (sp);
279 * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
280 * to maintain compatibility with a pre-ANSI scheme. The same scheme is
281 * also used in the FreeBSD syscons.
284 toggled_colors(int c)
287 static const int table[] =
288 {0, 4, 2, 6, 1, 5, 3, 7,
289 8, 12, 10, 14, 9, 13, 11, 15};
296 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
302 #if NCURSES_EXT_FUNCS
303 return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
310 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
318 if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
319 #if NCURSES_EXT_FUNCS
320 sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
321 sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
324 sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
325 sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
326 if (sp->_color_pairs != 0) {
327 bool save = sp->_default_color;
328 sp->_default_color = TRUE;
329 NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
333 sp->_default_color = save;
342 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
345 NCURSES_SP_OUTC outc)
353 if (set_a_foreground) {
354 TPUTS_TRACE("set_a_foreground");
355 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
356 TPARM_1(set_a_foreground, color), 1, outc);
358 TPUTS_TRACE("set_foreground");
359 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
360 TPARM_1(set_foreground,
361 toggled_colors(color)), 1, outc);
364 if (set_a_background) {
365 TPUTS_TRACE("set_a_background");
366 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
367 TPARM_1(set_a_background, color), 1, outc);
369 TPUTS_TRACE("set_background");
370 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
371 TPARM_1(set_background,
372 toggled_colors(color)), 1, outc);
378 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
386 if (orig_pair != 0) {
387 NCURSES_PUTP2("orig_pair", orig_pair);
394 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
402 if (orig_colors != 0) {
403 NCURSES_PUTP2("orig_colors", orig_colors);
410 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
414 bool useTioctl = TRUE;
417 sp = TCB->csp; /* can be null here */
420 useEnv = sp->_use_env;
421 useTioctl = sp->use_tioctl;
423 useEnv = _nc_prescreen.use_env;
424 useTioctl = _nc_prescreen.use_tioctl;
427 /* figure out the size of the screen */
428 T(("screen size: terminfo lines = %d columns = %d", lines, columns));
430 *linep = (int) lines;
431 *colp = (int) columns;
433 if (useEnv || useTioctl) {
439 _scrsize(screendata);
440 *colp = screendata[0];
441 *linep = ((sp != 0 && sp->_filtered)
444 T(("EMX screen size: environment LINES = %d COLUMNS = %d",
449 /* try asking the OS */
451 TERMINAL *termp = (TERMINAL *) TCB;
452 if (NC_ISATTY(termp->Filedes)) {
457 if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
458 *linep = ((sp != 0 && sp->_filtered)
460 : WINSIZE_ROWS(size));
461 *colp = WINSIZE_COLS(size);
462 T(("SYS screen size: environment LINES = %d COLUMNS = %d",
470 #endif /* HAVE_SIZECHANGE */
475 * If environment variables are used, update them.
477 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
478 _nc_setenv_num("LINES", *linep);
480 if (_nc_getenv_num("COLUMNS") > 0) {
481 _nc_setenv_num("COLUMNS", *colp);
486 * Finally, look for environment variables.
488 * Solaris lets users override either dimension with an environment
491 if ((value = _nc_getenv_num("LINES")) > 0) {
493 T(("screen size: environment LINES = %d", *linep));
495 if ((value = _nc_getenv_num("COLUMNS")) > 0) {
497 T(("screen size: environment COLUMNS = %d", *colp));
501 /* if we can't get dynamic info about the size, use static */
503 *linep = (int) lines;
506 *colp = (int) columns;
509 /* the ultimate fallback, assume fixed 24x80 size */
518 * Put the derived values back in the screen-size caps, so
519 * tigetnum() and tgetnum() will do the right thing.
521 lines = (short) (*linep);
522 columns = (short) (*colp);
525 T(("screen size is %dx%d", *linep, *colp));
530 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
533 assert(l != 0 && c != 0);
540 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
549 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
551 SCREEN *sp = TCB->csp;
552 TERMINAL *_term = (TERMINAL *) TCB;
558 if (SET_TTY(_term->Filedes, buf) != 0) {
561 if (errno == ENOTTY) {
571 if (GET_TTY(_term->Filedes, buf) != 0) {
583 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
586 TERMINAL *_term = (TERMINAL *) TCB;
592 if (progFlag) /* prog mode */
597 * Turn off the XTABS bit in the tty structure if it was on.
599 if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
601 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
603 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
608 /* reset_prog_mode */
609 if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
612 _nc_keypad(sp, TRUE);
617 } else { /* shell mode */
621 * If XTABS was on, remove the tab and backtab capabilities.
623 if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
625 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
626 tab = back_tab = NULL;
628 if (_term->Ottyb.sg_flags & XTABS)
629 tab = back_tab = NULL;
634 /* reset_shell_mode */
636 _nc_keypad(sp, FALSE);
637 NCURSES_SP_NAME(_nc_flush) (sp);
639 code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
650 NCURSES_SP_NAME(_nc_screen_wrap) (sp);
651 NCURSES_SP_NAME(_nc_mvcur_wrap) (sp); /* wrap up cursor addressing */
656 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
660 # define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
663 drv_screen_init(SCREEN *sp)
665 TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
670 * Check for mismatched graphic-rendition capabilities. Most SVr4
671 * terminfo trees contain entries that have rmul or rmso equated to
672 * sgr0 (Solaris curses copes with those entries). We do this only
673 * for curses, since many termcap applications assume that
674 * smso/rmso and smul/rmul are paired, and will not function
675 * properly if we remove rmso or rmul. Curses applications
676 * shouldn't be looking at this detail.
678 sp->_use_rmso = SGR0_TEST(exit_standout_mode);
679 sp->_use_rmul = SGR0_TEST(exit_underline_mode);
682 * Check whether we can optimize scrolling under dumb terminals in
683 * case we do not have any of these capabilities, scrolling
684 * optimization will be useless.
686 sp->_scrolling = ((scroll_forward && scroll_reverse) ||
694 NCURSES_SP_NAME(baudrate) (sp);
696 NCURSES_SP_NAME(_nc_mvcur_init) (sp);
697 /* initialize terminal to a sane state */
698 NCURSES_SP_NAME(_nc_screen_init) (sp);
702 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
708 trm = (TERMINAL *) TCB;
710 TCB->info.initcolor = VALID_STRING(initialize_color);
711 TCB->info.canchange = can_change;
712 TCB->info.hascolor = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
713 && (((set_foreground != NULL)
714 && (set_background != NULL))
715 || ((set_a_foreground != NULL)
716 && (set_a_background != NULL))
717 || set_color_pair)) ? TRUE : FALSE);
719 TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
721 TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
722 TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
723 TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
724 TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
725 TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
726 TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
728 TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
730 TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
733 * If an application calls setupterm() rather than initscr() or
734 * newterm(), we will not have the def_prog_mode() call in
735 * _nc_setupscreen(). Do it now anyway, so we can initialize the
738 if (NC_ISATTY(trm->Filedes)) {
739 TCB->drv->td_mode(TCB, TRUE, TRUE);
743 #define MAX_PALETTE 8
744 #define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
747 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
754 if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
755 const color_t *tp = InfoOf(sp).defaultPalette;
758 ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
760 tp[f].red, tp[f].green, tp[f].blue,
761 tp[b].red, tp[b].green, tp[b].blue));
763 NCURSES_PUTP2("initialize_pair",
764 TPARM_7(initialize_pair,
766 tp[f].red, tp[f].green, tp[f].blue,
767 tp[b].red, tp[b].green, tp[b].blue));
772 default_fg(SCREEN *sp)
774 #if NCURSES_EXT_FUNCS
775 return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
782 default_bg(SCREEN *sp)
784 #if NCURSES_EXT_FUNCS
785 return sp != 0 ? sp->_default_bg : COLOR_BLACK;
792 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
793 int color, int r, int g, int b)
795 SCREEN *sp = TCB->csp;
798 if (initialize_color != NULL) {
799 NCURSES_PUTP2("initialize_color",
800 TPARM_4(initialize_color, color, r, g, b));
805 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
809 NCURSES_SP_OUTC outc)
811 SCREEN *sp = TCB->csp;
812 int fg = COLOR_DEFAULT;
813 int bg = COLOR_DEFAULT;
820 if (pair < 0 || pair >= COLOR_PAIRS) {
822 } else if (pair != 0) {
823 if (set_color_pair) {
824 TPUTS_TRACE("set_color_pair");
825 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
826 TPARM_1(set_color_pair, pair), 1, outc);
828 } else if (sp != 0) {
829 _nc_pair_content(SP_PARM, pair, &fg, &bg);
835 && _nc_pair_content(SP_PARM, old_pair, &old_fg, &old_bg) != ERR) {
836 if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
837 || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
838 #if NCURSES_EXT_FUNCS
840 * A minor optimization - but extension. If "AX" is specified in
841 * the terminal description, treat it as screen's indicator of ECMA
842 * SGR 39 and SGR 49, and assume the two sequences are independent.
844 if (sp->_has_sgr_39_49
845 && isDefaultColor(old_bg)
846 && !isDefaultColor(old_fg)) {
847 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
848 } else if (sp->_has_sgr_39_49
849 && isDefaultColor(old_fg)
850 && !isDefaultColor(old_bg)) {
851 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
862 #if NCURSES_EXT_FUNCS
863 if (isDefaultColor(fg))
865 if (isDefaultColor(bg))
875 TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
878 if (!isDefaultColor(fg)) {
879 drv_setcolor(TCB, TRUE, fg, outc);
881 if (!isDefaultColor(bg)) {
882 drv_setcolor(TCB, FALSE, bg, outc);
886 #define xterm_kmous "\033[M"
888 init_xterm_mouse(SCREEN *sp)
890 sp->_mouse_type = M_XTERM;
891 sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
892 if (!VALID_STRING(sp->_mouse_xtermcap))
893 sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
897 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
904 /* we know how to recognize mouse events under "xterm" */
906 if (NonEmpty(key_mouse)) {
907 init_xterm_mouse(sp);
908 } else if (strstr(SP_TERMTYPE term_names, "xterm") != 0) {
909 if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
910 init_xterm_mouse(sp);
916 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
918 EVENTLIST_2nd(_nc_eventlist * evl))
927 if ((sp->_mouse_type == M_SYSMOUSE)
928 && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
933 rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
939 if ((sp->_mouse_type == M_SYSMOUSE)
940 && (sp->_sysmouse_head < sp->_sysmouse_tail)
942 && (errno == EINTR)) {
951 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
953 SCREEN *sp = TCB->csp;
955 return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
959 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
961 SCREEN *sp = TCB->csp;
964 if (labnum > 0 && labnum <= num_labels) {
965 NCURSES_PUTP2("plab_norm",
966 TPARM_2(plab_norm, labnum, text));
971 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
973 SCREEN *sp = TCB->csp;
977 NCURSES_PUTP2("label_on", label_on);
979 NCURSES_PUTP2("label_off", label_off);
984 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
986 SCREEN *sp = TCB->csp;
987 chtype attrs = A_NORMAL;
990 if (enter_alt_charset_mode)
991 attrs |= A_ALTCHARSET;
993 if (enter_blink_mode)
1002 if (enter_reverse_mode)
1005 if (enter_standout_mode)
1006 attrs |= A_STANDOUT;
1008 if (enter_protected_mode)
1011 if (enter_secure_mode)
1014 if (enter_underline_mode)
1015 attrs |= A_UNDERLINE;
1017 if (sp && sp->_coloron)
1021 if (enter_italics_mode)
1029 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1034 clear_screen = ABSENT_STRING;
1035 cursor_address = ABSENT_STRING;
1036 cursor_down = ABSENT_STRING;
1037 cursor_up = ABSENT_STRING;
1038 parm_down_cursor = ABSENT_STRING;
1039 parm_up_cursor = ABSENT_STRING;
1040 row_address = ABSENT_STRING;
1041 cursor_home = carriage_return;
1043 if (back_color_erase)
1044 clr_eos = ABSENT_STRING;
1048 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1050 SCREEN *sp = TCB->csp;
1054 if (ena_acs != NULL) {
1055 NCURSES_PUTP2("ena_acs", ena_acs);
1057 #if NCURSES_EXT_FUNCS
1059 * Linux console "supports" the "PC ROM" character set by the coincidence
1060 * that smpch/rmpch and smacs/rmacs have the same values. ncurses has
1061 * no codepage support (see SCO Merge for an example). Outside of the
1062 * values defined in acsc, there are no definitions for the "PC ROM"
1063 * character set (assumed by some applications to be codepage 437), but we
1064 * allow those applications to use those codepoints.
1066 * test/blue.c uses this feature.
1068 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1069 if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
1070 PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
1072 for (i = 1; i < ACS_LEN; ++i) {
1073 if (real_map[i] == 0) {
1074 real_map[i] = (chtype) i;
1075 if (real_map != fake_map) {
1077 sp->_screen_acs_map[i] = TRUE;
1084 if (acs_chars != NULL) {
1086 size_t length = strlen(acs_chars);
1088 while (i + 1 < length) {
1089 if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
1090 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
1091 T(("#%d real_map[%s] = %s",
1093 _tracechar(UChar(acs_chars[i])),
1094 _tracechtype(real_map[UChar(acs_chars[i])])));
1096 sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1103 /* Show the equivalent mapping, noting if it does not match the
1104 * given attribute, whether by re-ordering or duplication.
1106 if (USE_TRACEF(TRACE_CALLS)) {
1108 char show[ACS_LEN * 2 + 1];
1109 for (n = 1, m = 0; n < ACS_LEN; n++) {
1110 if (real_map[n] != 0) {
1111 show[m++] = (char) n;
1112 show[m++] = (char) ChCharOf(real_map[n]);
1116 if (acs_chars == NULL || strcmp(acs_chars, show))
1117 _tracef("%s acs_chars %s",
1118 (acs_chars == NULL) ? "NULL" : "READ",
1119 _nc_visbuf(acs_chars));
1120 _tracef("%s acs_chars %s",
1123 : (strcmp(acs_chars, show)
1127 _nc_unlock_global(tracef);
1132 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1134 NCURSES_EXPORT(void)
1135 _nc_cookie_init(SCREEN *sp)
1137 bool support_cookies = USE_XMC_SUPPORT;
1138 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1140 if (sp == 0 || !ENSURE_TINFO(sp))
1145 * If we have no magic-cookie support compiled-in, or if it is suppressed
1146 * in the environment, reset the support-flag.
1148 if (magic_cookie_glitch >= 0) {
1149 if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1150 support_cookies = FALSE;
1155 if (!support_cookies && magic_cookie_glitch >= 0) {
1156 T(("will disable attributes to work w/o magic cookies"));
1159 if (magic_cookie_glitch > 0) { /* tvi, wyse */
1161 sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1164 * We "should" treat colors as an attribute. The wyse350 (and its
1165 * clones) appear to be the only ones that have both colors and magic
1169 sp->_xmc_triggers |= A_COLOR;
1172 sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1174 T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1176 * Supporting line-drawing may be possible. But make the regular
1177 * video attributes work first.
1179 acs_chars = ABSENT_STRING;
1180 ena_acs = ABSENT_STRING;
1181 enter_alt_charset_mode = ABSENT_STRING;
1182 exit_alt_charset_mode = ABSENT_STRING;
1185 * To keep the cookie support simple, suppress all of the optimization
1186 * hooks except for clear_screen and the cursor addressing.
1188 if (support_cookies) {
1189 clr_eol = ABSENT_STRING;
1190 clr_eos = ABSENT_STRING;
1191 set_attributes = ABSENT_STRING;
1194 } else if (magic_cookie_glitch == 0) { /* hpterm */
1198 * If magic cookies are not supported, cancel the strings that set
1201 if (!support_cookies && magic_cookie_glitch >= 0) {
1202 magic_cookie_glitch = ABSENT_NUMERIC;
1203 set_attributes = ABSENT_STRING;
1204 enter_blink_mode = ABSENT_STRING;
1205 enter_bold_mode = ABSENT_STRING;
1206 enter_dim_mode = ABSENT_STRING;
1207 enter_reverse_mode = ABSENT_STRING;
1208 enter_standout_mode = ABSENT_STRING;
1209 enter_underline_mode = ABSENT_STRING;
1212 /* initialize normal acs before wide, since we use mapping in the latter */
1213 #if !USE_WIDEC_SUPPORT
1214 if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
1217 enter_alt_charset_mode = NULL;
1218 exit_alt_charset_mode = NULL;
1219 set_attributes = NULL;
1225 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1229 EVENTLIST_2nd(_nc_eventlist * evl))
1236 return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1240 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1243 unsigned char c2 = 0;
1250 # if USE_PTHREADS_EINTR
1251 if ((pthread_self) && (pthread_kill) && (pthread_equal))
1252 _nc_globals.read_thread = pthread_self();
1254 n = (int) read(sp->_ifd, &c2, (size_t) 1);
1255 #if USE_PTHREADS_EINTR
1256 _nc_globals.read_thread = 0;
1263 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1267 struct timespec request, remaining;
1268 request.tv_sec = ms / 1000;
1269 request.tv_nsec = (ms % 1000) * 1000000;
1270 while (nanosleep(&request, &remaining) == -1
1271 && errno == EINTR) {
1272 request = remaining;
1276 _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1282 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1287 rc = NCURSES_PUTP2(name, value);
1293 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1295 int rc = __nc_putp(sp, name, value);
1297 NCURSES_SP_NAME(_nc_flush) (sp);
1303 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1314 (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
1315 } else if (!flag && keypad_local) {
1316 (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
1318 if (flag && !sp->_tried) {
1319 _nc_init_keytry(sp);
1329 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1340 unsigned ch = (unsigned) c;
1342 while ((s = _nc_expand_try(sp->_key_ok,
1343 ch, &count, (size_t) 0)) != 0
1344 && _nc_remove_key(&(sp->_key_ok), ch)) {
1345 code = _nc_add_to_try(&(sp->_keytry), s, ch);
1352 while ((s = _nc_expand_try(sp->_keytry,
1353 ch, &count, (size_t) 0)) != 0
1354 && _nc_remove_key(&(sp->_keytry), ch)) {
1355 code = _nc_add_to_try(&(sp->_key_ok), s, ch);
1367 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1375 T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1377 if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1380 code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1383 code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1386 code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1396 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1402 res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1407 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1409 drv_Name, /* Name */
1410 drv_CanHandle, /* CanHandle */
1411 drv_init, /* init */
1412 drv_release, /* release */
1413 drv_size, /* size */
1414 drv_sgmode, /* sgmode */
1415 drv_conattr, /* conattr */
1416 drv_mvcur, /* hwcur */
1417 drv_mode, /* mode */
1418 drv_rescol, /* rescol */
1419 drv_rescolors, /* rescolors */
1420 drv_setcolor, /* color */
1421 drv_dobeepflash, /* doBeepOrFlash */
1422 drv_initpair, /* initpair */
1423 drv_initcolor, /* initcolor */
1424 drv_do_color, /* docolor */
1425 drv_initmouse, /* initmouse */
1426 drv_testmouse, /* testmouse */
1427 drv_setfilter, /* setfilter */
1428 drv_hwlabel, /* hwlabel */
1429 drv_hwlabelOnOff, /* hwlabelOnOff */
1430 drv_doupdate, /* update */
1431 drv_defaultcolors, /* defaultcolors */
1432 drv_print, /* print */
1433 drv_getsize, /* getsize */
1434 drv_setsize, /* setsize */
1435 drv_initacs, /* initacs */
1436 drv_screen_init, /* scinit */
1437 drv_wrap, /* scexit */
1438 drv_twait, /* twait */
1439 drv_read, /* read */
1441 drv_kpad, /* kpad */
1442 drv_keyok, /* kyOk */
1443 drv_kyExist, /* kyExist */
1444 drv_cursorSet /* cursorSet */