1 /****************************************************************************
2 * Copyright (c) 2008-2014,2015 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.
41 #include <sys/time.h> /* needed for MacOS X DP3 */
46 # if !defined(sun) || !TERMIOS
48 # include <sys/ioctl.h>
53 MODULE_ID("$Id: tinfo_driver.c,v 1.40 2015/06/27 01:20:41 tom Exp $")
56 * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS,
57 * Solaris, IRIX) define TIOCGWINSZ and struct winsize.
60 # define IOCTL_WINSIZE TIOCGSIZE
61 # define STRUCT_WINSIZE struct ttysize
62 # define WINSIZE_ROWS(n) (int)n.ts_lines
63 # define WINSIZE_COLS(n) (int)n.ts_cols
66 # define IOCTL_WINSIZE TIOCGWINSZ
67 # define STRUCT_WINSIZE struct winsize
68 # define WINSIZE_ROWS(n) (int)n.ws_row
69 # define WINSIZE_COLS(n) (int)n.ws_col
74 * These should be screen structure members. They need to be globals for
75 * historical reasons. So we assign them in start_color() and also in
76 * set_term()'s screen-switching logic.
80 NCURSES_PUBLIC_VAR(COLOR_PAIRS
) (void)
82 return CURRENT_SCREEN
? CURRENT_SCREEN
->_pair_count
: -1;
85 NCURSES_PUBLIC_VAR(COLORS
) (void)
87 return CURRENT_SCREEN
? CURRENT_SCREEN
->_color_count
: -1;
90 NCURSES_EXPORT_VAR(int) COLOR_PAIRS
= 0;
91 NCURSES_EXPORT_VAR(int) COLORS
= 0;
94 #define TCBMAGIC NCDRV_MAGIC(NCDRV_TINFO)
95 #define AssertTCB() assert(TCB!=0 && TCB->magic==TCBMAGIC)
96 #define SetSP() assert(TCB->csp!=0); sp = TCB->csp; (void) sp
99 * This routine needs to do all the work to make curscr look
103 drv_doupdate(TERMINAL_CONTROL_BLOCK
* TCB
)
106 return TINFO_DOUPDATE(TCB
->csp
);
110 drv_Name(TERMINAL_CONTROL_BLOCK
* TCB
)
117 #define SETUP_FAIL FALSE
120 drv_CanHandle(TERMINAL_CONTROL_BLOCK
* TCB
, const char *tname
, int *errret
)
128 T((T_CALLED("tinfo::drv_CanHandle(%p)"), TCB
));
130 assert(TCB
!= 0 && tname
!= 0);
131 termp
= (TERMINAL
*) TCB
;
133 TCB
->magic
= TCBMAGIC
;
135 #if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
136 status
= _nc_setup_tinfo(tname
, &termp
->type
);
141 /* try fallback list if entry on disk */
142 if (status
!= TGETENT_YES
) {
143 const TERMTYPE
*fallback
= _nc_fallback(tname
);
146 termp
->type
= *fallback
;
147 status
= TGETENT_YES
;
151 if (status
!= TGETENT_YES
) {
152 NCURSES_SP_NAME(del_curterm
) (NCURSES_SP_ARGx termp
);
153 if (status
== TGETENT_ERR
) {
154 ret_error0(status
, "terminals database is inaccessible\n");
155 } else if (status
== TGETENT_NO
) {
156 ret_error1(status
, "unknown terminal type.\n", tname
);
161 strncpy(ttytype
, termp
->type
.term_names
, (size_t) NAMESIZE
- 1);
162 ttytype
[NAMESIZE
- 1] = '\0';
165 if (command_character
)
166 _nc_tinfo_cmdch(termp
, *command_character
);
170 * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity
171 * check before giving up.
173 if ((VALID_STRING(cursor_address
)
174 || (VALID_STRING(cursor_down
) && VALID_STRING(cursor_home
)))
175 && VALID_STRING(clear_screen
)) {
176 ret_error1(TGETENT_YES
, "terminal is not really generic.\n", tname
);
178 ret_error1(TGETENT_NO
, "I need something more specific.\n", tname
);
182 ret_error1(TGETENT_YES
, "I can't handle hardcopy terminals.\n", tname
);
189 drv_dobeepflash(TERMINAL_CONTROL_BLOCK
* TCB
, int beepFlag
)
197 /* FIXME: should make sure that we are not in altchar mode */
200 res
= NCURSES_PUTP2("bell", bell
);
201 NCURSES_SP_NAME(_nc_flush
) (sp
);
202 } else if (flash_screen
) {
203 res
= NCURSES_PUTP2("flash_screen", flash_screen
);
204 NCURSES_SP_NAME(_nc_flush
) (sp
);
208 res
= NCURSES_PUTP2("flash_screen", flash_screen
);
209 NCURSES_SP_NAME(_nc_flush
) (sp
);
211 res
= NCURSES_PUTP2("bell", bell
);
212 NCURSES_SP_NAME(_nc_flush
) (sp
);
219 * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
220 * to maintain compatibility with a pre-ANSI scheme. The same scheme is
221 * also used in the FreeBSD syscons.
224 toggled_colors(int c
)
227 static const int table
[] =
228 {0, 4, 2, 6, 1, 5, 3, 7,
229 8, 12, 10, 14, 9, 13, 11, 15};
236 drv_print(TERMINAL_CONTROL_BLOCK
* TCB
, char *data
, int len
)
242 #if NCURSES_EXT_FUNCS
243 return NCURSES_SP_NAME(mcprint
) (TCB
->csp
, data
, len
);
250 drv_defaultcolors(TERMINAL_CONTROL_BLOCK
* TCB
, int fg
, int bg
)
258 if (sp
!= 0 && orig_pair
&& orig_colors
&& (initialize_pair
!= 0)) {
259 #if NCURSES_EXT_FUNCS
260 sp
->_default_color
= isDefaultColor(fg
) || isDefaultColor(bg
);
261 sp
->_has_sgr_39_49
= (NCURSES_SP_NAME(tigetflag
) (NCURSES_SP_ARGx
264 sp
->_default_fg
= isDefaultColor(fg
) ? COLOR_DEFAULT
: (fg
& C_MASK
);
265 sp
->_default_bg
= isDefaultColor(bg
) ? COLOR_DEFAULT
: (bg
& C_MASK
);
266 if (sp
->_color_pairs
!= 0) {
267 bool save
= sp
->_default_color
;
268 sp
->_default_color
= TRUE
;
269 NCURSES_SP_NAME(init_pair
) (NCURSES_SP_ARGx
273 sp
->_default_color
= save
;
282 drv_setcolor(TERMINAL_CONTROL_BLOCK
* TCB
,
285 NCURSES_SP_OUTC outc
)
293 if (set_a_foreground
) {
294 TPUTS_TRACE("set_a_foreground");
295 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
296 TPARM_1(set_a_foreground
, color
), 1, outc
);
298 TPUTS_TRACE("set_foreground");
299 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
300 TPARM_1(set_foreground
,
301 toggled_colors(color
)), 1, outc
);
304 if (set_a_background
) {
305 TPUTS_TRACE("set_a_background");
306 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
307 TPARM_1(set_a_background
, color
), 1, outc
);
309 TPUTS_TRACE("set_background");
310 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
311 TPARM_1(set_background
,
312 toggled_colors(color
)), 1, outc
);
318 drv_rescol(TERMINAL_CONTROL_BLOCK
* TCB
)
326 if (orig_pair
!= 0) {
327 NCURSES_PUTP2("orig_pair", orig_pair
);
334 drv_rescolors(TERMINAL_CONTROL_BLOCK
* TCB
)
342 if (orig_colors
!= 0) {
343 NCURSES_PUTP2("orig_colors", orig_colors
);
350 drv_size(TERMINAL_CONTROL_BLOCK
* TCB
, int *linep
, int *colp
)
354 bool useTioctl
= TRUE
;
357 sp
= TCB
->csp
; /* can be null here */
360 useEnv
= sp
->_use_env
;
361 useTioctl
= sp
->_use_tioctl
;
363 useEnv
= _nc_prescreen
.use_env
;
364 useTioctl
= _nc_prescreen
.use_tioctl
;
367 /* figure out the size of the screen */
368 T(("screen size: terminfo lines = %d columns = %d", lines
, columns
));
370 *linep
= (int) lines
;
371 *colp
= (int) columns
;
373 if (useEnv
|| useTioctl
) {
379 _scrsize(screendata
);
380 *colp
= screendata
[0];
381 *linep
= ((sp
!= 0 && sp
->_filtered
)
384 T(("EMX screen size: environment LINES = %d COLUMNS = %d",
389 /* try asking the OS */
391 TERMINAL
*termp
= (TERMINAL
*) TCB
;
392 if (NC_ISATTY(termp
->Filedes
)) {
397 if (ioctl(termp
->Filedes
, IOCTL_WINSIZE
, &size
) >= 0) {
398 *linep
= ((sp
!= 0 && sp
->_filtered
)
400 : WINSIZE_ROWS(size
));
401 *colp
= WINSIZE_COLS(size
);
402 T(("SYS screen size: environment LINES = %d COLUMNS = %d",
410 #endif /* HAVE_SIZECHANGE */
415 * If environment variables are used, update them.
417 if ((sp
== 0 || !sp
->_filtered
) && _nc_getenv_num("LINES") > 0) {
418 _nc_setenv_num("LINES", *linep
);
420 if (_nc_getenv_num("COLUMNS") > 0) {
421 _nc_setenv_num("COLUMNS", *colp
);
426 * Finally, look for environment variables.
428 * Solaris lets users override either dimension with an environment
431 if ((value
= _nc_getenv_num("LINES")) > 0) {
433 T(("screen size: environment LINES = %d", *linep
));
435 if ((value
= _nc_getenv_num("COLUMNS")) > 0) {
437 T(("screen size: environment COLUMNS = %d", *colp
));
441 /* if we can't get dynamic info about the size, use static */
443 *linep
= (int) lines
;
446 *colp
= (int) columns
;
449 /* the ultimate fallback, assume fixed 24x80 size */
458 * Put the derived values back in the screen-size caps, so
459 * tigetnum() and tgetnum() will do the right thing.
461 lines
= (short) (*linep
);
462 columns
= (short) (*colp
);
465 T(("screen size is %dx%d", *linep
, *colp
));
470 drv_getsize(TERMINAL_CONTROL_BLOCK
* TCB
, int *l
, int *c
)
473 assert(l
!= 0 && c
!= 0);
480 drv_setsize(TERMINAL_CONTROL_BLOCK
* TCB
, int l
, int c
)
489 drv_sgmode(TERMINAL_CONTROL_BLOCK
* TCB
, int setFlag
, TTY
* buf
)
491 SCREEN
*sp
= TCB
->csp
;
492 TERMINAL
*_term
= (TERMINAL
*) TCB
;
498 if (SET_TTY(_term
->Filedes
, buf
) != 0) {
501 if (errno
== ENOTTY
) {
511 if (GET_TTY(_term
->Filedes
, buf
) != 0) {
523 drv_mode(TERMINAL_CONTROL_BLOCK
* TCB
, int progFlag
, int defFlag
)
526 TERMINAL
*_term
= (TERMINAL
*) TCB
;
532 if (progFlag
) /* prog mode */
537 * Turn off the XTABS bit in the tty structure if it was on.
539 if ((drv_sgmode(TCB
, FALSE
, &(_term
->Nttyb
)) == OK
)) {
541 _term
->Nttyb
.c_oflag
&= (unsigned) ~OFLAGS_TABS
;
543 _term
->Nttyb
.sg_flags
&= (unsigned) ~XTABS
;
548 /* reset_prog_mode */
549 if (drv_sgmode(TCB
, TRUE
, &(_term
->Nttyb
)) == OK
) {
552 _nc_keypad(sp
, TRUE
);
557 } else { /* shell mode */
561 * If XTABS was on, remove the tab and backtab capabilities.
563 if (drv_sgmode(TCB
, FALSE
, &(_term
->Ottyb
)) == OK
) {
565 if (_term
->Ottyb
.c_oflag
& OFLAGS_TABS
)
566 tab
= back_tab
= NULL
;
568 if (_term
->Ottyb
.sg_flags
& XTABS
)
569 tab
= back_tab
= NULL
;
574 /* reset_shell_mode */
576 _nc_keypad(sp
, FALSE
);
577 NCURSES_SP_NAME(_nc_flush
) (sp
);
579 code
= drv_sgmode(TCB
, TRUE
, &(_term
->Ottyb
));
590 NCURSES_SP_NAME(_nc_screen_wrap
) (sp
);
591 NCURSES_SP_NAME(_nc_mvcur_wrap
) (sp
); /* wrap up cursor addressing */
596 drv_release(TERMINAL_CONTROL_BLOCK
* TCB GCC_UNUSED
)
600 # define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
603 drv_screen_init(SCREEN
*sp
)
605 TERMINAL_CONTROL_BLOCK
*TCB
= TCBOf(sp
);
610 * Check for mismatched graphic-rendition capabilities. Most SVr4
611 * terminfo trees contain entries that have rmul or rmso equated to
612 * sgr0 (Solaris curses copes with those entries). We do this only
613 * for curses, since many termcap applications assume that
614 * smso/rmso and smul/rmul are paired, and will not function
615 * properly if we remove rmso or rmul. Curses applications
616 * shouldn't be looking at this detail.
618 sp
->_use_rmso
= SGR0_TEST(exit_standout_mode
);
619 sp
->_use_rmul
= SGR0_TEST(exit_underline_mode
);
622 * Check whether we can optimize scrolling under dumb terminals in
623 * case we do not have any of these capabilities, scrolling
624 * optimization will be useless.
626 sp
->_scrolling
= ((scroll_forward
&& scroll_reverse
) ||
634 NCURSES_SP_NAME(baudrate
) (sp
);
636 NCURSES_SP_NAME(_nc_mvcur_init
) (sp
);
637 /* initialize terminal to a sane state */
638 NCURSES_SP_NAME(_nc_screen_init
) (sp
);
642 drv_init(TERMINAL_CONTROL_BLOCK
* TCB
)
648 trm
= (TERMINAL
*) TCB
;
650 TCB
->info
.initcolor
= VALID_STRING(initialize_color
);
651 TCB
->info
.canchange
= can_change
;
652 TCB
->info
.hascolor
= ((VALID_NUMERIC(max_colors
) && VALID_NUMERIC(max_pairs
)
653 && (((set_foreground
!= NULL
)
654 && (set_background
!= NULL
))
655 || ((set_a_foreground
!= NULL
)
656 && (set_a_background
!= NULL
))
657 || set_color_pair
)) ? TRUE
: FALSE
);
659 TCB
->info
.caninit
= !(exit_ca_mode
&& non_rev_rmcup
);
661 TCB
->info
.maxpairs
= VALID_NUMERIC(max_pairs
) ? max_pairs
: 0;
662 TCB
->info
.maxcolors
= VALID_NUMERIC(max_colors
) ? max_colors
: 0;
663 TCB
->info
.numlabels
= VALID_NUMERIC(num_labels
) ? num_labels
: 0;
664 TCB
->info
.labelwidth
= VALID_NUMERIC(label_width
) ? label_width
: 0;
665 TCB
->info
.labelheight
= VALID_NUMERIC(label_height
) ? label_height
: 0;
666 TCB
->info
.nocolorvideo
= VALID_NUMERIC(no_color_video
) ? no_color_video
668 TCB
->info
.tabsize
= VALID_NUMERIC(init_tabs
) ? (int) init_tabs
: 8;
670 TCB
->info
.defaultPalette
= hue_lightness_saturation
? _nc_hls_palette
: _nc_cga_palette
;
673 * If an application calls setupterm() rather than initscr() or
674 * newterm(), we will not have the def_prog_mode() call in
675 * _nc_setupscreen(). Do it now anyway, so we can initialize the
678 if (NC_ISATTY(trm
->Filedes
)) {
679 TCB
->drv
->td_mode(TCB
, TRUE
, TRUE
);
683 #define MAX_PALETTE 8
684 #define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE)
687 drv_initpair(TERMINAL_CONTROL_BLOCK
* TCB
, int pair
, int f
, int b
)
694 if ((initialize_pair
!= NULL
) && InPalette(f
) && InPalette(b
)) {
695 const color_t
*tp
= InfoOf(sp
).defaultPalette
;
698 ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
700 tp
[f
].red
, tp
[f
].green
, tp
[f
].blue
,
701 tp
[b
].red
, tp
[b
].green
, tp
[b
].blue
));
703 NCURSES_PUTP2("initialize_pair",
704 TPARM_7(initialize_pair
,
706 tp
[f
].red
, tp
[f
].green
, tp
[f
].blue
,
707 tp
[b
].red
, tp
[b
].green
, tp
[b
].blue
));
712 default_fg(SCREEN
*sp
)
714 #if NCURSES_EXT_FUNCS
715 return (sp
!= 0) ? sp
->_default_fg
: COLOR_WHITE
;
722 default_bg(SCREEN
*sp
)
724 #if NCURSES_EXT_FUNCS
725 return sp
!= 0 ? sp
->_default_bg
: COLOR_BLACK
;
732 drv_initcolor(TERMINAL_CONTROL_BLOCK
* TCB
,
733 int color
, int r
, int g
, int b
)
735 SCREEN
*sp
= TCB
->csp
;
738 if (initialize_color
!= NULL
) {
739 NCURSES_PUTP2("initialize_color",
740 TPARM_4(initialize_color
, color
, r
, g
, b
));
745 drv_do_color(TERMINAL_CONTROL_BLOCK
* TCB
,
749 NCURSES_SP_OUTC outc
)
751 SCREEN
*sp
= TCB
->csp
;
752 NCURSES_COLOR_T fg
= COLOR_DEFAULT
;
753 NCURSES_COLOR_T bg
= COLOR_DEFAULT
;
754 NCURSES_COLOR_T old_fg
, old_bg
;
760 if (pair
< 0 || pair
>= COLOR_PAIRS
) {
762 } else if (pair
!= 0) {
763 if (set_color_pair
) {
764 TPUTS_TRACE("set_color_pair");
765 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
766 TPARM_1(set_color_pair
, pair
), 1, outc
);
768 } else if (sp
!= 0) {
769 NCURSES_SP_NAME(pair_content
) (NCURSES_SP_ARGx
778 && NCURSES_SP_NAME(pair_content
) (NCURSES_SP_ARGx
782 if ((isDefaultColor(fg
) && !isDefaultColor(old_fg
))
783 || (isDefaultColor(bg
) && !isDefaultColor(old_bg
))) {
784 #if NCURSES_EXT_FUNCS
786 * A minor optimization - but extension. If "AX" is specified in
787 * the terminal description, treat it as screen's indicator of ECMA
788 * SGR 39 and SGR 49, and assume the two sequences are independent.
790 if (sp
->_has_sgr_39_49
791 && isDefaultColor(old_bg
)
792 && !isDefaultColor(old_fg
)) {
793 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
"\033[39m", 1, outc
);
794 } else if (sp
->_has_sgr_39_49
795 && isDefaultColor(old_fg
)
796 && !isDefaultColor(old_bg
)) {
797 NCURSES_SP_NAME(tputs
) (NCURSES_SP_ARGx
"\033[49m", 1, outc
);
808 #if NCURSES_EXT_FUNCS
809 if (isDefaultColor(fg
))
810 fg
= (NCURSES_COLOR_T
) default_fg(sp
);
811 if (isDefaultColor(bg
))
812 bg
= (NCURSES_COLOR_T
) default_bg(sp
);
816 NCURSES_COLOR_T xx
= fg
;
821 TR(TRACE_ATTRS
, ("setting colors: pair = %d, fg = %d, bg = %d", pair
,
824 if (!isDefaultColor(fg
)) {
825 drv_setcolor(TCB
, TRUE
, fg
, outc
);
827 if (!isDefaultColor(bg
)) {
828 drv_setcolor(TCB
, FALSE
, bg
, outc
);
832 #define xterm_kmous "\033[M"
834 init_xterm_mouse(SCREEN
*sp
)
836 sp
->_mouse_type
= M_XTERM
;
837 sp
->_mouse_xtermcap
= NCURSES_SP_NAME(tigetstr
) (NCURSES_SP_ARGx
"XM");
838 if (!VALID_STRING(sp
->_mouse_xtermcap
))
839 sp
->_mouse_xtermcap
= "\033[?1000%?%p1%{1}%=%th%el%;";
843 drv_initmouse(TERMINAL_CONTROL_BLOCK
* TCB
)
850 /* we know how to recognize mouse events under "xterm" */
852 if (key_mouse
!= 0) {
853 if (!strcmp(key_mouse
, xterm_kmous
)
854 || strstr(TerminalOf(sp
)->type
.term_names
, "xterm") != 0) {
855 init_xterm_mouse(sp
);
857 } else if (strstr(TerminalOf(sp
)->type
.term_names
, "xterm") != 0) {
858 if (_nc_add_to_try(&(sp
->_keytry
), xterm_kmous
, KEY_MOUSE
) == OK
)
859 init_xterm_mouse(sp
);
865 drv_testmouse(TERMINAL_CONTROL_BLOCK
* TCB
,
867 EVENTLIST_2nd(_nc_eventlist
* evl
))
876 if ((sp
->_mouse_type
== M_SYSMOUSE
)
877 && (sp
->_sysmouse_head
< sp
->_sysmouse_tail
)) {
882 rc
= TCBOf(sp
)->drv
->td_twait(TCBOf(sp
),
888 if ((sp
->_mouse_type
== M_SYSMOUSE
)
889 && (sp
->_sysmouse_head
< sp
->_sysmouse_tail
)
891 && (errno
== EINTR
)) {
900 drv_mvcur(TERMINAL_CONTROL_BLOCK
* TCB
, int yold
, int xold
, int ynew
, int xnew
)
902 SCREEN
*sp
= TCB
->csp
;
904 return NCURSES_SP_NAME(_nc_mvcur
) (sp
, yold
, xold
, ynew
, xnew
);
908 drv_hwlabel(TERMINAL_CONTROL_BLOCK
* TCB
, int labnum
, char *text
)
910 SCREEN
*sp
= TCB
->csp
;
913 if (labnum
> 0 && labnum
<= num_labels
) {
914 NCURSES_PUTP2("plab_norm",
915 TPARM_2(plab_norm
, labnum
, text
));
920 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK
* TCB
, int OnFlag
)
922 SCREEN
*sp
= TCB
->csp
;
926 NCURSES_PUTP2("label_on", label_on
);
928 NCURSES_PUTP2("label_off", label_off
);
933 drv_conattr(TERMINAL_CONTROL_BLOCK
* TCB
)
935 SCREEN
*sp
= TCB
->csp
;
936 chtype attrs
= A_NORMAL
;
939 if (enter_alt_charset_mode
)
940 attrs
|= A_ALTCHARSET
;
942 if (enter_blink_mode
)
951 if (enter_reverse_mode
)
954 if (enter_standout_mode
)
957 if (enter_protected_mode
)
960 if (enter_secure_mode
)
963 if (enter_underline_mode
)
964 attrs
|= A_UNDERLINE
;
966 if (sp
&& sp
->_coloron
)
970 if (enter_italics_mode
)
978 drv_setfilter(TERMINAL_CONTROL_BLOCK
* TCB
)
983 cursor_down
= parm_down_cursor
= 0;
985 cursor_up
= parm_up_cursor
= 0;
987 cursor_home
= carriage_return
;
991 drv_initacs(TERMINAL_CONTROL_BLOCK
* TCB
, chtype
*real_map
, chtype
*fake_map
)
993 SCREEN
*sp
= TCB
->csp
;
997 if (ena_acs
!= NULL
) {
998 NCURSES_PUTP2("ena_acs", ena_acs
);
1000 #if NCURSES_EXT_FUNCS
1002 * Linux console "supports" the "PC ROM" character set by the coincidence
1003 * that smpch/rmpch and smacs/rmacs have the same values. ncurses has
1004 * no codepage support (see SCO Merge for an example). Outside of the
1005 * values defined in acsc, there are no definitions for the "PC ROM"
1006 * character set (assumed by some applications to be codepage 437), but we
1007 * allow those applications to use those codepoints.
1009 * test/blue.c uses this feature.
1011 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1012 if (PCH_KLUDGE(enter_pc_charset_mode
, enter_alt_charset_mode
) &&
1013 PCH_KLUDGE(exit_pc_charset_mode
, exit_alt_charset_mode
)) {
1015 for (i
= 1; i
< ACS_LEN
; ++i
) {
1016 if (real_map
[i
] == 0) {
1017 real_map
[i
] = (chtype
) i
;
1018 if (real_map
!= fake_map
) {
1020 sp
->_screen_acs_map
[i
] = TRUE
;
1027 if (acs_chars
!= NULL
) {
1029 size_t length
= strlen(acs_chars
);
1031 while (i
+ 1 < length
) {
1032 if (acs_chars
[i
] != 0 && UChar(acs_chars
[i
]) < ACS_LEN
) {
1033 real_map
[UChar(acs_chars
[i
])] = UChar(acs_chars
[i
+ 1]) | A_ALTCHARSET
;
1035 sp
->_screen_acs_map
[UChar(acs_chars
[i
])] = TRUE
;
1041 /* Show the equivalent mapping, noting if it does not match the
1042 * given attribute, whether by re-ordering or duplication.
1044 if (USE_TRACEF(TRACE_CALLS
)) {
1046 char show
[ACS_LEN
* 2 + 1];
1047 for (n
= 1, m
= 0; n
< ACS_LEN
; n
++) {
1048 if (real_map
[n
] != 0) {
1049 show
[m
++] = (char) n
;
1050 show
[m
++] = (char) ChCharOf(real_map
[n
]);
1054 if (acs_chars
== NULL
|| strcmp(acs_chars
, show
))
1055 _tracef("%s acs_chars %s",
1056 (acs_chars
== NULL
) ? "NULL" : "READ",
1057 _nc_visbuf(acs_chars
));
1058 _tracef("%s acs_chars %s",
1061 : (strcmp(acs_chars
, show
)
1066 _nc_unlock_global(tracef
);
1071 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1073 NCURSES_EXPORT(void)
1074 _nc_cookie_init(SCREEN
*sp
)
1076 bool support_cookies
= USE_XMC_SUPPORT
;
1077 TERMINAL_CONTROL_BLOCK
*TCB
= (TERMINAL_CONTROL_BLOCK
*) (sp
->_term
);
1079 if (sp
== 0 || !ENSURE_TINFO(sp
))
1084 * If we have no magic-cookie support compiled-in, or if it is suppressed
1085 * in the environment, reset the support-flag.
1087 if (magic_cookie_glitch
>= 0) {
1088 if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1089 support_cookies
= FALSE
;
1094 if (!support_cookies
&& magic_cookie_glitch
>= 0) {
1095 T(("will disable attributes to work w/o magic cookies"));
1098 if (magic_cookie_glitch
> 0) { /* tvi, wyse */
1100 sp
->_xmc_triggers
= sp
->_ok_attributes
& XMC_CONFLICT
;
1103 * We "should" treat colors as an attribute. The wyse350 (and its
1104 * clones) appear to be the only ones that have both colors and magic
1108 sp
->_xmc_triggers
|= A_COLOR
;
1111 sp
->_xmc_suppress
= sp
->_xmc_triggers
& (chtype
) ~(A_BOLD
);
1113 T(("magic cookie attributes %s", _traceattr(sp
->_xmc_suppress
)));
1115 * Supporting line-drawing may be possible. But make the regular
1116 * video attributes work first.
1118 acs_chars
= ABSENT_STRING
;
1119 ena_acs
= ABSENT_STRING
;
1120 enter_alt_charset_mode
= ABSENT_STRING
;
1121 exit_alt_charset_mode
= ABSENT_STRING
;
1124 * To keep the cookie support simple, suppress all of the optimization
1125 * hooks except for clear_screen and the cursor addressing.
1127 if (support_cookies
) {
1128 clr_eol
= ABSENT_STRING
;
1129 clr_eos
= ABSENT_STRING
;
1130 set_attributes
= ABSENT_STRING
;
1133 } else if (magic_cookie_glitch
== 0) { /* hpterm */
1137 * If magic cookies are not supported, cancel the strings that set
1140 if (!support_cookies
&& magic_cookie_glitch
>= 0) {
1141 magic_cookie_glitch
= ABSENT_NUMERIC
;
1142 set_attributes
= ABSENT_STRING
;
1143 enter_blink_mode
= ABSENT_STRING
;
1144 enter_bold_mode
= ABSENT_STRING
;
1145 enter_dim_mode
= ABSENT_STRING
;
1146 enter_reverse_mode
= ABSENT_STRING
;
1147 enter_standout_mode
= ABSENT_STRING
;
1148 enter_underline_mode
= ABSENT_STRING
;
1151 /* initialize normal acs before wide, since we use mapping in the latter */
1152 #if !USE_WIDEC_SUPPORT
1153 if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp
->_term
)) {
1156 enter_alt_charset_mode
= NULL
;
1157 exit_alt_charset_mode
= NULL
;
1158 set_attributes
= NULL
;
1164 drv_twait(TERMINAL_CONTROL_BLOCK
* TCB
,
1168 EVENTLIST_2nd(_nc_eventlist
* evl
))
1175 return _nc_timed_wait(sp
, mode
, milliseconds
, timeleft
EVENTLIST_2nd(evl
));
1179 drv_read(TERMINAL_CONTROL_BLOCK
* TCB
, int *buf
)
1182 unsigned char c2
= 0;
1189 # if USE_PTHREADS_EINTR
1190 if ((pthread_self
) && (pthread_kill
) && (pthread_equal
))
1191 _nc_globals
.read_thread
= pthread_self();
1193 n
= (int) read(sp
->_ifd
, &c2
, (size_t) 1);
1194 #if USE_PTHREADS_EINTR
1195 _nc_globals
.read_thread
= 0;
1202 drv_nap(TERMINAL_CONTROL_BLOCK
* TCB GCC_UNUSED
, int ms
)
1206 struct timespec request
, remaining
;
1207 request
.tv_sec
= ms
/ 1000;
1208 request
.tv_nsec
= (ms
% 1000) * 1000000;
1209 while (nanosleep(&request
, &remaining
) == -1
1210 && errno
== EINTR
) {
1211 request
= remaining
;
1215 _nc_timed_wait(0, 0, ms
, (int *) 0 EVENTLIST_2nd(0));
1221 __nc_putp(SCREEN
*sp
, const char *name GCC_UNUSED
, const char *value
)
1226 rc
= NCURSES_PUTP2(name
, value
);
1232 __nc_putp_flush(SCREEN
*sp
, const char *name
, const char *value
)
1234 int rc
= __nc_putp(sp
, name
, value
);
1236 NCURSES_SP_NAME(_nc_flush
) (sp
);
1242 drv_kpad(TERMINAL_CONTROL_BLOCK
* TCB
, int flag
)
1253 (void) __nc_putp_flush(sp
, "keypad_xmit", keypad_xmit
);
1254 } else if (!flag
&& keypad_local
) {
1255 (void) __nc_putp_flush(sp
, "keypad_local", keypad_local
);
1257 if (flag
&& !sp
->_tried
) {
1258 _nc_init_keytry(sp
);
1268 drv_keyok(TERMINAL_CONTROL_BLOCK
* TCB
, int c
, int flag
)
1279 unsigned ch
= (unsigned) c
;
1281 while ((s
= _nc_expand_try(sp
->_key_ok
,
1282 ch
, &count
, (size_t) 0)) != 0
1283 && _nc_remove_key(&(sp
->_key_ok
), ch
)) {
1284 code
= _nc_add_to_try(&(sp
->_keytry
), s
, ch
);
1291 while ((s
= _nc_expand_try(sp
->_keytry
,
1292 ch
, &count
, (size_t) 0)) != 0
1293 && _nc_remove_key(&(sp
->_keytry
), ch
)) {
1294 code
= _nc_add_to_try(&(sp
->_key_ok
), s
, ch
);
1306 drv_cursorSet(TERMINAL_CONTROL_BLOCK
* TCB
, int vis
)
1314 T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM
, vis
));
1316 if (SP_PARM
!= 0 && IsTermInfo(SP_PARM
)) {
1319 code
= NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible
);
1322 code
= NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal
);
1325 code
= NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible
);
1335 drv_kyExist(TERMINAL_CONTROL_BLOCK
* TCB
, int key
)
1341 res
= TINFO_HAS_KEY(TCB
->csp
, key
) == 0 ? FALSE
: TRUE
;
1346 NCURSES_EXPORT_VAR (TERM_DRIVER
) _nc_TINFO_DRIVER
= {
1348 drv_Name
, /* Name */
1349 drv_CanHandle
, /* CanHandle */
1350 drv_init
, /* init */
1351 drv_release
, /* release */
1352 drv_size
, /* size */
1353 drv_sgmode
, /* sgmode */
1354 drv_conattr
, /* conattr */
1355 drv_mvcur
, /* hwcur */
1356 drv_mode
, /* mode */
1357 drv_rescol
, /* rescol */
1358 drv_rescolors
, /* rescolors */
1359 drv_setcolor
, /* color */
1360 drv_dobeepflash
, /* doBeepOrFlash */
1361 drv_initpair
, /* initpair */
1362 drv_initcolor
, /* initcolor */
1363 drv_do_color
, /* docolor */
1364 drv_initmouse
, /* initmouse */
1365 drv_testmouse
, /* testmouse */
1366 drv_setfilter
, /* setfilter */
1367 drv_hwlabel
, /* hwlabel */
1368 drv_hwlabelOnOff
, /* hwlabelOnOff */
1369 drv_doupdate
, /* update */
1370 drv_defaultcolors
, /* defaultcolors */
1371 drv_print
, /* print */
1372 drv_getsize
, /* getsize */
1373 drv_setsize
, /* setsize */
1374 drv_initacs
, /* initacs */
1375 drv_screen_init
, /* scinit */
1376 drv_wrap
, /* scexit */
1377 drv_twait
, /* twait */
1378 drv_read
, /* read */
1380 drv_kpad
, /* kpad */
1381 drv_keyok
, /* kyOk */
1382 drv_kyExist
, /* kyExist */
1383 drv_cursorSet
/* cursorSet */