]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/tinfo_driver.c
ncurses 6.1 - patch 20190728
[ncurses.git] / ncurses / tinfo / tinfo_driver.c
1 /****************************************************************************
2  * Copyright (c) 2008-2018,2019 Free Software Foundation, Inc.              *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Juergen Pfeifer                                                 *
31  *     and: Thomas E. Dickey                                                *
32  ****************************************************************************/
33
34 #include <curses.priv.h>
35 #define CUR TerminalType((TERMINAL*)TCB).
36 #include <tic.h>
37 #include <termcap.h>            /* ospeed */
38
39 #if HAVE_NANOSLEEP
40 #include <time.h>
41 #if HAVE_SYS_TIME_H
42 #include <sys/time.h>           /* needed for MacOS X DP3 */
43 #endif
44 #endif
45
46 #if HAVE_SIZECHANGE
47 # if !defined(sun) || !TERMIOS
48 #  if HAVE_SYS_IOCTL_H
49 #   include <sys/ioctl.h>
50 #  endif
51 # endif
52 #endif
53
54 MODULE_ID("$Id: tinfo_driver.c,v 1.64 2019/07/28 18:43:09 tom Exp $")
55
56 /*
57  * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS,
58  * Solaris, IRIX) define TIOCGWINSZ and struct winsize.
59  */
60 #ifdef TIOCGSIZE
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
65 #else
66 # ifdef TIOCGWINSZ
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
71 # endif
72 #endif
73
74 /*
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.
78  */
79 #if USE_REENTRANT
80 NCURSES_EXPORT(int)
81 NCURSES_PUBLIC_VAR(COLOR_PAIRS) (void)
82 {
83     return CURRENT_SCREEN ? CURRENT_SCREEN->_pair_count : -1;
84 }
85 NCURSES_EXPORT(int)
86 NCURSES_PUBLIC_VAR(COLORS) (void)
87 {
88     return CURRENT_SCREEN ? CURRENT_SCREEN->_color_count : -1;
89 }
90 #else
91 NCURSES_EXPORT_VAR(int) COLOR_PAIRS = 0;
92 NCURSES_EXPORT_VAR(int) COLORS = 0;
93 #endif
94
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
98
99 /*
100  * This routine needs to do all the work to make curscr look
101  * like newscr.
102  */
103 static int
104 drv_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
105 {
106     AssertTCB();
107     return TINFO_DOUPDATE(TCB->csp);
108 }
109
110 static const char *
111 drv_Name(TERMINAL_CONTROL_BLOCK * TCB)
112 {
113     (void) TCB;
114     return "tinfo";
115 }
116
117 static void
118 get_baudrate(TERMINAL *termp)
119 {
120     int my_ospeed;
121     int result;
122     if (GET_TTY(termp->Filedes, &termp->Nttyb) == OK) {
123 #ifdef TERMIOS
124         termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
125 #else
126         termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
127 #endif
128     }
129 #ifdef USE_OLD_TTY
130     result = (int) cfgetospeed(&(termp->Nttyb));
131     my_ospeed = (NCURSES_OSPEED) _nc_ospeed(result);
132 #else /* !USE_OLD_TTY */
133 #ifdef TERMIOS
134     my_ospeed = (NCURSES_OSPEED) cfgetospeed(&(termp->Nttyb));
135 #else
136     my_ospeed = (NCURSES_OSPEED) termp->Nttyb.sg_ospeed;
137 #endif
138     result = _nc_baudrate(my_ospeed);
139 #endif
140     termp->_baudrate = result;
141     ospeed = (NCURSES_OSPEED) my_ospeed;
142 }
143
144 #undef SETUP_FAIL
145 #define SETUP_FAIL FALSE
146
147 #define NO_COPY {}
148
149 static bool
150 drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
151 {
152     bool result = FALSE;
153     int status;
154     TERMINAL *termp;
155     SCREEN *sp;
156
157     START_TRACE();
158     T((T_CALLED("tinfo::drv_CanHandle(%p)"), (void *) TCB));
159
160     assert(TCB != 0 && tname != 0);
161     termp = (TERMINAL *) TCB;
162     sp = TCB->csp;
163     TCB->magic = TCBMAGIC;
164
165 #if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
166     status = _nc_setup_tinfo(tname, &TerminalType(termp));
167     T(("_nc_setup_tinfo returns %d", status));
168 #else
169     T(("no database available"));
170     status = TGETENT_NO;
171 #endif
172
173     /* try fallback list if entry on disk */
174     if (status != TGETENT_YES) {
175         const TERMTYPE2 *fallback = _nc_fallback2(tname);
176
177         if (fallback) {
178             T(("found fallback entry"));
179             TerminalType(termp) = *fallback;
180             status = TGETENT_YES;
181         }
182     }
183
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",
190                        tname, NO_COPY);
191         }
192     }
193     result = TRUE;
194 #if NCURSES_EXT_NUMBERS
195     _nc_export_termtype2(&termp->type, &TerminalType(termp));
196 #endif
197 #if !USE_REENTRANT
198     save_ttytype(termp);
199 #endif
200
201     if (command_character)
202         _nc_tinfo_cmdch(termp, *command_character);
203
204     /*
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
208      * baudrate.
209      */
210     if (sp == 0 && NC_ISATTY(termp->Filedes)) {
211         get_baudrate(termp);
212     }
213 #if NCURSES_EXT_NUMBERS
214 #define cleanup_termtype() \
215     _nc_free_termtype2(&TerminalType(termp)); \
216     _nc_free_termtype(&termp->type)
217 #else
218 #define cleanup_termtype() \
219     _nc_free_termtype2(&TerminalType(termp))
220 #endif
221
222     if (generic_type) {
223         /*
224          * BSD 4.3's termcap contains mis-typed "gn" for wy99.  Do a sanity
225          * check before giving up.
226          */
227         if ((VALID_STRING(cursor_address)
228              || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
229             && VALID_STRING(clear_screen)) {
230             cleanup_termtype();
231             ret_error1(TGETENT_YES, "terminal is not really generic.\n",
232                        tname, NO_COPY);
233         } else {
234             cleanup_termtype();
235             ret_error1(TGETENT_NO, "I need something more specific.\n",
236                        tname, NO_COPY);
237         }
238     }
239     if (hard_copy) {
240         cleanup_termtype();
241         ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n",
242                    tname, NO_COPY);
243     }
244
245     returnBool(result);
246 }
247
248 static int
249 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
250 {
251     SCREEN *sp;
252     int res = ERR;
253
254     AssertTCB();
255     SetSP();
256
257     /* FIXME: should make sure that we are not in altchar mode */
258     if (beepFlag) {
259         if (bell) {
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);
265         }
266     } else {
267         if (flash_screen) {
268             res = NCURSES_PUTP2("flash_screen", flash_screen);
269             NCURSES_SP_NAME(_nc_flush) (sp);
270         } else if (bell) {
271             res = NCURSES_PUTP2("bell", bell);
272             NCURSES_SP_NAME(_nc_flush) (sp);
273         }
274     }
275     return res;
276 }
277
278 /*
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.
282  */
283 static int
284 toggled_colors(int c)
285 {
286     if (c < 16) {
287         static const int table[] =
288         {0, 4, 2, 6, 1, 5, 3, 7,
289          8, 12, 10, 14, 9, 13, 11, 15};
290         c = table[c];
291     }
292     return c;
293 }
294
295 static int
296 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
297 {
298     SCREEN *sp;
299
300     AssertTCB();
301     SetSP();
302 #if NCURSES_EXT_FUNCS
303     return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
304 #else
305     return ERR;
306 #endif
307 }
308
309 static int
310 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
311 {
312     SCREEN *sp;
313     int code = ERR;
314
315     AssertTCB();
316     SetSP();
317
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
322                                                           "AX")
323                               == TRUE);
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
330                                         0,
331                                         (short)fg,
332                                         (short)bg);
333             sp->_default_color = save;
334         }
335 #endif
336         code = OK;
337     }
338     return (code);
339 }
340
341 static void
342 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
343              int fore,
344              int color,
345              NCURSES_SP_OUTC outc)
346 {
347     SCREEN *sp;
348
349     AssertTCB();
350     SetSP();
351
352     if (fore) {
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);
357         } else {
358             TPUTS_TRACE("set_foreground");
359             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
360                                     TPARM_1(set_foreground,
361                                             toggled_colors(color)), 1, outc);
362         }
363     } else {
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);
368         } else {
369             TPUTS_TRACE("set_background");
370             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
371                                     TPARM_1(set_background,
372                                             toggled_colors(color)), 1, outc);
373         }
374     }
375 }
376
377 static bool
378 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
379 {
380     bool result = FALSE;
381     SCREEN *sp;
382
383     AssertTCB();
384     SetSP();
385
386     if (orig_pair != 0) {
387         NCURSES_PUTP2("orig_pair", orig_pair);
388         result = TRUE;
389     }
390     return result;
391 }
392
393 static bool
394 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
395 {
396     int result = FALSE;
397     SCREEN *sp;
398
399     AssertTCB();
400     SetSP();
401
402     if (orig_colors != 0) {
403         NCURSES_PUTP2("orig_colors", orig_colors);
404         result = TRUE;
405     }
406     return result;
407 }
408
409 static int
410 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
411 {
412     SCREEN *sp;
413     bool useEnv = TRUE;
414     bool useTioctl = TRUE;
415
416     AssertTCB();
417     sp = TCB->csp;              /* can be null here */
418
419     if (sp) {
420         useEnv = sp->_use_env;
421         useTioctl = sp->use_tioctl;
422     } else {
423         useEnv = _nc_prescreen.use_env;
424         useTioctl = _nc_prescreen.use_tioctl;
425     }
426
427     /* figure out the size of the screen */
428     T(("screen size: terminfo lines = %d columns = %d", lines, columns));
429
430     *linep = (int) lines;
431     *colp = (int) columns;
432
433     if (useEnv || useTioctl) {
434         int value;
435
436 #ifdef __EMX__
437         {
438             int screendata[2];
439             _scrsize(screendata);
440             *colp = screendata[0];
441             *linep = ((sp != 0 && sp->_filtered)
442                       ? 1
443                       : screendata[1]);
444             T(("EMX screen size: environment LINES = %d COLUMNS = %d",
445                *linep, *colp));
446         }
447 #endif
448 #if HAVE_SIZECHANGE
449         /* try asking the OS */
450         {
451             TERMINAL *termp = (TERMINAL *) TCB;
452             if (NC_ISATTY(termp->Filedes)) {
453                 STRUCT_WINSIZE size;
454
455                 errno = 0;
456                 do {
457                     if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
458                         *linep = ((sp != 0 && sp->_filtered)
459                                   ? 1
460                                   : WINSIZE_ROWS(size));
461                         *colp = WINSIZE_COLS(size);
462                         T(("SYS screen size: environment LINES = %d COLUMNS = %d",
463                            *linep, *colp));
464                         break;
465                     }
466                 } while
467                     (errno == EINTR);
468             }
469         }
470 #endif /* HAVE_SIZECHANGE */
471
472         if (useEnv) {
473             if (useTioctl) {
474                 /*
475                  * If environment variables are used, update them.
476                  */
477                 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
478                     _nc_setenv_num("LINES", *linep);
479                 }
480                 if (_nc_getenv_num("COLUMNS") > 0) {
481                     _nc_setenv_num("COLUMNS", *colp);
482                 }
483             }
484
485             /*
486              * Finally, look for environment variables.
487              *
488              * Solaris lets users override either dimension with an environment
489              * variable.
490              */
491             if ((value = _nc_getenv_num("LINES")) > 0) {
492                 *linep = value;
493                 T(("screen size: environment LINES = %d", *linep));
494             }
495             if ((value = _nc_getenv_num("COLUMNS")) > 0) {
496                 *colp = value;
497                 T(("screen size: environment COLUMNS = %d", *colp));
498             }
499         }
500
501         /* if we can't get dynamic info about the size, use static */
502         if (*linep <= 0) {
503             *linep = (int) lines;
504         }
505         if (*colp <= 0) {
506             *colp = (int) columns;
507         }
508
509         /* the ultimate fallback, assume fixed 24x80 size */
510         if (*linep <= 0) {
511             *linep = 24;
512         }
513         if (*colp <= 0) {
514             *colp = 80;
515         }
516
517         /*
518          * Put the derived values back in the screen-size caps, so
519          * tigetnum() and tgetnum() will do the right thing.
520          */
521         lines = (short) (*linep);
522         columns = (short) (*colp);
523     }
524
525     T(("screen size is %dx%d", *linep, *colp));
526     return OK;
527 }
528
529 static int
530 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
531 {
532     AssertTCB();
533     assert(l != 0 && c != 0);
534     *l = lines;
535     *c = columns;
536     return OK;
537 }
538
539 static int
540 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
541 {
542     AssertTCB();
543     lines = (short) l;
544     columns = (short) c;
545     return OK;
546 }
547
548 static int
549 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
550 {
551     SCREEN *sp = TCB->csp;
552     TERMINAL *_term = (TERMINAL *) TCB;
553     int result = OK;
554
555     AssertTCB();
556     if (setFlag) {
557         for (;;) {
558             if (SET_TTY(_term->Filedes, buf) != 0) {
559                 if (errno == EINTR)
560                     continue;
561                 if (errno == ENOTTY) {
562                     if (sp)
563                         sp->_notty = TRUE;
564                 }
565                 result = ERR;
566             }
567             break;
568         }
569     } else {
570         for (;;) {
571             if (GET_TTY(_term->Filedes, buf) != 0) {
572                 if (errno == EINTR)
573                     continue;
574                 result = ERR;
575             }
576             break;
577         }
578     }
579     return result;
580 }
581
582 static int
583 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
584 {
585     SCREEN *sp;
586     TERMINAL *_term = (TERMINAL *) TCB;
587     int code = ERR;
588
589     AssertTCB();
590     sp = TCB->csp;
591
592     if (progFlag)               /* prog mode */
593     {
594         if (defFlag) {
595             /* def_prog_mode */
596             /*
597              * Turn off the XTABS bit in the tty structure if it was on.
598              */
599             if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
600 #ifdef TERMIOS
601                 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
602 #else
603                 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
604 #endif
605                 code = OK;
606             }
607         } else {
608             /* reset_prog_mode */
609             if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
610                 if (sp) {
611                     if (sp->_keypad_on)
612                         _nc_keypad(sp, TRUE);
613                 }
614                 code = OK;
615             }
616         }
617     } else {                    /* shell mode */
618         if (defFlag) {
619             /* def_shell_mode */
620             /*
621              * If XTABS was on, remove the tab and backtab capabilities.
622              */
623             if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
624 #ifdef TERMIOS
625                 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
626                     tab = back_tab = NULL;
627 #else
628                 if (_term->Ottyb.sg_flags & XTABS)
629                     tab = back_tab = NULL;
630 #endif
631                 code = OK;
632             }
633         } else {
634             /* reset_shell_mode */
635             if (sp) {
636                 _nc_keypad(sp, FALSE);
637                 NCURSES_SP_NAME(_nc_flush) (sp);
638             }
639             code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
640         }
641     }
642     return (code);
643 }
644
645 static void
646 drv_wrap(SCREEN *sp)
647 {
648     if (sp) {
649         sp->_mouse_wrap(sp);
650         NCURSES_SP_NAME(_nc_screen_wrap) (sp);
651         NCURSES_SP_NAME(_nc_mvcur_wrap) (sp);   /* wrap up cursor addressing */
652     }
653 }
654
655 static void
656 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
657 {
658 }
659
660 #  define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
661
662 static void
663 drv_screen_init(SCREEN *sp)
664 {
665     TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
666
667     AssertTCB();
668
669     /*
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.
677      */
678     sp->_use_rmso = SGR0_TEST(exit_standout_mode);
679     sp->_use_rmul = SGR0_TEST(exit_underline_mode);
680
681     /*
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.
685      */
686     sp->_scrolling = ((scroll_forward && scroll_reverse) ||
687                       ((parm_rindex ||
688                         parm_insert_line ||
689                         insert_line) &&
690                        (parm_index ||
691                         parm_delete_line ||
692                         delete_line)));
693
694     NCURSES_SP_NAME(baudrate) (sp);
695
696     NCURSES_SP_NAME(_nc_mvcur_init) (sp);
697     /* initialize terminal to a sane state */
698     NCURSES_SP_NAME(_nc_screen_init) (sp);
699 }
700
701 static void
702 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
703 {
704     TERMINAL *trm;
705
706     AssertTCB();
707
708     trm = (TERMINAL *) TCB;
709
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);
718
719     TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
720
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
727         : 0;
728     TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
729
730     TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
731
732     /*
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
736      * baudrate.
737      */
738     if (NC_ISATTY(trm->Filedes)) {
739         TCB->drv->td_mode(TCB, TRUE, TRUE);
740     }
741 }
742
743 #define MAX_PALETTE     8
744 #define InPalette(n)    ((n) >= 0 && (n) < MAX_PALETTE)
745
746 static void
747 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
748 {
749     SCREEN *sp;
750
751     AssertTCB();
752     SetSP();
753
754     if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
755         const color_t *tp = InfoOf(sp).defaultPalette;
756
757         TR(TRACE_ATTRS,
758            ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
759             pair,
760             tp[f].red, tp[f].green, tp[f].blue,
761             tp[b].red, tp[b].green, tp[b].blue));
762
763         NCURSES_PUTP2("initialize_pair",
764                       TPARM_7(initialize_pair,
765                               pair,
766                               tp[f].red, tp[f].green, tp[f].blue,
767                               tp[b].red, tp[b].green, tp[b].blue));
768     }
769 }
770
771 static int
772 default_fg(SCREEN *sp)
773 {
774 #if NCURSES_EXT_FUNCS
775     return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
776 #else
777     return COLOR_WHITE;
778 #endif
779 }
780
781 static int
782 default_bg(SCREEN *sp)
783 {
784 #if NCURSES_EXT_FUNCS
785     return sp != 0 ? sp->_default_bg : COLOR_BLACK;
786 #else
787     return COLOR_BLACK;
788 #endif
789 }
790
791 static void
792 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
793               int color, int r, int g, int b)
794 {
795     SCREEN *sp = TCB->csp;
796
797     AssertTCB();
798     if (initialize_color != NULL) {
799         NCURSES_PUTP2("initialize_color",
800                       TPARM_4(initialize_color, color, r, g, b));
801     }
802 }
803
804 static void
805 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
806              int old_pair,
807              int pair,
808              int reverse,
809              NCURSES_SP_OUTC outc)
810 {
811     SCREEN *sp = TCB->csp;
812     int fg = COLOR_DEFAULT;
813     int bg = COLOR_DEFAULT;
814     int old_fg, old_bg;
815
816     AssertTCB();
817     if (sp == 0)
818         return;
819
820     if (pair < 0 || pair >= COLOR_PAIRS) {
821         return;
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);
827             return;
828         } else if (sp != 0) {
829             _nc_pair_content(SP_PARM, pair, &fg, &bg);
830         }
831     }
832
833     if (old_pair >= 0
834         && sp != 0
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
839             /*
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.
843              */
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);
852             } else
853 #endif
854                 drv_rescol(TCB);
855         }
856     } else {
857         drv_rescol(TCB);
858         if (old_pair < 0)
859             return;
860     }
861
862 #if NCURSES_EXT_FUNCS
863     if (isDefaultColor(fg))
864         fg = default_fg(sp);
865     if (isDefaultColor(bg))
866         bg = default_bg(sp);
867 #endif
868
869     if (reverse) {
870         int xx = fg;
871         fg = bg;
872         bg = xx;
873     }
874
875     TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
876                      fg, bg));
877
878     if (!isDefaultColor(fg)) {
879         drv_setcolor(TCB, TRUE, fg, outc);
880     }
881     if (!isDefaultColor(bg)) {
882         drv_setcolor(TCB, FALSE, bg, outc);
883     }
884 }
885
886 #define xterm_kmous "\033[M"
887 static void
888 init_xterm_mouse(SCREEN *sp)
889 {
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%;";
894 }
895
896 static void
897 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
898 {
899     SCREEN *sp;
900
901     AssertTCB();
902     SetSP();
903
904     /* we know how to recognize mouse events under "xterm" */
905     if (sp != 0) {
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);
911         }
912     }
913 }
914
915 static int
916 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
917               int delay
918               EVENTLIST_2nd(_nc_eventlist * evl))
919 {
920     int rc = 0;
921     SCREEN *sp;
922
923     AssertTCB();
924     SetSP();
925
926 #if USE_SYSMOUSE
927     if ((sp->_mouse_type == M_SYSMOUSE)
928         && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
929         rc = TW_MOUSE;
930     } else
931 #endif
932     {
933         rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
934                                       TWAIT_MASK,
935                                       delay,
936                                       (int *) 0
937                                       EVENTLIST_2nd(evl));
938 #if USE_SYSMOUSE
939         if ((sp->_mouse_type == M_SYSMOUSE)
940             && (sp->_sysmouse_head < sp->_sysmouse_tail)
941             && (rc == 0)
942             && (errno == EINTR)) {
943             rc |= TW_MOUSE;
944         }
945 #endif
946     }
947     return rc;
948 }
949
950 static int
951 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
952 {
953     SCREEN *sp = TCB->csp;
954     AssertTCB();
955     return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
956 }
957
958 static void
959 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
960 {
961     SCREEN *sp = TCB->csp;
962
963     AssertTCB();
964     if (labnum > 0 && labnum <= num_labels) {
965         NCURSES_PUTP2("plab_norm",
966                       TPARM_2(plab_norm, labnum, text));
967     }
968 }
969
970 static void
971 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
972 {
973     SCREEN *sp = TCB->csp;
974
975     AssertTCB();
976     if (OnFlag) {
977         NCURSES_PUTP2("label_on", label_on);
978     } else {
979         NCURSES_PUTP2("label_off", label_off);
980     }
981 }
982
983 static chtype
984 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
985 {
986     SCREEN *sp = TCB->csp;
987     chtype attrs = A_NORMAL;
988
989     AssertTCB();
990     if (enter_alt_charset_mode)
991         attrs |= A_ALTCHARSET;
992
993     if (enter_blink_mode)
994         attrs |= A_BLINK;
995
996     if (enter_bold_mode)
997         attrs |= A_BOLD;
998
999     if (enter_dim_mode)
1000         attrs |= A_DIM;
1001
1002     if (enter_reverse_mode)
1003         attrs |= A_REVERSE;
1004
1005     if (enter_standout_mode)
1006         attrs |= A_STANDOUT;
1007
1008     if (enter_protected_mode)
1009         attrs |= A_PROTECT;
1010
1011     if (enter_secure_mode)
1012         attrs |= A_INVIS;
1013
1014     if (enter_underline_mode)
1015         attrs |= A_UNDERLINE;
1016
1017     if (sp && sp->_coloron)
1018         attrs |= A_COLOR;
1019
1020 #if USE_ITALIC
1021     if (enter_italics_mode)
1022         attrs |= A_ITALIC;
1023 #endif
1024
1025     return (attrs);
1026 }
1027
1028 static void
1029 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1030 {
1031     AssertTCB();
1032
1033     /* *INDENT-EQLS* */
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;
1042
1043     if (back_color_erase)
1044         clr_eos = ABSENT_STRING;
1045 }
1046
1047 static void
1048 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1049 {
1050     SCREEN *sp = TCB->csp;
1051
1052     AssertTCB();
1053     assert(sp != 0);
1054     if (ena_acs != NULL) {
1055         NCURSES_PUTP2("ena_acs", ena_acs);
1056     }
1057 #if NCURSES_EXT_FUNCS
1058     /*
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.
1065      *
1066      * test/blue.c uses this feature.
1067      */
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)) {
1071         size_t i;
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) {
1076                     if (sp != 0)
1077                         sp->_screen_acs_map[i] = TRUE;
1078                 }
1079             }
1080         }
1081     }
1082 #endif
1083
1084     if (acs_chars != NULL) {
1085         size_t i = 0;
1086         size_t length = strlen(acs_chars);
1087
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",
1092                    (int) i,
1093                    _tracechar(UChar(acs_chars[i])),
1094                    _tracechtype(real_map[UChar(acs_chars[i])])));
1095                 if (sp != 0) {
1096                     sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1097                 }
1098             }
1099             i += 2;
1100         }
1101     }
1102 #ifdef TRACE
1103     /* Show the equivalent mapping, noting if it does not match the
1104      * given attribute, whether by re-ordering or duplication.
1105      */
1106     if (USE_TRACEF(TRACE_CALLS)) {
1107         size_t n, m;
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]);
1113             }
1114         }
1115         show[m] = 0;
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",
1121                 (acs_chars == NULL)
1122                 ? "NULL"
1123                 : (strcmp(acs_chars, show)
1124                    ? "DIFF"
1125                    : "SAME"),
1126                 _nc_visbuf(show));
1127         _nc_unlock_global(tracef);
1128     }
1129 #endif /* TRACE */
1130 }
1131
1132 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1133
1134 NCURSES_EXPORT(void)
1135 _nc_cookie_init(SCREEN *sp)
1136 {
1137     bool support_cookies = USE_XMC_SUPPORT;
1138     TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1139
1140     if (sp == 0 || !ENSURE_TINFO(sp))
1141         return;
1142
1143 #if USE_XMC_SUPPORT
1144     /*
1145      * If we have no magic-cookie support compiled-in, or if it is suppressed
1146      * in the environment, reset the support-flag.
1147      */
1148     if (magic_cookie_glitch >= 0) {
1149         if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1150             support_cookies = FALSE;
1151         }
1152     }
1153 #endif
1154
1155     if (!support_cookies && magic_cookie_glitch >= 0) {
1156         T(("will disable attributes to work w/o magic cookies"));
1157     }
1158
1159     if (magic_cookie_glitch > 0) {      /* tvi, wyse */
1160
1161         sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1162 #if 0
1163         /*
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
1166          * cookies.
1167          */
1168         if (has_colors()) {
1169             sp->_xmc_triggers |= A_COLOR;
1170         }
1171 #endif
1172         sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1173
1174         T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1175         /*
1176          * Supporting line-drawing may be possible.  But make the regular
1177          * video attributes work first.
1178          */
1179         acs_chars = ABSENT_STRING;
1180         ena_acs = ABSENT_STRING;
1181         enter_alt_charset_mode = ABSENT_STRING;
1182         exit_alt_charset_mode = ABSENT_STRING;
1183 #if USE_XMC_SUPPORT
1184         /*
1185          * To keep the cookie support simple, suppress all of the optimization
1186          * hooks except for clear_screen and the cursor addressing.
1187          */
1188         if (support_cookies) {
1189             clr_eol = ABSENT_STRING;
1190             clr_eos = ABSENT_STRING;
1191             set_attributes = ABSENT_STRING;
1192         }
1193 #endif
1194     } else if (magic_cookie_glitch == 0) {      /* hpterm */
1195     }
1196
1197     /*
1198      * If magic cookies are not supported, cancel the strings that set
1199      * video attributes.
1200      */
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;
1210     }
1211
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)) {
1215         acs_chars = NULL;
1216         ena_acs = NULL;
1217         enter_alt_charset_mode = NULL;
1218         exit_alt_charset_mode = NULL;
1219         set_attributes = NULL;
1220     }
1221 #endif
1222 }
1223
1224 static int
1225 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1226           int mode,
1227           int milliseconds,
1228           int *timeleft
1229           EVENTLIST_2nd(_nc_eventlist * evl))
1230 {
1231     SCREEN *sp;
1232
1233     AssertTCB();
1234     SetSP();
1235
1236     return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1237 }
1238
1239 static int
1240 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1241 {
1242     SCREEN *sp;
1243     unsigned char c2 = 0;
1244     int n;
1245
1246     AssertTCB();
1247     assert(buf);
1248     SetSP();
1249
1250 # if USE_PTHREADS_EINTR
1251     if ((pthread_self) && (pthread_kill) && (pthread_equal))
1252         _nc_globals.read_thread = pthread_self();
1253 # endif
1254     n = (int) read(sp->_ifd, &c2, (size_t) 1);
1255 #if USE_PTHREADS_EINTR
1256     _nc_globals.read_thread = 0;
1257 #endif
1258     *buf = (int) c2;
1259     return n;
1260 }
1261
1262 static int
1263 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1264 {
1265 #if HAVE_NANOSLEEP
1266     {
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;
1273         }
1274     }
1275 #else
1276     _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1277 #endif
1278     return OK;
1279 }
1280
1281 static int
1282 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1283 {
1284     int rc = ERR;
1285
1286     if (value) {
1287         rc = NCURSES_PUTP2(name, value);
1288     }
1289     return rc;
1290 }
1291
1292 static int
1293 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1294 {
1295     int rc = __nc_putp(sp, name, value);
1296     if (rc != ERR) {
1297         NCURSES_SP_NAME(_nc_flush) (sp);
1298     }
1299     return rc;
1300 }
1301
1302 static int
1303 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1304 {
1305     int ret = ERR;
1306     SCREEN *sp;
1307
1308     AssertTCB();
1309
1310     sp = TCB->csp;
1311
1312     if (sp) {
1313         if (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);
1317         }
1318         if (flag && !sp->_tried) {
1319             _nc_init_keytry(sp);
1320             sp->_tried = TRUE;
1321         }
1322         ret = OK;
1323     }
1324
1325     return ret;
1326 }
1327
1328 static int
1329 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1330 {
1331     SCREEN *sp;
1332     int code = ERR;
1333     int count = 0;
1334     char *s;
1335
1336     AssertTCB();
1337     SetSP();
1338
1339     if (c >= 0) {
1340         unsigned ch = (unsigned) c;
1341         if (flag) {
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);
1346                 free(s);
1347                 count = 0;
1348                 if (code != OK)
1349                     break;
1350             }
1351         } else {
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);
1356                 free(s);
1357                 count = 0;
1358                 if (code != OK)
1359                     break;
1360             }
1361         }
1362     }
1363     return (code);
1364 }
1365
1366 static int
1367 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1368 {
1369     SCREEN *sp;
1370     int code = ERR;
1371
1372     AssertTCB();
1373     SetSP();
1374
1375     T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1376
1377     if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1378         switch (vis) {
1379         case 2:
1380             code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1381             break;
1382         case 1:
1383             code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1384             break;
1385         case 0:
1386             code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1387             break;
1388         }
1389     } else {
1390         code = ERR;
1391     }
1392     returnCode(code);
1393 }
1394
1395 static bool
1396 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1397 {
1398     bool res = FALSE;
1399
1400     AssertTCB();
1401     if (TCB->csp)
1402         res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1403
1404     return res;
1405 }
1406
1407 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1408     TRUE,
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 */
1440         drv_nap,                /* nap */
1441         drv_kpad,               /* kpad */
1442         drv_keyok,              /* kyOk */
1443         drv_kyExist,            /* kyExist */
1444         drv_cursorSet           /* cursorSet */
1445 };