]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/tinfo_driver.c
ncurses 6.0 - patch 20170311
[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  *                                                                          *
32  ****************************************************************************/
33
34 #include <curses.priv.h>
35 #define CUR ((TERMINAL*)TCB)->type.
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.45 2017/02/28 22:10:05 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)"), 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, &termp->type);
165 #else
166     status = TGETENT_NO;
167 #endif
168
169     /* try fallback list if entry on disk */
170     if (status != TGETENT_YES) {
171         const TERMTYPE *fallback = _nc_fallback(tname);
172
173         if (fallback) {
174             termp->type = *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 !USE_REENTRANT
189 #define MY_SIZE (size_t) NAMESIZE - 1
190     _nc_STRNCPY(ttytype, termp->type.term_names, MY_SIZE);
191     ttytype[MY_SIZE] = '\0';
192 #endif
193
194     if (command_character)
195         _nc_tinfo_cmdch(termp, *command_character);
196
197     /*
198      * If an application calls setupterm() rather than initscr() or
199      * newterm(), we will not have the def_prog_mode() call in
200      * _nc_setupscreen().  Do it now anyway, so we can initialize the
201      * baudrate.
202      */
203     if (sp == 0 && NC_ISATTY(termp->Filedes)) {
204         get_baudrate(termp);
205     }
206
207     if (generic_type) {
208         /*
209          * BSD 4.3's termcap contains mis-typed "gn" for wy99.  Do a sanity
210          * check before giving up.
211          */
212         if ((VALID_STRING(cursor_address)
213              || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
214             && VALID_STRING(clear_screen)) {
215             ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
216         } else {
217             ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
218         }
219     }
220     if (hard_copy) {
221         ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
222     }
223
224     returnBool(result);
225 }
226
227 static int
228 drv_dobeepflash(TERMINAL_CONTROL_BLOCK * TCB, int beepFlag)
229 {
230     SCREEN *sp;
231     int res = ERR;
232
233     AssertTCB();
234     SetSP();
235
236     /* FIXME: should make sure that we are not in altchar mode */
237     if (beepFlag) {
238         if (bell) {
239             res = NCURSES_PUTP2("bell", bell);
240             NCURSES_SP_NAME(_nc_flush) (sp);
241         } else if (flash_screen) {
242             res = NCURSES_PUTP2("flash_screen", flash_screen);
243             NCURSES_SP_NAME(_nc_flush) (sp);
244         }
245     } else {
246         if (flash_screen) {
247             res = NCURSES_PUTP2("flash_screen", flash_screen);
248             NCURSES_SP_NAME(_nc_flush) (sp);
249         } else if (bell) {
250             res = NCURSES_PUTP2("bell", bell);
251             NCURSES_SP_NAME(_nc_flush) (sp);
252         }
253     }
254     return res;
255 }
256
257 /*
258  * SVr4 curses is known to interchange color codes (1,4) and (3,6), possibly
259  * to maintain compatibility with a pre-ANSI scheme.  The same scheme is
260  * also used in the FreeBSD syscons.
261  */
262 static int
263 toggled_colors(int c)
264 {
265     if (c < 16) {
266         static const int table[] =
267         {0, 4, 2, 6, 1, 5, 3, 7,
268          8, 12, 10, 14, 9, 13, 11, 15};
269         c = table[c];
270     }
271     return c;
272 }
273
274 static int
275 drv_print(TERMINAL_CONTROL_BLOCK * TCB, char *data, int len)
276 {
277     SCREEN *sp;
278
279     AssertTCB();
280     SetSP();
281 #if NCURSES_EXT_FUNCS
282     return NCURSES_SP_NAME(mcprint) (TCB->csp, data, len);
283 #else
284     return ERR;
285 #endif
286 }
287
288 static int
289 drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg)
290 {
291     SCREEN *sp;
292     int code = ERR;
293
294     AssertTCB();
295     SetSP();
296
297     if (sp != 0 && orig_pair && orig_colors && (initialize_pair != 0)) {
298 #if NCURSES_EXT_FUNCS
299         sp->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
300         sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx
301                                                           "AX")
302                               == TRUE);
303         sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
304         sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
305         if (sp->_color_pairs != 0) {
306             bool save = sp->_default_color;
307             sp->_default_color = TRUE;
308             NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx
309                                         0,
310                                         (short)fg,
311                                         (short)bg);
312             sp->_default_color = save;
313         }
314 #endif
315         code = OK;
316     }
317     return (code);
318 }
319
320 static void
321 drv_setcolor(TERMINAL_CONTROL_BLOCK * TCB,
322              int fore,
323              int color,
324              NCURSES_SP_OUTC outc)
325 {
326     SCREEN *sp;
327
328     AssertTCB();
329     SetSP();
330
331     if (fore) {
332         if (set_a_foreground) {
333             TPUTS_TRACE("set_a_foreground");
334             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
335                                     TPARM_1(set_a_foreground, color), 1, outc);
336         } else {
337             TPUTS_TRACE("set_foreground");
338             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
339                                     TPARM_1(set_foreground,
340                                             toggled_colors(color)), 1, outc);
341         }
342     } else {
343         if (set_a_background) {
344             TPUTS_TRACE("set_a_background");
345             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
346                                     TPARM_1(set_a_background, color), 1, outc);
347         } else {
348             TPUTS_TRACE("set_background");
349             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
350                                     TPARM_1(set_background,
351                                             toggled_colors(color)), 1, outc);
352         }
353     }
354 }
355
356 static bool
357 drv_rescol(TERMINAL_CONTROL_BLOCK * TCB)
358 {
359     bool result = FALSE;
360     SCREEN *sp;
361
362     AssertTCB();
363     SetSP();
364
365     if (orig_pair != 0) {
366         NCURSES_PUTP2("orig_pair", orig_pair);
367         result = TRUE;
368     }
369     return result;
370 }
371
372 static bool
373 drv_rescolors(TERMINAL_CONTROL_BLOCK * TCB)
374 {
375     int result = FALSE;
376     SCREEN *sp;
377
378     AssertTCB();
379     SetSP();
380
381     if (orig_colors != 0) {
382         NCURSES_PUTP2("orig_colors", orig_colors);
383         result = TRUE;
384     }
385     return result;
386 }
387
388 static int
389 drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp)
390 {
391     SCREEN *sp;
392     bool useEnv = TRUE;
393     bool useTioctl = TRUE;
394
395     AssertTCB();
396     sp = TCB->csp;              /* can be null here */
397
398     if (sp) {
399         useEnv = sp->_use_env;
400         useTioctl = sp->use_tioctl;
401     } else {
402         useEnv = _nc_prescreen.use_env;
403         useTioctl = _nc_prescreen.use_tioctl;
404     }
405
406     /* figure out the size of the screen */
407     T(("screen size: terminfo lines = %d columns = %d", lines, columns));
408
409     *linep = (int) lines;
410     *colp = (int) columns;
411
412     if (useEnv || useTioctl) {
413         int value;
414
415 #ifdef __EMX__
416         {
417             int screendata[2];
418             _scrsize(screendata);
419             *colp = screendata[0];
420             *linep = ((sp != 0 && sp->_filtered)
421                       ? 1
422                       : screendata[1]);
423             T(("EMX screen size: environment LINES = %d COLUMNS = %d",
424                *linep, *colp));
425         }
426 #endif
427 #if HAVE_SIZECHANGE
428         /* try asking the OS */
429         {
430             TERMINAL *termp = (TERMINAL *) TCB;
431             if (NC_ISATTY(termp->Filedes)) {
432                 STRUCT_WINSIZE size;
433
434                 errno = 0;
435                 do {
436                     if (ioctl(termp->Filedes, IOCTL_WINSIZE, &size) >= 0) {
437                         *linep = ((sp != 0 && sp->_filtered)
438                                   ? 1
439                                   : WINSIZE_ROWS(size));
440                         *colp = WINSIZE_COLS(size);
441                         T(("SYS screen size: environment LINES = %d COLUMNS = %d",
442                            *linep, *colp));
443                         break;
444                     }
445                 } while
446                     (errno == EINTR);
447             }
448         }
449 #endif /* HAVE_SIZECHANGE */
450
451         if (useEnv) {
452             if (useTioctl) {
453                 /*
454                  * If environment variables are used, update them.
455                  */
456                 if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) {
457                     _nc_setenv_num("LINES", *linep);
458                 }
459                 if (_nc_getenv_num("COLUMNS") > 0) {
460                     _nc_setenv_num("COLUMNS", *colp);
461                 }
462             }
463
464             /*
465              * Finally, look for environment variables.
466              *
467              * Solaris lets users override either dimension with an environment
468              * variable.
469              */
470             if ((value = _nc_getenv_num("LINES")) > 0) {
471                 *linep = value;
472                 T(("screen size: environment LINES = %d", *linep));
473             }
474             if ((value = _nc_getenv_num("COLUMNS")) > 0) {
475                 *colp = value;
476                 T(("screen size: environment COLUMNS = %d", *colp));
477             }
478         }
479
480         /* if we can't get dynamic info about the size, use static */
481         if (*linep <= 0) {
482             *linep = (int) lines;
483         }
484         if (*colp <= 0) {
485             *colp = (int) columns;
486         }
487
488         /* the ultimate fallback, assume fixed 24x80 size */
489         if (*linep <= 0) {
490             *linep = 24;
491         }
492         if (*colp <= 0) {
493             *colp = 80;
494         }
495
496         /*
497          * Put the derived values back in the screen-size caps, so
498          * tigetnum() and tgetnum() will do the right thing.
499          */
500         lines = (short) (*linep);
501         columns = (short) (*colp);
502     }
503
504     T(("screen size is %dx%d", *linep, *colp));
505     return OK;
506 }
507
508 static int
509 drv_getsize(TERMINAL_CONTROL_BLOCK * TCB, int *l, int *c)
510 {
511     AssertTCB();
512     assert(l != 0 && c != 0);
513     *l = lines;
514     *c = columns;
515     return OK;
516 }
517
518 static int
519 drv_setsize(TERMINAL_CONTROL_BLOCK * TCB, int l, int c)
520 {
521     AssertTCB();
522     lines = (short) l;
523     columns = (short) c;
524     return OK;
525 }
526
527 static int
528 drv_sgmode(TERMINAL_CONTROL_BLOCK * TCB, int setFlag, TTY * buf)
529 {
530     SCREEN *sp = TCB->csp;
531     TERMINAL *_term = (TERMINAL *) TCB;
532     int result = OK;
533
534     AssertTCB();
535     if (setFlag) {
536         for (;;) {
537             if (SET_TTY(_term->Filedes, buf) != 0) {
538                 if (errno == EINTR)
539                     continue;
540                 if (errno == ENOTTY) {
541                     if (sp)
542                         sp->_notty = TRUE;
543                 }
544                 result = ERR;
545             }
546             break;
547         }
548     } else {
549         for (;;) {
550             if (GET_TTY(_term->Filedes, buf) != 0) {
551                 if (errno == EINTR)
552                     continue;
553                 result = ERR;
554             }
555             break;
556         }
557     }
558     return result;
559 }
560
561 static int
562 drv_mode(TERMINAL_CONTROL_BLOCK * TCB, int progFlag, int defFlag)
563 {
564     SCREEN *sp;
565     TERMINAL *_term = (TERMINAL *) TCB;
566     int code = ERR;
567
568     AssertTCB();
569     sp = TCB->csp;
570
571     if (progFlag)               /* prog mode */
572     {
573         if (defFlag) {
574             /* def_prog_mode */
575             /*
576              * Turn off the XTABS bit in the tty structure if it was on.
577              */
578             if ((drv_sgmode(TCB, FALSE, &(_term->Nttyb)) == OK)) {
579 #ifdef TERMIOS
580                 _term->Nttyb.c_oflag &= (unsigned) ~OFLAGS_TABS;
581 #else
582                 _term->Nttyb.sg_flags &= (unsigned) ~XTABS;
583 #endif
584                 code = OK;
585             }
586         } else {
587             /* reset_prog_mode */
588             if (drv_sgmode(TCB, TRUE, &(_term->Nttyb)) == OK) {
589                 if (sp) {
590                     if (sp->_keypad_on)
591                         _nc_keypad(sp, TRUE);
592                 }
593                 code = OK;
594             }
595         }
596     } else {                    /* shell mode */
597         if (defFlag) {
598             /* def_shell_mode */
599             /*
600              * If XTABS was on, remove the tab and backtab capabilities.
601              */
602             if (drv_sgmode(TCB, FALSE, &(_term->Ottyb)) == OK) {
603 #ifdef TERMIOS
604                 if (_term->Ottyb.c_oflag & OFLAGS_TABS)
605                     tab = back_tab = NULL;
606 #else
607                 if (_term->Ottyb.sg_flags & XTABS)
608                     tab = back_tab = NULL;
609 #endif
610                 code = OK;
611             }
612         } else {
613             /* reset_shell_mode */
614             if (sp) {
615                 _nc_keypad(sp, FALSE);
616                 NCURSES_SP_NAME(_nc_flush) (sp);
617             }
618             code = drv_sgmode(TCB, TRUE, &(_term->Ottyb));
619         }
620     }
621     return (code);
622 }
623
624 static void
625 drv_wrap(SCREEN *sp)
626 {
627     if (sp) {
628         sp->_mouse_wrap(sp);
629         NCURSES_SP_NAME(_nc_screen_wrap) (sp);
630         NCURSES_SP_NAME(_nc_mvcur_wrap) (sp);   /* wrap up cursor addressing */
631     }
632 }
633
634 static void
635 drv_release(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED)
636 {
637 }
638
639 #  define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode))
640
641 static void
642 drv_screen_init(SCREEN *sp)
643 {
644     TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
645
646     AssertTCB();
647
648     /*
649      * Check for mismatched graphic-rendition capabilities.  Most SVr4
650      * terminfo trees contain entries that have rmul or rmso equated to
651      * sgr0 (Solaris curses copes with those entries).  We do this only
652      * for curses, since many termcap applications assume that
653      * smso/rmso and smul/rmul are paired, and will not function
654      * properly if we remove rmso or rmul.  Curses applications
655      * shouldn't be looking at this detail.
656      */
657     sp->_use_rmso = SGR0_TEST(exit_standout_mode);
658     sp->_use_rmul = SGR0_TEST(exit_underline_mode);
659
660     /*
661      * Check whether we can optimize scrolling under dumb terminals in
662      * case we do not have any of these capabilities, scrolling
663      * optimization will be useless.
664      */
665     sp->_scrolling = ((scroll_forward && scroll_reverse) ||
666                       ((parm_rindex ||
667                         parm_insert_line ||
668                         insert_line) &&
669                        (parm_index ||
670                         parm_delete_line ||
671                         delete_line)));
672
673     NCURSES_SP_NAME(baudrate) (sp);
674
675     NCURSES_SP_NAME(_nc_mvcur_init) (sp);
676     /* initialize terminal to a sane state */
677     NCURSES_SP_NAME(_nc_screen_init) (sp);
678 }
679
680 static void
681 drv_init(TERMINAL_CONTROL_BLOCK * TCB)
682 {
683     TERMINAL *trm;
684
685     AssertTCB();
686
687     trm = (TERMINAL *) TCB;
688
689     TCB->info.initcolor = VALID_STRING(initialize_color);
690     TCB->info.canchange = can_change;
691     TCB->info.hascolor = ((VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
692                            && (((set_foreground != NULL)
693                                 && (set_background != NULL))
694                                || ((set_a_foreground != NULL)
695                                    && (set_a_background != NULL))
696                                || set_color_pair)) ? TRUE : FALSE);
697
698     TCB->info.caninit = !(exit_ca_mode && non_rev_rmcup);
699
700     TCB->info.maxpairs = VALID_NUMERIC(max_pairs) ? max_pairs : 0;
701     TCB->info.maxcolors = VALID_NUMERIC(max_colors) ? max_colors : 0;
702     TCB->info.numlabels = VALID_NUMERIC(num_labels) ? num_labels : 0;
703     TCB->info.labelwidth = VALID_NUMERIC(label_width) ? label_width : 0;
704     TCB->info.labelheight = VALID_NUMERIC(label_height) ? label_height : 0;
705     TCB->info.nocolorvideo = VALID_NUMERIC(no_color_video) ? no_color_video
706         : 0;
707     TCB->info.tabsize = VALID_NUMERIC(init_tabs) ? (int) init_tabs : 8;
708
709     TCB->info.defaultPalette = hue_lightness_saturation ? _nc_hls_palette : _nc_cga_palette;
710
711     /*
712      * If an application calls setupterm() rather than initscr() or
713      * newterm(), we will not have the def_prog_mode() call in
714      * _nc_setupscreen().  Do it now anyway, so we can initialize the
715      * baudrate.
716      */
717     if (NC_ISATTY(trm->Filedes)) {
718         TCB->drv->td_mode(TCB, TRUE, TRUE);
719     }
720 }
721
722 #define MAX_PALETTE     8
723 #define InPalette(n)    ((n) >= 0 && (n) < MAX_PALETTE)
724
725 static void
726 drv_initpair(TERMINAL_CONTROL_BLOCK * TCB, int pair, int f, int b)
727 {
728     SCREEN *sp;
729
730     AssertTCB();
731     SetSP();
732
733     if ((initialize_pair != NULL) && InPalette(f) && InPalette(b)) {
734         const color_t *tp = InfoOf(sp).defaultPalette;
735
736         TR(TRACE_ATTRS,
737            ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
738             pair,
739             tp[f].red, tp[f].green, tp[f].blue,
740             tp[b].red, tp[b].green, tp[b].blue));
741
742         NCURSES_PUTP2("initialize_pair",
743                       TPARM_7(initialize_pair,
744                               pair,
745                               tp[f].red, tp[f].green, tp[f].blue,
746                               tp[b].red, tp[b].green, tp[b].blue));
747     }
748 }
749
750 static int
751 default_fg(SCREEN *sp)
752 {
753 #if NCURSES_EXT_FUNCS
754     return (sp != 0) ? sp->_default_fg : COLOR_WHITE;
755 #else
756     return COLOR_WHITE;
757 #endif
758 }
759
760 static int
761 default_bg(SCREEN *sp)
762 {
763 #if NCURSES_EXT_FUNCS
764     return sp != 0 ? sp->_default_bg : COLOR_BLACK;
765 #else
766     return COLOR_BLACK;
767 #endif
768 }
769
770 static void
771 drv_initcolor(TERMINAL_CONTROL_BLOCK * TCB,
772               int color, int r, int g, int b)
773 {
774     SCREEN *sp = TCB->csp;
775
776     AssertTCB();
777     if (initialize_color != NULL) {
778         NCURSES_PUTP2("initialize_color",
779                       TPARM_4(initialize_color, color, r, g, b));
780     }
781 }
782
783 static void
784 drv_do_color(TERMINAL_CONTROL_BLOCK * TCB,
785              int old_pair,
786              int pair,
787              int reverse,
788              NCURSES_SP_OUTC outc)
789 {
790     SCREEN *sp = TCB->csp;
791     NCURSES_COLOR_T fg = COLOR_DEFAULT;
792     NCURSES_COLOR_T bg = COLOR_DEFAULT;
793     NCURSES_COLOR_T old_fg, old_bg;
794
795     AssertTCB();
796     if (sp == 0)
797         return;
798
799     if (pair < 0 || pair >= COLOR_PAIRS) {
800         return;
801     } else if (pair != 0) {
802         if (set_color_pair) {
803             TPUTS_TRACE("set_color_pair");
804             NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
805                                     TPARM_1(set_color_pair, pair), 1, outc);
806             return;
807         } else if (sp != 0) {
808             NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
809                                            (short) pair,
810                                            &fg,
811                                            &bg);
812         }
813     }
814
815     if (old_pair >= 0
816         && sp != 0
817         && NCURSES_SP_NAME(pair_content) (NCURSES_SP_ARGx
818                                           (short) old_pair,
819                                           &old_fg,
820                                           &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 = (NCURSES_COLOR_T) default_fg(sp);
850     if (isDefaultColor(bg))
851         bg = (NCURSES_COLOR_T) default_bg(sp);
852 #endif
853
854     if (reverse) {
855         NCURSES_COLOR_T 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(TerminalOf(sp)->type.term_names, "xterm") != 0) {
894                 init_xterm_mouse(sp);
895             }
896         } else if (strstr(TerminalOf(sp)->type.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 };