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