]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/tinfo_driver.c
ncurses 6.0 - patch 20170415
[ncurses.git] / ncurses / tinfo / tinfo_driver.c
1 /****************************************************************************
2  * Copyright (c) 2008-2016,2017 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.51 2017/04/14 08:19:49 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 static bool
148 drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
149 {
150     bool result = FALSE;
151     int status;
152     TERMINAL *termp;
153     SCREEN *sp;
154
155     START_TRACE();
156     T((T_CALLED("tinfo::drv_CanHandle(%p)"), (void *) TCB));
157
158     assert(TCB != 0 && tname != 0);
159     termp = (TERMINAL *) TCB;
160     sp = TCB->csp;
161     TCB->magic = TCBMAGIC;
162
163 #if (NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP)
164     status = _nc_setup_tinfo(tname, &TerminalType(termp));
165 #else
166     status = TGETENT_NO;
167 #endif
168
169     /* try fallback list if entry on disk */
170     if (status != TGETENT_YES) {
171         const TERMTYPE2 *fallback = _nc_fallback2(tname);
172
173         if (fallback) {
174             TerminalType(termp) = *fallback;
175             status = TGETENT_YES;
176         }
177     }
178
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);
185         }
186     }
187     result = TRUE;
188 #if NCURSES_EXT_NUMBERS
189     _nc_export_termtype2(&termp->type, &TerminalType(termp));
190 #endif
191 #if !USE_REENTRANT
192 #define MY_SIZE (size_t) NAMESIZE - 1
193     _nc_STRNCPY(ttytype, termp->type.term_names, MY_SIZE);
194     ttytype[MY_SIZE] = '\0';
195 #endif
196
197     if (command_character)
198         _nc_tinfo_cmdch(termp, *command_character);
199
200     /*
201      * If an application calls setupterm() rather than initscr() or
202      * newterm(), we will not have the def_prog_mode() call in
203      * _nc_setupscreen().  Do it now anyway, so we can initialize the
204      * baudrate.
205      */
206     if (sp == 0 && NC_ISATTY(termp->Filedes)) {
207         get_baudrate(termp);
208     }
209
210     if (generic_type) {
211         /*
212          * BSD 4.3's termcap contains mis-typed "gn" for wy99.  Do a sanity
213          * check before giving up.
214          */
215         if ((VALID_STRING(cursor_address)
216              || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
217             && VALID_STRING(clear_screen)) {
218             ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
219         } else {
220             ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
221         }
222     }
223     if (hard_copy) {
224         ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
225     }
226
227     returnBool(result);
228 }
229
230 static int
231 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
232 {
233     SCREEN *sp;
234     int res = ERR;
235
236     AssertTCB();
237     SetSP();
238
239     /* FIXME: should make sure that we are not in altchar mode */
240     if (beepFlag) {
241         if (bell) {
242             res = NCURSES_PUTP2("bell", bell);
243             NCURSES_SP_NAME(_nc_flush) (sp);
244         } else if (flash_screen) {
245             res = NCURSES_PUTP2("flash_screen", flash_screen);
246             NCURSES_SP_NAME(_nc_flush) (sp);
247         }
248     } else {
249         if (flash_screen) {
250             res = NCURSES_PUTP2("flash_screen", flash_screen);
251             NCURSES_SP_NAME(_nc_flush) (sp);
252         } else if (bell) {
253             res = NCURSES_PUTP2("bell", bell);
254             NCURSES_SP_NAME(_nc_flush) (sp);
255         }
256     }
257     return res;
258 }
259
260 /*
261  * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
262  * to maintain compatibility with a pre-ANSI scheme.  The same scheme is
263  * also used in the FreeBSD syscons.
264  */
265 static int
266 toggled_colors(int c)
267 {
268     if (c < 16) {
269         static const int table[] =
270         {0, 4, 2, 6, 1, 5, 3, 7,
271          8, 12, 10, 14, 9, 13, 11, 15};
272         c = table[c];
273     }
274     return c;
275 }
276
277 static int
278 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
279 {
280     SCREEN *sp;
281
282     AssertTCB();
283     SetSP();
284 #if NCURSES_EXT_FUNCS
285     return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
286 #else
287     return ERR;
288 #endif
289 }
290
291 static int
292 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
293 {
294     SCREEN *sp;
295     int code = ERR;
296
297     AssertTCB();
298     SetSP();
299
300     if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
301 #if NCURSES_EXT_FUNCS
302         sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
303         sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
304                                                           "AX")
305                               == TRUE);
306         sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
307         sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
308         if (sp->_color_pairs != 0) {
309             bool save = sp->_default_color;
310             sp->_default_color = TRUE;
311             NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
312                                         0,
313                                         (short)fg,
314                                         (short)bg);
315             sp->_default_color = save;
316         }
317 #endif
318         code = OK;
319     }
320     return (code);
321 }
322
323 static void
324 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
325              int fore,
326              int color,
327              NCURSES_SP_OUTC outc)
328 {
329     SCREEN *sp;
330
331     AssertTCB();
332     SetSP();
333
334     if (fore) {
335         if (set_a_foreground) {
336             TPUTS_TRACE("set_a_foreground");
337             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
338                                     TPARM_1(set_a_foreground, color), 1, outc);
339         } else {
340             TPUTS_TRACE("set_foreground");
341             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
342                                     TPARM_1(set_foreground,
343                                             toggled_colors(color)), 1, outc);
344         }
345     } else {
346         if (set_a_background) {
347             TPUTS_TRACE("set_a_background");
348             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
349                                     TPARM_1(set_a_background, color), 1, outc);
350         } else {
351             TPUTS_TRACE("set_background");
352             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
353                                     TPARM_1(set_background,
354                                             toggled_colors(color)), 1, outc);
355         }
356     }
357 }
358
359 static bool
360 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
361 {
362     bool result = FALSE;
363     SCREEN *sp;
364
365     AssertTCB();
366     SetSP();
367
368     if (orig_pair != 0) {
369         NCURSES_PUTP2("orig_pair", orig_pair);
370         result = TRUE;
371     }
372     return result;
373 }
374
375 static bool
376 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
377 {
378     int result = FALSE;
379     SCREEN *sp;
380
381     AssertTCB();
382     SetSP();
383
384     if (orig_colors != 0) {
385         NCURSES_PUTP2("orig_colors", orig_colors);
386         result = TRUE;
387     }
388     return result;
389 }
390
391 static int
392 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
393 {
394     SCREEN *sp;
395     bool useEnv = TRUE;
396     bool useTioctl = TRUE;
397
398     AssertTCB();
399     sp = TCB->csp;              /* can be null here */
400
401     if (sp) {
402         useEnv = sp->_use_env;
403         useTioctl = sp->use_tioctl;
404     } else {
405         useEnv = _nc_prescreen.use_env;
406         useTioctl = _nc_prescreen.use_tioctl;
407     }
408
409     /* figure out the size of the screen */
410     T(("screen size: terminfo lines = %d columns = %d", lines, columns));
411
412     *linep = (int) lines;
413     *colp = (int) columns;
414
415     if (useEnv || useTioctl) {
416         int value;
417
418 #ifdef __EMX__
419         {
420             int screendata[2];
421             _scrsize(screendata);
422             *colp = screendata[0];
423             *linep = ((sp != 0 && sp->_filtered)
424                       ? 1
425                       : screendata[1]);
426             T(("EMX screen size: environment LINES = %d COLUMNS = %d",
427                *linep, *colp));
428         }
429 #endif
430 #if HAVE_SIZECHANGE
431         /* try asking the OS */
432         {
433             TERMINAL *termp = (TERMINAL *) TCB;
434             if (NC_ISATTY(termp->Filedes)) {
435                 STRUCT_WINSIZE size;
436
437                 errno = 0;
438                 do {
439                     if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
440                         *linep = ((sp != 0 && sp->_filtered)
441                                   ? 1
442                                   : WINSIZE_ROWS(size));
443                         *colp = WINSIZE_COLS(size);
444                         T(("SYS screen size: environment LINES = %d COLUMNS = %d",
445                            *linep, *colp));
446                         break;
447                     }
448                 } while
449                     (errno == EINTR);
450             }
451         }
452 #endif /* HAVE_SIZECHANGE */
453
454         if (useEnv) {
455             if (useTioctl) {
456                 /*
457                  * If environment variables are used, update them.
458                  */
459                 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
460                     _nc_setenv_num("LINES", *linep);
461                 }
462                 if (_nc_getenv_num("COLUMNS") > 0) {
463                     _nc_setenv_num("COLUMNS", *colp);
464                 }
465             }
466
467             /*
468              * Finally, look for environment variables.
469              *
470              * Solaris lets users override either dimension with an environment
471              * variable.
472              */
473             if ((value = _nc_getenv_num("LINES")) > 0) {
474                 *linep = value;
475                 T(("screen size: environment LINES = %d", *linep));
476             }
477             if ((value = _nc_getenv_num("COLUMNS")) > 0) {
478                 *colp = value;
479                 T(("screen size: environment COLUMNS = %d", *colp));
480             }
481         }
482
483         /* if we can't get dynamic info about the size, use static */
484         if (*linep <= 0) {
485             *linep = (int) lines;
486         }
487         if (*colp <= 0) {
488             *colp = (int) columns;
489         }
490
491         /* the ultimate fallback, assume fixed 24x80 size */
492         if (*linep <= 0) {
493             *linep = 24;
494         }
495         if (*colp <= 0) {
496             *colp = 80;
497         }
498
499         /*
500          * Put the derived values back in the screen-size caps, so
501          * tigetnum() and tgetnum() will do the right thing.
502          */
503         lines = (short) (*linep);
504         columns = (short) (*colp);
505     }
506
507     T(("screen size is %dx%d", *linep, *colp));
508     return OK;
509 }
510
511 static int
512 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
513 {
514     AssertTCB();
515     assert(l != 0 && c != 0);
516     *l = lines;
517     *c = columns;
518     return OK;
519 }
520
521 static int
522 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
523 {
524     AssertTCB();
525     lines = (short) l;
526     columns = (short) c;
527     return OK;
528 }
529
530 static int
531 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
532 {
533     SCREEN *sp = TCB->csp;
534     TERMINAL *_term = (TERMINAL *) TCB;
535     int result = OK;
536
537     AssertTCB();
538     if (setFlag) {
539         for (;;) {
540             if (SET_TTY(_term->Filedes, buf) != 0) {
541                 if (errno == EINTR)
542                     continue;
543                 if (errno == ENOTTY) {
544                     if (sp)
545                         sp->_notty = TRUE;
546                 }
547                 result = ERR;
548             }
549             break;
550         }
551     } else {
552         for (;;) {
553             if (GET_TTY(_term->Filedes, buf) != 0) {
554                 if (errno == EINTR)
555                     continue;
556                 result = ERR;
557             }
558             break;
559         }
560     }
561     return result;
562 }
563
564 static int
565 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
566 {
567     SCREEN *sp;
568     TERMINAL *_term = (TERMINAL *) TCB;
569     int code = ERR;
570
571     AssertTCB();
572     sp = TCB->csp;
573
574     if (progFlag)               /* prog mode */
575     {
576         if (defFlag) {
577             /* def_prog_mode */
578             /*
579              * Turn off the XTABS bit in the tty structure if it was on.
580              */
581             if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
582 #ifdef TERMIOS
583                 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
584 #else
585                 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
586 #endif
587                 code = OK;
588             }
589         } else {
590             /* reset_prog_mode */
591             if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
592                 if (sp) {
593                     if (sp->_keypad_on)
594                         _nc_keypad(sp, TRUE);
595                 }
596                 code = OK;
597             }
598         }
599     } else {                    /* shell mode */
600         if (defFlag) {
601             /* def_shell_mode */
602             /*
603              * If XTABS was on, remove the tab and backtab capabilities.
604              */
605             if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
606 #ifdef TERMIOS
607                 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
608                     tab = back_tab = NULL;
609 #else
610                 if (_term->Ottyb.sg_flags & XTABS)
611                     tab = back_tab = NULL;
612 #endif
613                 code = OK;
614             }
615         } else {
616             /* reset_shell_mode */
617             if (sp) {
618                 _nc_keypad(sp, FALSE);
619                 NCURSES_SP_NAME(_nc_flush) (sp);
620             }
621             code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
622         }
623     }
624     return (code);
625 }
626
627 static void
628 drv_wrap(SCREEN *sp)
629 {
630     if (sp) {
631         sp->_mouse_wrap(sp);
632         NCURSES_SP_NAME(_nc_screen_wrap) (sp);
633         NCURSES_SP_NAME(_nc_mvcur_wrap) (sp);   /* wrap up cursor addressing */
634     }
635 }
636
637 static void
638 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
639 {
640 }
641
642 #  define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
643
644 static void
645 drv_screen_init(SCREEN *sp)
646 {
647     TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
648
649     AssertTCB();
650
651     /*
652      * Check for mismatched graphic-rendition capabilities.  Most SVr4
653      * terminfo trees contain entries that have rmul or rmso equated to
654      * sgr0 (Solaris curses copes with those entries).  We do this only
655      * for curses, since many termcap applications assume that
656      * smso/rmso and smul/rmul are paired, and will not function
657      * properly if we remove rmso or rmul.  Curses applications
658      * shouldn't be looking at this detail.
659      */
660     sp->_use_rmso = SGR0_TEST(exit_standout_mode);
661     sp->_use_rmul = SGR0_TEST(exit_underline_mode);
662
663     /*
664      * Check whether we can optimize scrolling under dumb terminals in
665      * case we do not have any of these capabilities, scrolling
666      * optimization will be useless.
667      */
668     sp->_scrolling = ((scroll_forward && scroll_reverse) ||
669                       ((parm_rindex ||
670                         parm_insert_line ||
671                         insert_line) &&
672                        (parm_index ||
673                         parm_delete_line ||
674                         delete_line)));
675
676     NCURSES_SP_NAME(baudrate) (sp);
677
678     NCURSES_SP_NAME(_nc_mvcur_init) (sp);
679     /* initialize terminal to a sane state */
680     NCURSES_SP_NAME(_nc_screen_init) (sp);
681 }
682
683 static void
684 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
685 {
686     TERMINAL *trm;
687
688     AssertTCB();
689
690     trm = (TERMINAL *) TCB;
691
692     TCB->info.initcolor = VALID_STRING(initialize_color);
693     TCB->info.canchange = can_change;
694     TCB->info.hascolor = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
695                            && (((set_foreground != NULL)
696                                 && (set_background != NULL))
697                                || ((set_a_foreground != NULL)
698                                    && (set_a_background != NULL))
699                                || set_color_pair)) ? TRUE : FALSE);
700
701     TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
702
703     TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
704     TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
705     TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
706     TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
707     TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
708     TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
709         : 0;
710     TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
711
712     TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
713
714     /*
715      * If an application calls setupterm() rather than initscr() or
716      * newterm(), we will not have the def_prog_mode() call in
717      * _nc_setupscreen().  Do it now anyway, so we can initialize the
718      * baudrate.
719      */
720     if (NC_ISATTY(trm->Filedes)) {
721         TCB->drv->td_mode(TCB, TRUE, TRUE);
722     }
723 }
724
725 #define MAX_PALETTE     8
726 #define InPalette(n)    ((n) >= 0 && (n) < MAX_PALETTE)
727
728 static void
729 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
730 {
731     SCREEN *sp;
732
733     AssertTCB();
734     SetSP();
735
736     if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
737         const color_t *tp = InfoOf(sp).defaultPalette;
738
739         TR(TRACE_ATTRS,
740            ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
741             pair,
742             tp[f].red, tp[f].green, tp[f].blue,
743             tp[b].red, tp[b].green, tp[b].blue));
744
745         NCURSES_PUTP2("initialize_pair",
746                       TPARM_7(initialize_pair,
747                               pair,
748                               tp[f].red, tp[f].green, tp[f].blue,
749                               tp[b].red, tp[b].green, tp[b].blue));
750     }
751 }
752
753 static int
754 default_fg(SCREEN *sp)
755 {
756 #if NCURSES_EXT_FUNCS
757     return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
758 #else
759     return COLOR_WHITE;
760 #endif
761 }
762
763 static int
764 default_bg(SCREEN *sp)
765 {
766 #if NCURSES_EXT_FUNCS
767     return sp != 0 ? sp->_default_bg : COLOR_BLACK;
768 #else
769     return COLOR_BLACK;
770 #endif
771 }
772
773 static void
774 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
775               int color, int r, int g, int b)
776 {
777     SCREEN *sp = TCB->csp;
778
779     AssertTCB();
780     if (initialize_color != NULL) {
781         NCURSES_PUTP2("initialize_color",
782                       TPARM_4(initialize_color, color, r, g, b));
783     }
784 }
785
786 static void
787 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
788              int old_pair,
789              int pair,
790              int reverse,
791              NCURSES_SP_OUTC outc)
792 {
793     SCREEN *sp = TCB->csp;
794     int fg = COLOR_DEFAULT;
795     int bg = COLOR_DEFAULT;
796     int old_fg, old_bg;
797
798     AssertTCB();
799     if (sp == 0)
800         return;
801
802     if (pair < 0 || pair >= COLOR_PAIRS) {
803         return;
804     } else if (pair != 0) {
805         if (set_color_pair) {
806             TPUTS_TRACE("set_color_pair");
807             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
808                                     TPARM_1(set_color_pair, pair), 1, outc);
809             return;
810         } else if (sp != 0) {
811             _nc_pair_content(SP_PARM, pair, &fg, &bg);
812         }
813     }
814
815     if (old_pair >= 0
816         && sp != 0
817         && _nc_pair_content(SP_PARM, old_pair, &old_fg, &old_bg) != ERR) {
818         if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
819             || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
820 #if NCURSES_EXT_FUNCS
821             /*
822              * A minor optimization - but extension.  If "AX" is specified in
823              * the terminal description, treat it as screen's indicator of ECMA
824              * SGR 39 and SGR 49, and assume the two sequences are independent.
825              */
826             if (sp->_has_sgr_39_49
827                 && isDefaultColor(old_bg)
828                 && !isDefaultColor(old_fg)) {
829                 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
830             } else if (sp->_has_sgr_39_49
831                        && isDefaultColor(old_fg)
832                        && !isDefaultColor(old_bg)) {
833                 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
834             } else
835 #endif
836                 drv_rescol(TCB);
837         }
838     } else {
839         drv_rescol(TCB);
840         if (old_pair < 0)
841             return;
842     }
843
844 #if NCURSES_EXT_FUNCS
845     if (isDefaultColor(fg))
846         fg = default_fg(sp);
847     if (isDefaultColor(bg))
848         bg = default_bg(sp);
849 #endif
850
851     if (reverse) {
852         int xx = fg;
853         fg = bg;
854         bg = xx;
855     }
856
857     TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
858                      fg, bg));
859
860     if (!isDefaultColor(fg)) {
861         drv_setcolor(TCB, TRUE, fg, outc);
862     }
863     if (!isDefaultColor(bg)) {
864         drv_setcolor(TCB, FALSE, bg, outc);
865     }
866 }
867
868 #define xterm_kmous "\033[M"
869 static void
870 init_xterm_mouse(SCREEN *sp)
871 {
872     sp->_mouse_type = M_XTERM;
873     sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
874     if (!VALID_STRING(sp->_mouse_xtermcap))
875         sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
876 }
877
878 static void
879 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
880 {
881     SCREEN *sp;
882
883     AssertTCB();
884     SetSP();
885
886     /* we know how to recognize mouse events under "xterm" */
887     if (sp != 0) {
888         if (key_mouse != 0) {
889             if (!strcmp(key_mouse, xterm_kmous)
890                 || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
891                 init_xterm_mouse(sp);
892             }
893         } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
894             if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
895                 init_xterm_mouse(sp);
896         }
897     }
898 }
899
900 static int
901 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
902               int delay
903               EVENTLIST_2nd(_nc_eventlist * evl))
904 {
905     int rc = 0;
906     SCREEN *sp;
907
908     AssertTCB();
909     SetSP();
910
911 #if USE_SYSMOUSE
912     if ((sp->_mouse_type == M_SYSMOUSE)
913         && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
914         rc = TW_MOUSE;
915     } else
916 #endif
917     {
918         rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
919                                       TWAIT_MASK,
920                                       delay,
921                                       (int *) 0
922                                       EVENTLIST_2nd(evl));
923 #if USE_SYSMOUSE
924         if ((sp->_mouse_type == M_SYSMOUSE)
925             && (sp->_sysmouse_head < sp->_sysmouse_tail)
926             && (rc == 0)
927             && (errno == EINTR)) {
928             rc |= TW_MOUSE;
929         }
930 #endif
931     }
932     return rc;
933 }
934
935 static int
936 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
937 {
938     SCREEN *sp = TCB->csp;
939     AssertTCB();
940     return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
941 }
942
943 static void
944 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
945 {
946     SCREEN *sp = TCB->csp;
947
948     AssertTCB();
949     if (labnum > 0 && labnum <= num_labels) {
950         NCURSES_PUTP2("plab_norm",
951                       TPARM_2(plab_norm, labnum, text));
952     }
953 }
954
955 static void
956 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
957 {
958     SCREEN *sp = TCB->csp;
959
960     AssertTCB();
961     if (OnFlag) {
962         NCURSES_PUTP2("label_on", label_on);
963     } else {
964         NCURSES_PUTP2("label_off", label_off);
965     }
966 }
967
968 static chtype
969 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
970 {
971     SCREEN *sp = TCB->csp;
972     chtype attrs = A_NORMAL;
973
974     AssertTCB();
975     if (enter_alt_charset_mode)
976         attrs |= A_ALTCHARSET;
977
978     if (enter_blink_mode)
979         attrs |= A_BLINK;
980
981     if (enter_bold_mode)
982         attrs |= A_BOLD;
983
984     if (enter_dim_mode)
985         attrs |= A_DIM;
986
987     if (enter_reverse_mode)
988         attrs |= A_REVERSE;
989
990     if (enter_standout_mode)
991         attrs |= A_STANDOUT;
992
993     if (enter_protected_mode)
994         attrs |= A_PROTECT;
995
996     if (enter_secure_mode)
997         attrs |= A_INVIS;
998
999     if (enter_underline_mode)
1000         attrs |= A_UNDERLINE;
1001
1002     if (sp && sp->_coloron)
1003         attrs |= A_COLOR;
1004
1005 #if USE_ITALIC
1006     if (enter_italics_mode)
1007         attrs |= A_ITALIC;
1008 #endif
1009
1010     return (attrs);
1011 }
1012
1013 static void
1014 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1015 {
1016     AssertTCB();
1017
1018     clear_screen = 0;
1019     cursor_down = parm_down_cursor = 0;
1020     cursor_address = 0;
1021     cursor_up = parm_up_cursor = 0;
1022     row_address = 0;
1023     cursor_home = carriage_return;
1024 }
1025
1026 static void
1027 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1028 {
1029     SCREEN *sp = TCB->csp;
1030
1031     AssertTCB();
1032     assert(sp != 0);
1033     if (ena_acs != NULL) {
1034         NCURSES_PUTP2("ena_acs", ena_acs);
1035     }
1036 #if NCURSES_EXT_FUNCS
1037     /*
1038      * Linux console "supports" the "PC ROM" character set by the coincidence
1039      * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
1040      * no codepage support (see SCO Merge for an example).  Outside of the
1041      * values defined in acsc, there are no definitions for the "PC ROM"
1042      * character set (assumed by some applications to be codepage 437), but we
1043      * allow those applications to use those codepoints.
1044      *
1045      * test/blue.c uses this feature.
1046      */
1047 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1048     if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
1049         PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
1050         size_t i;
1051         for (i = 1; i < ACS_LEN; ++i) {
1052             if (real_map[i] == 0) {
1053                 real_map[i] = (chtype) i;
1054                 if (real_map != fake_map) {
1055                     if (sp != 0)
1056                         sp->_screen_acs_map[i] = TRUE;
1057                 }
1058             }
1059         }
1060     }
1061 #endif
1062
1063     if (acs_chars != NULL) {
1064         size_t i = 0;
1065         size_t length = strlen(acs_chars);
1066
1067         while (i + 1 < length) {
1068             if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
1069                 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
1070                 if (sp != 0)
1071                     sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1072             }
1073             i += 2;
1074         }
1075     }
1076 #ifdef TRACE
1077     /* Show the equivalent mapping, noting if it does not match the
1078      * given attribute, whether by re-ordering or duplication.
1079      */
1080     if (USE_TRACEF(TRACE_CALLS)) {
1081         size_t n, m;
1082         char show[ACS_LEN * 2 + 1];
1083         for (n = 1, m = 0; n < ACS_LEN; n++) {
1084             if (real_map[n] != 0) {
1085                 show[m++] = (char) n;
1086                 show[m++] = (char) ChCharOf(real_map[n]);
1087             }
1088         }
1089         show[m] = 0;
1090         if (acs_chars == NULL || strcmp(acs_chars, show))
1091             _tracef("%s acs_chars %s",
1092                     (acs_chars == NULL) ? "NULL" : "READ",
1093                     _nc_visbuf(acs_chars));
1094         _tracef("%s acs_chars %s",
1095                 (acs_chars == NULL)
1096                 ? "NULL"
1097                 : (strcmp(acs_chars, show)
1098                    ? "DIFF"
1099                    : "SAME"),
1100                 _nc_visbuf(show));
1101
1102         _nc_unlock_global(tracef);
1103     }
1104 #endif /* TRACE */
1105 }
1106
1107 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1108
1109 NCURSES_EXPORT(void)
1110 _nc_cookie_init(SCREEN *sp)
1111 {
1112     bool support_cookies = USE_XMC_SUPPORT;
1113     TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1114
1115     if (sp == 0 || !ENSURE_TINFO(sp))
1116         return;
1117
1118 #if USE_XMC_SUPPORT
1119     /*
1120      * If we have no magic-cookie support compiled-in, or if it is suppressed
1121      * in the environment, reset the support-flag.
1122      */
1123     if (magic_cookie_glitch >= 0) {
1124         if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1125             support_cookies = FALSE;
1126         }
1127     }
1128 #endif
1129
1130     if (!support_cookies && magic_cookie_glitch >= 0) {
1131         T(("will disable attributes to work w/o magic cookies"));
1132     }
1133
1134     if (magic_cookie_glitch > 0) {      /* tvi, wyse */
1135
1136         sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1137 #if 0
1138         /*
1139          * We "should" treat colors as an attribute.  The wyse350 (and its
1140          * clones) appear to be the only ones that have both colors and magic
1141          * cookies.
1142          */
1143         if (has_colors()) {
1144             sp->_xmc_triggers |= A_COLOR;
1145         }
1146 #endif
1147         sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1148
1149         T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1150         /*
1151          * Supporting line-drawing may be possible.  But make the regular
1152          * video attributes work first.
1153          */
1154         acs_chars = ABSENT_STRING;
1155         ena_acs = ABSENT_STRING;
1156         enter_alt_charset_mode = ABSENT_STRING;
1157         exit_alt_charset_mode = ABSENT_STRING;
1158 #if USE_XMC_SUPPORT
1159         /*
1160          * To keep the cookie support simple, suppress all of the optimization
1161          * hooks except for clear_screen and the cursor addressing.
1162          */
1163         if (support_cookies) {
1164             clr_eol = ABSENT_STRING;
1165             clr_eos = ABSENT_STRING;
1166             set_attributes = ABSENT_STRING;
1167         }
1168 #endif
1169     } else if (magic_cookie_glitch == 0) {      /* hpterm */
1170     }
1171
1172     /*
1173      * If magic cookies are not supported, cancel the strings that set
1174      * video attributes.
1175      */
1176     if (!support_cookies && magic_cookie_glitch >= 0) {
1177         magic_cookie_glitch = ABSENT_NUMERIC;
1178         set_attributes = ABSENT_STRING;
1179         enter_blink_mode = ABSENT_STRING;
1180         enter_bold_mode = ABSENT_STRING;
1181         enter_dim_mode = ABSENT_STRING;
1182         enter_reverse_mode = ABSENT_STRING;
1183         enter_standout_mode = ABSENT_STRING;
1184         enter_underline_mode = ABSENT_STRING;
1185     }
1186
1187     /* initialize normal acs before wide, since we use mapping in the latter */
1188 #if !USE_WIDEC_SUPPORT
1189     if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
1190         acs_chars = NULL;
1191         ena_acs = NULL;
1192         enter_alt_charset_mode = NULL;
1193         exit_alt_charset_mode = NULL;
1194         set_attributes = NULL;
1195     }
1196 #endif
1197 }
1198
1199 static int
1200 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1201           int mode,
1202           int milliseconds,
1203           int *timeleft
1204           EVENTLIST_2nd(_nc_eventlist * evl))
1205 {
1206     SCREEN *sp;
1207
1208     AssertTCB();
1209     SetSP();
1210
1211     return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1212 }
1213
1214 static int
1215 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1216 {
1217     SCREEN *sp;
1218     unsigned char c2 = 0;
1219     int n;
1220
1221     AssertTCB();
1222     assert(buf);
1223     SetSP();
1224
1225 # if USE_PTHREADS_EINTR
1226     if ((pthread_self) && (pthread_kill) && (pthread_equal))
1227         _nc_globals.read_thread = pthread_self();
1228 # endif
1229     n = (int) read(sp->_ifd, &c2, (size_t) 1);
1230 #if USE_PTHREADS_EINTR
1231     _nc_globals.read_thread = 0;
1232 #endif
1233     *buf = (int) c2;
1234     return n;
1235 }
1236
1237 static int
1238 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1239 {
1240 #if HAVE_NANOSLEEP
1241     {
1242         struct timespec request, remaining;
1243         request.tv_sec = ms / 1000;
1244         request.tv_nsec = (ms % 1000) * 1000000;
1245         while (nanosleep(&request, &remaining) == -1
1246                && errno == EINTR) {
1247             request = remaining;
1248         }
1249     }
1250 #else
1251     _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1252 #endif
1253     return OK;
1254 }
1255
1256 static int
1257 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1258 {
1259     int rc = ERR;
1260
1261     if (value) {
1262         rc = NCURSES_PUTP2(name, value);
1263     }
1264     return rc;
1265 }
1266
1267 static int
1268 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1269 {
1270     int rc = __nc_putp(sp, name, value);
1271     if (rc != ERR) {
1272         NCURSES_SP_NAME(_nc_flush) (sp);
1273     }
1274     return rc;
1275 }
1276
1277 static int
1278 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1279 {
1280     int ret = ERR;
1281     SCREEN *sp;
1282
1283     AssertTCB();
1284
1285     sp = TCB->csp;
1286
1287     if (sp) {
1288         if (flag) {
1289             (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
1290         } else if (!flag && keypad_local) {
1291             (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
1292         }
1293         if (flag && !sp->_tried) {
1294             _nc_init_keytry(sp);
1295             sp->_tried = TRUE;
1296         }
1297         ret = OK;
1298     }
1299
1300     return ret;
1301 }
1302
1303 static int
1304 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1305 {
1306     SCREEN *sp;
1307     int code = ERR;
1308     int count = 0;
1309     char *s;
1310
1311     AssertTCB();
1312     SetSP();
1313
1314     if (c >= 0) {
1315         unsigned ch = (unsigned) c;
1316         if (flag) {
1317             while ((s = _nc_expand_try(sp->_key_ok,
1318                                        ch, &count, (size_t) 0)) != 0
1319                    && _nc_remove_key(&(sp->_key_ok), ch)) {
1320                 code = _nc_add_to_try(&(sp->_keytry), s, ch);
1321                 free(s);
1322                 count = 0;
1323                 if (code != OK)
1324                     break;
1325             }
1326         } else {
1327             while ((s = _nc_expand_try(sp->_keytry,
1328                                        ch, &count, (size_t) 0)) != 0
1329                    && _nc_remove_key(&(sp->_keytry), ch)) {
1330                 code = _nc_add_to_try(&(sp->_key_ok), s, ch);
1331                 free(s);
1332                 count = 0;
1333                 if (code != OK)
1334                     break;
1335             }
1336         }
1337     }
1338     return (code);
1339 }
1340
1341 static int
1342 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1343 {
1344     SCREEN *sp;
1345     int code = ERR;
1346
1347     AssertTCB();
1348     SetSP();
1349
1350     T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1351
1352     if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1353         switch (vis) {
1354         case 2:
1355             code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1356             break;
1357         case 1:
1358             code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1359             break;
1360         case 0:
1361             code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1362             break;
1363         }
1364     } else {
1365         code = ERR;
1366     }
1367     returnCode(code);
1368 }
1369
1370 static bool
1371 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1372 {
1373     bool res = FALSE;
1374
1375     AssertTCB();
1376     if (TCB->csp)
1377         res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1378
1379     return res;
1380 }
1381
1382 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1383     TRUE,
1384         drv_Name,               /* Name */
1385         drv_CanHandle,          /* CanHandle */
1386         drv_init,               /* init */
1387         drv_release,            /* release */
1388         drv_size,               /* size */
1389         drv_sgmode,             /* sgmode */
1390         drv_conattr,            /* conattr */
1391         drv_mvcur,              /* hwcur */
1392         drv_mode,               /* mode */
1393         drv_rescol,             /* rescol */
1394         drv_rescolors,          /* rescolors */
1395         drv_setcolor,           /* color */
1396         drv_dobeepflash,        /* doBeepOrFlash */
1397         drv_initpair,           /* initpair */
1398         drv_initcolor,          /* initcolor */
1399         drv_do_color,           /* docolor */
1400         drv_initmouse,          /* initmouse */
1401         drv_testmouse,          /* testmouse */
1402         drv_setfilter,          /* setfilter */
1403         drv_hwlabel,            /* hwlabel */
1404         drv_hwlabelOnOff,       /* hwlabelOnOff */
1405         drv_doupdate,           /* update */
1406         drv_defaultcolors,      /* defaultcolors */
1407         drv_print,              /* print */
1408         drv_getsize,            /* getsize */
1409         drv_setsize,            /* setsize */
1410         drv_initacs,            /* initacs */
1411         drv_screen_init,        /* scinit */
1412         drv_wrap,               /* scexit */
1413         drv_twait,              /* twait  */
1414         drv_read,               /* read */
1415         drv_nap,                /* nap */
1416         drv_kpad,               /* kpad */
1417         drv_keyok,              /* kyOk */
1418         drv_kyExist,            /* kyExist */
1419         drv_cursorSet           /* cursorSet */
1420 };