]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/tinfo_driver.c
ncurses 6.0 - patch 20170401
[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.47 2017/03/28 09:15:24 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, &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     int fg = COLOR_DEFAULT;
792     int bg = COLOR_DEFAULT;
793     int 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             _nc_pair_content(SP_PARM, pair, &fg, &bg);
809         }
810     }
811
812     if (old_pair >= 0
813         && sp != 0
814         && _nc_pair_content(SP_PARM, old_pair, &old_fg, &old_bg) != ERR) {
815         if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
816             || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
817 #if NCURSES_EXT_FUNCS
818             /*
819              * A minor optimization - but extension.  If "AX" is specified in
820              * the terminal description, treat it as screen's indicator of ECMA
821              * SGR 39 and SGR 49, and assume the two sequences are independent.
822              */
823             if (sp->_has_sgr_39_49
824                 && isDefaultColor(old_bg)
825                 && !isDefaultColor(old_fg)) {
826                 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
827             } else if (sp->_has_sgr_39_49
828                        && isDefaultColor(old_fg)
829                        && !isDefaultColor(old_bg)) {
830                 NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
831             } else
832 #endif
833                 drv_rescol(TCB);
834         }
835     } else {
836         drv_rescol(TCB);
837         if (old_pair < 0)
838             return;
839     }
840
841 #if NCURSES_EXT_FUNCS
842     if (isDefaultColor(fg))
843         fg = default_fg(sp);
844     if (isDefaultColor(bg))
845         bg = default_bg(sp);
846 #endif
847
848     if (reverse) {
849         int xx = fg;
850         fg = bg;
851         bg = xx;
852     }
853
854     TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
855                      fg, bg));
856
857     if (!isDefaultColor(fg)) {
858         drv_setcolor(TCB, TRUE, fg, outc);
859     }
860     if (!isDefaultColor(bg)) {
861         drv_setcolor(TCB, FALSE, bg, outc);
862     }
863 }
864
865 #define xterm_kmous "\033[M"
866 static void
867 init_xterm_mouse(SCREEN *sp)
868 {
869     sp->_mouse_type = M_XTERM;
870     sp->_mouse_xtermcap = NCURSES_SP_NAME(tigetstr) (NCURSES_SP_ARGx "XM");
871     if (!VALID_STRING(sp->_mouse_xtermcap))
872         sp->_mouse_xtermcap = "\033[?1000%?%p1%{1}%=%th%el%;";
873 }
874
875 static void
876 drv_initmouse(TERMINAL_CONTROL_BLOCK * TCB)
877 {
878     SCREEN *sp;
879
880     AssertTCB();
881     SetSP();
882
883     /* we know how to recognize mouse events under "xterm" */
884     if (sp != 0) {
885         if (key_mouse != 0) {
886             if (!strcmp(key_mouse, xterm_kmous)
887                 || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
888                 init_xterm_mouse(sp);
889             }
890         } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
891             if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
892                 init_xterm_mouse(sp);
893         }
894     }
895 }
896
897 static int
898 drv_testmouse(TERMINAL_CONTROL_BLOCK * TCB,
899               int delay
900               EVENTLIST_2nd(_nc_eventlist * evl))
901 {
902     int rc = 0;
903     SCREEN *sp;
904
905     AssertTCB();
906     SetSP();
907
908 #if USE_SYSMOUSE
909     if ((sp->_mouse_type == M_SYSMOUSE)
910         && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
911         rc = TW_MOUSE;
912     } else
913 #endif
914     {
915         rc = TCBOf(sp)->drv->td_twait(TCBOf(sp),
916                                       TWAIT_MASK,
917                                       delay,
918                                       (int *) 0
919                                       EVENTLIST_2nd(evl));
920 #if USE_SYSMOUSE
921         if ((sp->_mouse_type == M_SYSMOUSE)
922             && (sp->_sysmouse_head < sp->_sysmouse_tail)
923             && (rc == 0)
924             && (errno == EINTR)) {
925             rc |= TW_MOUSE;
926         }
927 #endif
928     }
929     return rc;
930 }
931
932 static int
933 drv_mvcur(TERMINAL_CONTROL_BLOCK * TCB, int yold, int xold, int ynew, int xnew)
934 {
935     SCREEN *sp = TCB->csp;
936     AssertTCB();
937     return NCURSES_SP_NAME(_nc_mvcur) (sp, yold, xold, ynew, xnew);
938 }
939
940 static void
941 drv_hwlabel(TERMINAL_CONTROL_BLOCK * TCB, int labnum, char *text)
942 {
943     SCREEN *sp = TCB->csp;
944
945     AssertTCB();
946     if (labnum > 0 && labnum <= num_labels) {
947         NCURSES_PUTP2("plab_norm",
948                       TPARM_2(plab_norm, labnum, text));
949     }
950 }
951
952 static void
953 drv_hwlabelOnOff(TERMINAL_CONTROL_BLOCK * TCB, int OnFlag)
954 {
955     SCREEN *sp = TCB->csp;
956
957     AssertTCB();
958     if (OnFlag) {
959         NCURSES_PUTP2("label_on", label_on);
960     } else {
961         NCURSES_PUTP2("label_off", label_off);
962     }
963 }
964
965 static chtype
966 drv_conattr(TERMINAL_CONTROL_BLOCK * TCB)
967 {
968     SCREEN *sp = TCB->csp;
969     chtype attrs = A_NORMAL;
970
971     AssertTCB();
972     if (enter_alt_charset_mode)
973         attrs |= A_ALTCHARSET;
974
975     if (enter_blink_mode)
976         attrs |= A_BLINK;
977
978     if (enter_bold_mode)
979         attrs |= A_BOLD;
980
981     if (enter_dim_mode)
982         attrs |= A_DIM;
983
984     if (enter_reverse_mode)
985         attrs |= A_REVERSE;
986
987     if (enter_standout_mode)
988         attrs |= A_STANDOUT;
989
990     if (enter_protected_mode)
991         attrs |= A_PROTECT;
992
993     if (enter_secure_mode)
994         attrs |= A_INVIS;
995
996     if (enter_underline_mode)
997         attrs |= A_UNDERLINE;
998
999     if (sp && sp->_coloron)
1000         attrs |= A_COLOR;
1001
1002 #if USE_ITALIC
1003     if (enter_italics_mode)
1004         attrs |= A_ITALIC;
1005 #endif
1006
1007     return (attrs);
1008 }
1009
1010 static void
1011 drv_setfilter(TERMINAL_CONTROL_BLOCK * TCB)
1012 {
1013     AssertTCB();
1014
1015     clear_screen = 0;
1016     cursor_down = parm_down_cursor = 0;
1017     cursor_address = 0;
1018     cursor_up = parm_up_cursor = 0;
1019     row_address = 0;
1020     cursor_home = carriage_return;
1021 }
1022
1023 static void
1024 drv_initacs(TERMINAL_CONTROL_BLOCK * TCB, chtype *real_map, chtype *fake_map)
1025 {
1026     SCREEN *sp = TCB->csp;
1027
1028     AssertTCB();
1029     assert(sp != 0);
1030     if (ena_acs != NULL) {
1031         NCURSES_PUTP2("ena_acs", ena_acs);
1032     }
1033 #if NCURSES_EXT_FUNCS
1034     /*
1035      * Linux console "supports" the "PC ROM" character set by the coincidence
1036      * that smpch/rmpch and smacs/rmacs have the same values.  ncurses has
1037      * no codepage support (see SCO Merge for an example).  Outside of the
1038      * values defined in acsc, there are no definitions for the "PC ROM"
1039      * character set (assumed by some applications to be codepage 437), but we
1040      * allow those applications to use those codepoints.
1041      *
1042      * test/blue.c uses this feature.
1043      */
1044 #define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
1045     if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
1046         PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
1047         size_t i;
1048         for (i = 1; i < ACS_LEN; ++i) {
1049             if (real_map[i] == 0) {
1050                 real_map[i] = (chtype) i;
1051                 if (real_map != fake_map) {
1052                     if (sp != 0)
1053                         sp->_screen_acs_map[i] = TRUE;
1054                 }
1055             }
1056         }
1057     }
1058 #endif
1059
1060     if (acs_chars != NULL) {
1061         size_t i = 0;
1062         size_t length = strlen(acs_chars);
1063
1064         while (i + 1 < length) {
1065             if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
1066                 real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
1067                 if (sp != 0)
1068                     sp->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
1069             }
1070             i += 2;
1071         }
1072     }
1073 #ifdef TRACE
1074     /* Show the equivalent mapping, noting if it does not match the
1075      * given attribute, whether by re-ordering or duplication.
1076      */
1077     if (USE_TRACEF(TRACE_CALLS)) {
1078         size_t n, m;
1079         char show[ACS_LEN * 2 + 1];
1080         for (n = 1, m = 0; n < ACS_LEN; n++) {
1081             if (real_map[n] != 0) {
1082                 show[m++] = (char) n;
1083                 show[m++] = (char) ChCharOf(real_map[n]);
1084             }
1085         }
1086         show[m] = 0;
1087         if (acs_chars == NULL || strcmp(acs_chars, show))
1088             _tracef("%s acs_chars %s",
1089                     (acs_chars == NULL) ? "NULL" : "READ",
1090                     _nc_visbuf(acs_chars));
1091         _tracef("%s acs_chars %s",
1092                 (acs_chars == NULL)
1093                 ? "NULL"
1094                 : (strcmp(acs_chars, show)
1095                    ? "DIFF"
1096                    : "SAME"),
1097                 _nc_visbuf(show));
1098
1099         _nc_unlock_global(tracef);
1100     }
1101 #endif /* TRACE */
1102 }
1103
1104 #define ENSURE_TINFO(sp) (TCBOf(sp)->drv->isTerminfo)
1105
1106 NCURSES_EXPORT(void)
1107 _nc_cookie_init(SCREEN *sp)
1108 {
1109     bool support_cookies = USE_XMC_SUPPORT;
1110     TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) (sp->_term);
1111
1112     if (sp == 0 || !ENSURE_TINFO(sp))
1113         return;
1114
1115 #if USE_XMC_SUPPORT
1116     /*
1117      * If we have no magic-cookie support compiled-in, or if it is suppressed
1118      * in the environment, reset the support-flag.
1119      */
1120     if (magic_cookie_glitch >= 0) {
1121         if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
1122             support_cookies = FALSE;
1123         }
1124     }
1125 #endif
1126
1127     if (!support_cookies && magic_cookie_glitch >= 0) {
1128         T(("will disable attributes to work w/o magic cookies"));
1129     }
1130
1131     if (magic_cookie_glitch > 0) {      /* tvi, wyse */
1132
1133         sp->_xmc_triggers = sp->_ok_attributes & XMC_CONFLICT;
1134 #if 0
1135         /*
1136          * We "should" treat colors as an attribute.  The wyse350 (and its
1137          * clones) appear to be the only ones that have both colors and magic
1138          * cookies.
1139          */
1140         if (has_colors()) {
1141             sp->_xmc_triggers |= A_COLOR;
1142         }
1143 #endif
1144         sp->_xmc_suppress = sp->_xmc_triggers & (chtype) ~(A_BOLD);
1145
1146         T(("magic cookie attributes %s", _traceattr(sp->_xmc_suppress)));
1147         /*
1148          * Supporting line-drawing may be possible.  But make the regular
1149          * video attributes work first.
1150          */
1151         acs_chars = ABSENT_STRING;
1152         ena_acs = ABSENT_STRING;
1153         enter_alt_charset_mode = ABSENT_STRING;
1154         exit_alt_charset_mode = ABSENT_STRING;
1155 #if USE_XMC_SUPPORT
1156         /*
1157          * To keep the cookie support simple, suppress all of the optimization
1158          * hooks except for clear_screen and the cursor addressing.
1159          */
1160         if (support_cookies) {
1161             clr_eol = ABSENT_STRING;
1162             clr_eos = ABSENT_STRING;
1163             set_attributes = ABSENT_STRING;
1164         }
1165 #endif
1166     } else if (magic_cookie_glitch == 0) {      /* hpterm */
1167     }
1168
1169     /*
1170      * If magic cookies are not supported, cancel the strings that set
1171      * video attributes.
1172      */
1173     if (!support_cookies && magic_cookie_glitch >= 0) {
1174         magic_cookie_glitch = ABSENT_NUMERIC;
1175         set_attributes = ABSENT_STRING;
1176         enter_blink_mode = ABSENT_STRING;
1177         enter_bold_mode = ABSENT_STRING;
1178         enter_dim_mode = ABSENT_STRING;
1179         enter_reverse_mode = ABSENT_STRING;
1180         enter_standout_mode = ABSENT_STRING;
1181         enter_underline_mode = ABSENT_STRING;
1182     }
1183
1184     /* initialize normal acs before wide, since we use mapping in the latter */
1185 #if !USE_WIDEC_SUPPORT
1186     if (_nc_unicode_locale() && _nc_locale_breaks_acs(sp->_term)) {
1187         acs_chars = NULL;
1188         ena_acs = NULL;
1189         enter_alt_charset_mode = NULL;
1190         exit_alt_charset_mode = NULL;
1191         set_attributes = NULL;
1192     }
1193 #endif
1194 }
1195
1196 static int
1197 drv_twait(TERMINAL_CONTROL_BLOCK * TCB,
1198           int mode,
1199           int milliseconds,
1200           int *timeleft
1201           EVENTLIST_2nd(_nc_eventlist * evl))
1202 {
1203     SCREEN *sp;
1204
1205     AssertTCB();
1206     SetSP();
1207
1208     return _nc_timed_wait(sp, mode, milliseconds, timeleft EVENTLIST_2nd(evl));
1209 }
1210
1211 static int
1212 drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
1213 {
1214     SCREEN *sp;
1215     unsigned char c2 = 0;
1216     int n;
1217
1218     AssertTCB();
1219     assert(buf);
1220     SetSP();
1221
1222 # if USE_PTHREADS_EINTR
1223     if ((pthread_self) && (pthread_kill) && (pthread_equal))
1224         _nc_globals.read_thread = pthread_self();
1225 # endif
1226     n = (int) read(sp->_ifd, &c2, (size_t) 1);
1227 #if USE_PTHREADS_EINTR
1228     _nc_globals.read_thread = 0;
1229 #endif
1230     *buf = (int) c2;
1231     return n;
1232 }
1233
1234 static int
1235 drv_nap(TERMINAL_CONTROL_BLOCK * TCB GCC_UNUSED, int ms)
1236 {
1237 #if HAVE_NANOSLEEP
1238     {
1239         struct timespec request, remaining;
1240         request.tv_sec = ms / 1000;
1241         request.tv_nsec = (ms % 1000) * 1000000;
1242         while (nanosleep(&request, &remaining) == -1
1243                && errno == EINTR) {
1244             request = remaining;
1245         }
1246     }
1247 #else
1248     _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
1249 #endif
1250     return OK;
1251 }
1252
1253 static int
1254 __nc_putp(SCREEN *sp, const char *name GCC_UNUSED, const char *value)
1255 {
1256     int rc = ERR;
1257
1258     if (value) {
1259         rc = NCURSES_PUTP2(name, value);
1260     }
1261     return rc;
1262 }
1263
1264 static int
1265 __nc_putp_flush(SCREEN *sp, const char *name, const char *value)
1266 {
1267     int rc = __nc_putp(sp, name, value);
1268     if (rc != ERR) {
1269         NCURSES_SP_NAME(_nc_flush) (sp);
1270     }
1271     return rc;
1272 }
1273
1274 static int
1275 drv_kpad(TERMINAL_CONTROL_BLOCK * TCB, int flag)
1276 {
1277     int ret = ERR;
1278     SCREEN *sp;
1279
1280     AssertTCB();
1281
1282     sp = TCB->csp;
1283
1284     if (sp) {
1285         if (flag) {
1286             (void) __nc_putp_flush(sp, "keypad_xmit", keypad_xmit);
1287         } else if (!flag && keypad_local) {
1288             (void) __nc_putp_flush(sp, "keypad_local", keypad_local);
1289         }
1290         if (flag && !sp->_tried) {
1291             _nc_init_keytry(sp);
1292             sp->_tried = TRUE;
1293         }
1294         ret = OK;
1295     }
1296
1297     return ret;
1298 }
1299
1300 static int
1301 drv_keyok(TERMINAL_CONTROL_BLOCK * TCB, int c, int flag)
1302 {
1303     SCREEN *sp;
1304     int code = ERR;
1305     int count = 0;
1306     char *s;
1307
1308     AssertTCB();
1309     SetSP();
1310
1311     if (c >= 0) {
1312         unsigned ch = (unsigned) c;
1313         if (flag) {
1314             while ((s = _nc_expand_try(sp->_key_ok,
1315                                        ch, &count, (size_t) 0)) != 0
1316                    && _nc_remove_key(&(sp->_key_ok), ch)) {
1317                 code = _nc_add_to_try(&(sp->_keytry), s, ch);
1318                 free(s);
1319                 count = 0;
1320                 if (code != OK)
1321                     break;
1322             }
1323         } else {
1324             while ((s = _nc_expand_try(sp->_keytry,
1325                                        ch, &count, (size_t) 0)) != 0
1326                    && _nc_remove_key(&(sp->_keytry), ch)) {
1327                 code = _nc_add_to_try(&(sp->_key_ok), s, ch);
1328                 free(s);
1329                 count = 0;
1330                 if (code != OK)
1331                     break;
1332             }
1333         }
1334     }
1335     return (code);
1336 }
1337
1338 static int
1339 drv_cursorSet(TERMINAL_CONTROL_BLOCK * TCB, int vis)
1340 {
1341     SCREEN *sp;
1342     int code = ERR;
1343
1344     AssertTCB();
1345     SetSP();
1346
1347     T((T_CALLED("tinfo:drv_cursorSet(%p,%d)"), (void *) SP_PARM, vis));
1348
1349     if (SP_PARM != 0 && IsTermInfo(SP_PARM)) {
1350         switch (vis) {
1351         case 2:
1352             code = NCURSES_PUTP2_FLUSH("cursor_visible", cursor_visible);
1353             break;
1354         case 1:
1355             code = NCURSES_PUTP2_FLUSH("cursor_normal", cursor_normal);
1356             break;
1357         case 0:
1358             code = NCURSES_PUTP2_FLUSH("cursor_invisible", cursor_invisible);
1359             break;
1360         }
1361     } else {
1362         code = ERR;
1363     }
1364     returnCode(code);
1365 }
1366
1367 static bool
1368 drv_kyExist(TERMINAL_CONTROL_BLOCK * TCB, int key)
1369 {
1370     bool res = FALSE;
1371
1372     AssertTCB();
1373     if (TCB->csp)
1374         res = TINFO_HAS_KEY(TCB->csp, key) == 0 ? FALSE : TRUE;
1375
1376     return res;
1377 }
1378
1379 NCURSES_EXPORT_VAR (TERM_DRIVER) _nc_TINFO_DRIVER = {
1380     TRUE,
1381         drv_Name,               /* Name */
1382         drv_CanHandle,          /* CanHandle */
1383         drv_init,               /* init */
1384         drv_release,            /* release */
1385         drv_size,               /* size */
1386         drv_sgmode,             /* sgmode */
1387         drv_conattr,            /* conattr */
1388         drv_mvcur,              /* hwcur */
1389         drv_mode,               /* mode */
1390         drv_rescol,             /* rescol */
1391         drv_rescolors,          /* rescolors */
1392         drv_setcolor,           /* color */
1393         drv_dobeepflash,        /* doBeepOrFlash */
1394         drv_initpair,           /* initpair */
1395         drv_initcolor,          /* initcolor */
1396         drv_do_color,           /* docolor */
1397         drv_initmouse,          /* initmouse */
1398         drv_testmouse,          /* testmouse */
1399         drv_setfilter,          /* setfilter */
1400         drv_hwlabel,            /* hwlabel */
1401         drv_hwlabelOnOff,       /* hwlabelOnOff */
1402         drv_doupdate,           /* update */
1403         drv_defaultcolors,      /* defaultcolors */
1404         drv_print,              /* print */
1405         drv_getsize,            /* getsize */
1406         drv_setsize,            /* setsize */
1407         drv_initacs,            /* initacs */
1408         drv_screen_init,        /* scinit */
1409         drv_wrap,               /* scexit */
1410         drv_twait,              /* twait  */
1411         drv_read,               /* read */
1412         drv_nap,                /* nap */
1413         drv_kpad,               /* kpad */
1414         drv_keyok,              /* kyOk */
1415         drv_kyExist,            /* kyExist */
1416         drv_cursorSet           /* cursorSet */
1417 };