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 *
32 ****************************************************************************/
34 #include <curses.priv.h>
35 #define CUR ((TERMINAL*)TCB)->type.
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.44 2017/01/07 16:34:52 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)"), 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, &termp->type);
169 /* try fallback list if entry on disk */
170 if (status != TGETENT_YES) {
171 const TERMTYPE *fallback = _nc_fallback(tname);
174 termp->type = *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);
189 #define MY_SIZE (size_t) NAMESIZE - 1
190 _nc_STRNCPY(ttytype, termp->type.term_names, MY_SIZE);
191 ttytype[MY_SIZE] = '\0';
194 if (command_character)
195 _nc_tinfo_cmdch(termp, *command_character);
198 * If an application calls setupterm() rather than initscr() or
199 * newterm(), we will not have the def_prog_mode() call in
200 * _nc_setupscreen(). Do it now anyway, so we can initialize the
203 if (sp == 0 && NC_ISATTY(termp->Filedes)) {
209 * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity
210 * check before giving up.
212 if ((VALID_STRING(cursor_address)
213 || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
214 && VALID_STRING(clear_screen)) {
215 ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
217 ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
221 ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
228 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
236 /* FIXME: should make sure that we are not in altchar mode */
239 res = NCURSES_PUTP2("bell", bell);
240 NCURSES_SP_NAME(_nc_flush) (sp);
241 } else if (flash_screen) {
242 res = NCURSES_PUTP2("flash_screen", flash_screen);
243 NCURSES_SP_NAME(_nc_flush) (sp);
247 res = NCURSES_PUTP2("flash_screen", flash_screen);
248 NCURSES_SP_NAME(_nc_flush) (sp);
250 res = NCURSES_PUTP2("bell", bell);
251 NCURSES_SP_NAME(_nc_flush) (sp);
258 * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
259 * to maintain compatibility with a pre-ANSI scheme. The same scheme is
260 * also used in the FreeBSD syscons.
263 toggled_colors(int c)
266 static const int table[] =
267 {0, 4, 2, 6, 1, 5, 3, 7,
268 8, 12, 10, 14, 9, 13, 11, 15};
275 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
281 #if NCURSES_EXT_FUNCS
282 return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
289 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
297 if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
298 #if NCURSES_EXT_FUNCS
299 sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
300 sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
303 sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK);
304 sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK);
305 if (sp->_color_pairs != 0) {
306 bool save = sp->_default_color;
307 sp->_default_color = TRUE;
308 NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
312 sp->_default_color = save;
321 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
324 NCURSES_SP_OUTC outc)
332 if (set_a_foreground) {
333 TPUTS_TRACE("set_a_foreground");
334 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
335 TPARM_1(set_a_foreground, color), 1, outc);
337 TPUTS_TRACE("set_foreground");
338 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
339 TPARM_1(set_foreground,
340 toggled_colors(color)), 1, outc);
343 if (set_a_background) {
344 TPUTS_TRACE("set_a_background");
345 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
346 TPARM_1(set_a_background, color), 1, outc);
348 TPUTS_TRACE("set_background");
349 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
350 TPARM_1(set_background,
351 toggled_colors(color)), 1, outc);
357 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
365 if (orig_pair != 0) {
366 NCURSES_PUTP2("orig_pair", orig_pair);
373 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
381 if (orig_colors != 0) {
382 NCURSES_PUTP2("orig_colors", orig_colors);
389 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
393 bool useTioctl = TRUE;
396 sp = TCB->csp; /* can be null here */
399 useEnv = sp->_use_env;
400 useTioctl = sp->use_tioctl;
402 useEnv = _nc_prescreen.use_env;
403 useTioctl = _nc_prescreen.use_tioctl;
406 /* figure out the size of the screen */
407 T(("screen size: terminfo lines = %d columns = %d", lines, columns));
409 *linep = (int) lines;
410 *colp = (int) columns;
412 if (useEnv || useTioctl) {
418 _scrsize(screendata);
419 *colp = screendata[0];
420 *linep = ((sp != 0 && sp->_filtered)
423 T(("EMX screen size: environment LINES = %d COLUMNS = %d",
428 /* try asking the OS */
430 TERMINAL *termp = (TERMINAL *) TCB;
431 if (NC_ISATTY(termp->Filedes)) {
436 if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
437 *linep = ((sp != 0 && sp->_filtered)
439 : WINSIZE_ROWS(size));
440 *colp = WINSIZE_COLS(size);
441 T(("SYS screen size: environment LINES = %d COLUMNS = %d",
449 #endif /* HAVE_SIZECHANGE */
454 * If environment variables are used, update them.
456 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
457 _nc_setenv_num("LINES", *linep);
459 if (_nc_getenv_num("COLUMNS") > 0) {
460 _nc_setenv_num("COLUMNS", *colp);
465 * Finally, look for environment variables.
467 * Solaris lets users override either dimension with an environment
470 if ((value = _nc_getenv_num("LINES")) > 0) {
472 T(("screen size: environment LINES = %d", *linep));
474 if ((value = _nc_getenv_num("COLUMNS")) > 0) {
476 T(("screen size: environment COLUMNS = %d", *colp));
480 /* if we can't get dynamic info about the size, use static */
482 *linep = (int) lines;
485 *colp = (int) columns;
488 /* the ultimate fallback, assume fixed 24x80 size */
497 * Put the derived values back in the screen-size caps, so
498 * tigetnum() and tgetnum() will do the right thing.
500 lines = (short) (*linep);
501 columns = (short) (*colp);
504 T(("screen size is %dx%d", *linep, *colp));
509 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
512 assert(l != 0 && c != 0);
519 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
528 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
530 SCREEN *sp = TCB->csp;
531 TERMINAL *_term = (TERMINAL *) TCB;
537 if (SET_TTY(_term->Filedes, buf) != 0) {
540 if (errno == ENOTTY) {
550 if (GET_TTY(_term->Filedes, buf) != 0) {
562 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
565 TERMINAL *_term = (TERMINAL *) TCB;
571 if (progFlag) /* prog mode */
576 * Turn off the XTABS bit in the tty structure if it was on.
578 if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
580 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
582 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
587 /* reset_prog_mode */
588 if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
591 _nc_keypad(sp, TRUE);
596 } else { /* shell mode */
600 * If XTABS was on, remove the tab and backtab capabilities.
602 if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
604 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
605 tab = back_tab = NULL;
607 if (_term->Ottyb.sg_flags & XTABS)
608 tab = back_tab = NULL;
613 /* reset_shell_mode */
615 _nc_keypad(sp, FALSE);
616 NCURSES_SP_NAME(_nc_flush) (sp);
618 code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
629 NCURSES_SP_NAME(_nc_screen_wrap) (sp);
630 NCURSES_SP_NAME(_nc_mvcur_wrap) (sp); /* wrap up cursor addressing */
635 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
639 # define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
642 drv_screen_init(SCREEN *sp)
644 TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
649 * Check for mismatched graphic-rendition capabilities. Most SVr4
650 * terminfo trees contain entries that have rmul or rmso equated to
651 * sgr0 (Solaris curses copes with those entries). We do this only
652 * for curses, since many termcap applications assume that
653 * smso/rmso and smul/rmul are paired, and will not function
654 * properly if we remove rmso or rmul. Curses applications
655 * shouldn't be looking at this detail.
657 sp->_use_rmso = SGR0_TEST(exit_standout_mode);
658 sp->_use_rmul = SGR0_TEST(exit_underline_mode);
661 * Check whether we can optimize scrolling under dumb terminals in
662 * case we do not have any of these capabilities, scrolling
663 * optimization will be useless.
665 sp->_scrolling = ((scroll_forward && scroll_reverse) ||
673 NCURSES_SP_NAME(baudrate) (sp);
675 NCURSES_SP_NAME(_nc_mvcur_init) (sp);
676 /* initialize terminal to a sane state */
677 NCURSES_SP_NAME(_nc_screen_init) (sp);
681 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
687 trm = (TERMINAL *) TCB;
689 TCB->info.initcolor = VALID_STRING(initialize_color);
690 TCB->info.canchange = can_change;
691 TCB->info.hascolor = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
692 && (((set_foreground != NULL)
693 && (set_background != NULL))
694 || ((set_a_foreground != NULL)
695 && (set_a_background != NULL))
696 || set_color_pair)) ? TRUE : FALSE);
698 TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
700 TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
701 TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
702 TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
703 TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
704 TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
705 TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
707 TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
709 TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
712 * If an application calls setupterm() rather than initscr() or
713 * newterm(), we will not have the def_prog_mode() call in
714 * _nc_setupscreen(). Do it now anyway, so we can initialize the
717 if (NC_ISATTY(trm->Filedes)) {
718 TCB->drv->td_mode(TCB, TRUE, TRUE);
722 #define MAX_PALETTE 8
723 #define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
726 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
733 if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
734 const color_t *tp = InfoOf(sp).defaultPalette;
737 ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
739 tp[f].red, tp[f].green, tp[f].blue,
740 tp[b].red, tp[b].green, tp[b].blue));
742 NCURSES_PUTP2("initialize_pair",
743 TPARM_7(initialize_pair,
745 tp[f].red, tp[f].green, tp[f].blue,
746 tp[b].red, tp[b].green, tp[b].blue));
751 default_fg(SCREEN *sp)
753 #if NCURSES_EXT_FUNCS
754 return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
761 default_bg(SCREEN *sp)
763 #if NCURSES_EXT_FUNCS
764 return sp != 0 ? sp->_default_bg : COLOR_BLACK;
771 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
772 int color, int r, int g, int b)
774 SCREEN *sp = TCB->csp;
777 if (initialize_color != NULL) {
778 NCURSES_PUTP2("initialize_color",
779 TPARM_4(initialize_color, color, r, g, b));
784 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
788 NCURSES_SP_OUTC outc)
790 SCREEN *sp = TCB->csp;
791 NCURSES_COLOR_T fg = COLOR_DEFAULT;
792 NCURSES_COLOR_T bg = COLOR_DEFAULT;
793 NCURSES_COLOR_T old_fg, old_bg;
799 if (pair < 0 || pair >= COLOR_PAIRS) {
801 } else if (pair != 0) {
802 if (set_color_pair) {
803 TPUTS_TRACE("set_color_pair");
804 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
805 TPARM_1(set_color_pair, pair), 1, outc);
807 } else if (sp != 0) {
808 NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
817 && NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
821 if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
822 || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
823 #if NCURSES_EXT_FUNCS
825 * A minor optimization - but extension. If "AX" is specified in
826 * the terminal description, treat it as screen's indicator of ECMA
827 * SGR 39 and SGR 49, and assume the two sequences are independent.
829 if (sp->_has_sgr_39_49
830 && isDefaultColor(old_bg)
831 && !isDefaultColor(old_fg)) {
832 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
833 } else if (sp->_has_sgr_39_49
834 && isDefaultColor(old_fg)
835 && !isDefaultColor(old_bg)) {
836 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
847 #if NCURSES_EXT_FUNCS
848 if (isDefaultColor(fg))
849 fg = (NCURSES_COLOR_T) default_fg(sp);
850 if (isDefaultColor(bg))
851 bg = (NCURSES_COLOR_T) default_bg(sp);
855 NCURSES_COLOR_T xx = fg;
860 TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
863 if (!isDefaultColor(fg)) {
864 drv_setcolor(TCB, TRUE, fg, outc);
866 if (!isDefaultColor(bg)) {
867 drv_setcolor(TCB, FALSE, bg, outc);
871 #define xterm_kmous "\033[M"
873 init_xterm_mouse(SCREEN *sp)
875 sp->_mouse_type = M_XTERM;
876 sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
877 if (!VALID_STRING(sp->_mouse_xtermcap))
878 sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
882 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
889 /* we know how to recognize mouse events under "xterm" */
891 if (key_mouse != 0) {
892 if (!strcmp(key_mouse, xterm_kmous)
893 || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
894 init_xterm_mouse(sp);
896 } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
897 if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
898 init_xterm_mouse(sp);
904 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
906 EVENTLIST_2nd(_nc_eventlist * evl))
915 if ((sp->_mouse_type == M_SYSMOUSE)
916 && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
921 rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
927 if ((sp->_mouse_type == M_SYSMOUSE)
928 && (sp->_sysmouse_head < sp->_sysmouse_tail)
930 && (errno == EINTR)) {
939 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
941 SCREEN *sp = TCB->csp;
943 return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
947 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
949 SCREEN *sp = TCB->csp;
952 if (labnum > 0 && labnum <= num_labels) {
953 NCURSES_PUTP2("plab_norm",
954 TPARM_2(plab_norm, labnum, text));
959 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
961 SCREEN *sp = TCB->csp;
965 NCURSES_PUTP2("label_on", label_on);
967 NCURSES_PUTP2("label_off", label_off);
972 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
974 SCREEN *sp = TCB->csp;
975 chtype attrs = A_NORMAL;
978 if (enter_alt_charset_mode)
979 attrs |= A_ALTCHARSET;
981 if (enter_blink_mode)
990 if (enter_reverse_mode)
993 if (enter_standout_mode)
996 if (enter_protected_mode)
999 if (enter_secure_mode)
1002 if (enter_underline_mode)
1003 attrs |= A_UNDERLINE;
1005 if (sp && sp->_coloron)
1009 if (enter_italics_mode)
1017 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1022 cursor_down = parm_down_cursor = 0;
1024 cursor_up = parm_up_cursor = 0;
1026 cursor_home = carriage_return;
1030 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1032 SCREEN *sp = TCB->csp;
1036 if (ena_acs != NULL) {
1037 NCURSES_PUTP2("ena_acs", ena_acs);
1039 #if NCURSES_EXT_FUNCS
1041 * Linux console "supports" the "PC ROM" character set by the coincidence
1042 * that smpch/rmpch and smacs/rmacs have the same values. ncurses has
1043 * no codepage support (see SCO Merge for an example). Outside of the
1044 * values defined in acsc, there are no definitions for the "PC ROM"
1045 * character set (assumed by some applications to be codepage 437), but we
1046 * allow those applications to use those codepoints.
1048 * test/blue.c uses this feature.
1050 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1051 if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
1052 PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
1054 for (i = 1; i < ACS_LEN; ++i) {
1055 if (real_map[i] == 0) {
1056 real_map[i] = (chtype) i;
1057 if (real_map != fake_map) {
1059 sp->_screen_acs_map[i] = TRUE;
1066 if (acs_chars != NULL) {
1068 size_t length = strlen(acs_chars);
1070 while (i + 1 < length) {
1071 if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
1072 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
1074 sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1080 /* Show the equivalent mapping, noting if it does not match the
1081 * given attribute, whether by re-ordering or duplication.
1083 if (USE_TRACEF(TRACE_CALLS)) {
1085 char show[ACS_LEN * 2 + 1];
1086 for (n = 1, m = 0; n < ACS_LEN; n++) {
1087 if (real_map[n] != 0) {
1088 show[m++] = (char) n;
1089 show[m++] = (char) ChCharOf(real_map[n]);
1093 if (acs_chars == NULL || strcmp(acs_chars, show))
1094 _tracef("%s acs_chars %s",
1095 (acs_chars == NULL) ? "NULL" : "READ",
1096 _nc_visbuf(acs_chars));
1097 _tracef("%s acs_chars %s",
1100 : (strcmp(acs_chars, show)
1105 _nc_unlock_global(tracef);
1110 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1112 NCURSES_EXPORT(void)
1113 _nc_cookie_init(SCREEN *sp)
1115 bool support_cookies = USE_XMC_SUPPORT;
1116 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1118 if (sp == 0 || !ENSURE_TINFO(sp))
1123 * If we have no magic-cookie support compiled-in, or if it is suppressed
1124 * in the environment, reset the support-flag.
1126 if (magic_cookie_glitch >= 0) {
1127 if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1128 support_cookies = FALSE;
1133 if (!support_cookies && magic_cookie_glitch >= 0) {
1134 T(("will disable attributes to work w/o magic cookies"));
1137 if (magic_cookie_glitch > 0) { /* tvi, wyse */
1139 sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1142 * We "should" treat colors as an attribute. The wyse350 (and its
1143 * clones) appear to be the only ones that have both colors and magic
1147 sp->_xmc_triggers |= A_COLOR;
1150 sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1152 T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1154 * Supporting line-drawing may be possible. But make the regular
1155 * video attributes work first.
1157 acs_chars = ABSENT_STRING;
1158 ena_acs = ABSENT_STRING;
1159 enter_alt_charset_mode = ABSENT_STRING;
1160 exit_alt_charset_mode = ABSENT_STRING;
1163 * To keep the cookie support simple, suppress all of the optimization
1164 * hooks except for clear_screen and the cursor addressing.
1166 if (support_cookies) {
1167 clr_eol = ABSENT_STRING;
1168 clr_eos = ABSENT_STRING;
1169 set_attributes = ABSENT_STRING;
1172 } else if (magic_cookie_glitch == 0) { /* hpterm */
1176 * If magic cookies are not supported, cancel the strings that set
1179 if (!support_cookies && magic_cookie_glitch >= 0) {
1180 magic_cookie_glitch = ABSENT_NUMERIC;
1181 set_attributes = ABSENT_STRING;
1182 enter_blink_mode = ABSENT_STRING;
1183 enter_bold_mode = ABSENT_STRING;
1184 enter_dim_mode = ABSENT_STRING;
1185 enter_reverse_mode = ABSENT_STRING;
1186 enter_standout_mode = ABSENT_STRING;
1187 enter_underline_mode = ABSENT_STRING;
1190 /* initialize normal acs before wide, since we use mapping in the latter */
1191 #if !USE_WIDEC_SUPPORT
1192 if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
1195 enter_alt_charset_mode = NULL;
1196 exit_alt_charset_mode = NULL;
1197 set_attributes = NULL;
1203 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1207 EVENTLIST_2nd(_nc_eventlist * evl))
1214 return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1218 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1221 unsigned char c2 = 0;
1228 # if USE_PTHREADS_EINTR
1229 if ((pthread_self) && (pthread_kill) && (pthread_equal))
1230 _nc_globals.read_thread = pthread_self();
1232 n = (int) read(sp->_ifd, &c2, (size_t) 1);
1233 #if USE_PTHREADS_EINTR
1234 _nc_globals.read_thread = 0;
1241 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1245 struct timespec request, remaining;
1246 request.tv_sec = ms / 1000;
1247 request.tv_nsec = (ms % 1000) * 1000000;
1248 while (nanosleep(&request, &remaining) == -1
1249 && errno == EINTR) {
1250 request = remaining;
1254 _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1260 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1265 rc = NCURSES_PUTP2(name, value);
1271 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1273 int rc = __nc_putp(sp, name, value);
1275 NCURSES_SP_NAME(_nc_flush) (sp);
1281 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1292 (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
1293 } else if (!flag && keypad_local) {
1294 (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
1296 if (flag && !sp->_tried) {
1297 _nc_init_keytry(sp);
1307 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1318 unsigned ch = (unsigned) c;
1320 while ((s = _nc_expand_try(sp->_key_ok,
1321 ch, &count, (size_t) 0)) != 0
1322 && _nc_remove_key(&(sp->_key_ok), ch)) {
1323 code = _nc_add_to_try(&(sp->_keytry), s, ch);
1330 while ((s = _nc_expand_try(sp->_keytry,
1331 ch, &count, (size_t) 0)) != 0
1332 && _nc_remove_key(&(sp->_keytry), ch)) {
1333 code = _nc_add_to_try(&(sp->_key_ok), s, ch);
1345 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1353 T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1355 if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1358 code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1361 code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1364 code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1374 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1380 res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1385 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1387 drv_Name, /* Name */
1388 drv_CanHandle, /* CanHandle */
1389 drv_init, /* init */
1390 drv_release, /* release */
1391 drv_size, /* size */
1392 drv_sgmode, /* sgmode */
1393 drv_conattr, /* conattr */
1394 drv_mvcur, /* hwcur */
1395 drv_mode, /* mode */
1396 drv_rescol, /* rescol */
1397 drv_rescolors, /* rescolors */
1398 drv_setcolor, /* color */
1399 drv_dobeepflash, /* doBeepOrFlash */
1400 drv_initpair, /* initpair */
1401 drv_initcolor, /* initcolor */
1402 drv_do_color, /* docolor */
1403 drv_initmouse, /* initmouse */
1404 drv_testmouse, /* testmouse */
1405 drv_setfilter, /* setfilter */
1406 drv_hwlabel, /* hwlabel */
1407 drv_hwlabelOnOff, /* hwlabelOnOff */
1408 drv_doupdate, /* update */
1409 drv_defaultcolors, /* defaultcolors */
1410 drv_print, /* print */
1411 drv_getsize, /* getsize */
1412 drv_setsize, /* setsize */
1413 drv_initacs, /* initacs */
1414 drv_screen_init, /* scinit */
1415 drv_wrap, /* scexit */
1416 drv_twait, /* twait */
1417 drv_read, /* read */
1419 drv_kpad, /* kpad */
1420 drv_keyok, /* kyOk */
1421 drv_kyExist, /* kyExist */
1422 drv_cursorSet /* cursorSet */