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