X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Ftinfo_driver.c;h=18c7e2fd024b9a15d9b60cd02e553f4bf0fb3a2f;hp=c6a1c22b66bfefd90c3645d0f43efcef5c2e5dd6;hb=5eb177874dea59107a1a2ea44f5d8f5bb99550b2;hpb=91e802b0dd5f97879f57d12e9dd758e59ab8abb8 diff --git a/ncurses/tinfo/tinfo_driver.c b/ncurses/tinfo/tinfo_driver.c index c6a1c22b..18c7e2fd 100644 --- a/ncurses/tinfo/tinfo_driver.c +++ b/ncurses/tinfo/tinfo_driver.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2008-2014,2015 Free Software Foundation, Inc. * + * Copyright (c) 2008-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -34,6 +34,7 @@ #include #define CUR ((TERMINAL*)TCB)->type. #include +#include /* ospeed */ #if HAVE_NANOSLEEP #include @@ -50,7 +51,7 @@ # endif #endif -MODULE_ID("$Id: tinfo_driver.c,v 1.40 2015/06/27 01:20:41 tom Exp $") +MODULE_ID("$Id: tinfo_driver.c,v 1.45 2017/02/28 22:10:05 tom Exp $") /* * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, @@ -113,6 +114,33 @@ drv_Name(TERMINAL_CONTROL_BLOCK * TCB) return "tinfo"; } +static void +get_baudrate(TERMINAL * termp) +{ + int my_ospeed; + int result; + if (GET_TTY(termp->Filedes, &termp->Nttyb) == OK) { +#ifdef TERMIOS + termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS); +#else + termp->Nttyb.sg_flags &= (unsigned) (~XTABS); +#endif + } +#ifdef USE_OLD_TTY + result = (int) cfgetospeed(&(termp->Nttyb)); + my_ospeed = (NCURSES_OSPEED) _nc_ospeed(result); +#else /* !USE_OLD_TTY */ +#ifdef TERMIOS + my_ospeed = (NCURSES_OSPEED) cfgetospeed(&(termp->Nttyb)); +#else + my_ospeed = (NCURSES_OSPEED) termp->Nttyb.sg_ospeed; +#endif + result = _nc_baudrate(my_ospeed); +#endif + termp->_baudrate = result; + ospeed = (NCURSES_OSPEED) my_ospeed; +} + #undef SETUP_FAIL #define SETUP_FAIL FALSE @@ -158,13 +186,24 @@ drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret) } result = TRUE; #if !USE_REENTRANT - strncpy(ttytype, termp->type.term_names, (size_t) NAMESIZE - 1); - ttytype[NAMESIZE - 1] = '\0'; +#define MY_SIZE (size_t) NAMESIZE - 1 + _nc_STRNCPY(ttytype, termp->type.term_names, MY_SIZE); + ttytype[MY_SIZE] = '\0'; #endif if (command_character) _nc_tinfo_cmdch(termp, *command_character); + /* + * If an application calls setupterm() rather than initscr() or + * newterm(), we will not have the def_prog_mode() call in + * _nc_setupscreen(). Do it now anyway, so we can initialize the + * baudrate. + */ + if (sp == 0 && NC_ISATTY(termp->Filedes)) { + get_baudrate(termp); + } + if (generic_type) { /* * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity @@ -261,8 +300,8 @@ drv_defaultcolors(TERMINAL_CONTROL_BLOCK * TCB, int fg, int bg) sp->_has_sgr_39_49 = (NCURSES_SP_NAME(tigetflag) (NCURSES_SP_ARGx "AX") == TRUE); - sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK); - sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK); + sp->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg; + sp->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg; if (sp->_color_pairs != 0) { bool save = sp->_default_color; sp->_default_color = TRUE; @@ -358,7 +397,7 @@ drv_size(TERMINAL_CONTROL_BLOCK * TCB, int *linep, int *colp) if (sp) { useEnv = sp->_use_env; - useTioctl = sp->_use_tioctl; + useTioctl = sp->use_tioctl; } else { useEnv = _nc_prescreen.use_env; useTioctl = _nc_prescreen.use_tioctl;