]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/tinfo_driver.c
ncurses 6.0 - patch 20161224
[ncurses.git] / ncurses / tinfo / tinfo_driver.c
index a17accd358e543be61110f942c45e97d5f9a60c1..4a6426fcb08f80181e1d79f64c67cb162297fd30 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2008-2013,2014 Free Software Foundation, Inc.              *
+ * Copyright (c) 2008-2015,2016 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 <curses.priv.h>
 #define CUR ((TERMINAL*)TCB)->type.
 #include <tic.h>
+#include <termcap.h>           /* ospeed */
 
 #if HAVE_NANOSLEEP
 #include <time.h>
@@ -50,7 +51,7 @@
 # endif
 #endif
 
-MODULE_ID("$Id: tinfo_driver.c,v 1.39 2014/09/27 21:58:57 tom Exp $")
+MODULE_ID("$Id: tinfo_driver.c,v 1.43 2016/12/24 23:20:08 tom Exp $")
 
 /*
  * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS,
@@ -113,6 +114,36 @@ 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
+
 static bool
 drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
 {
@@ -121,6 +152,7 @@ drv_CanHandle(TERMINAL_CONTROL_BLOCK * TCB, const char *tname, int *errret)
     TERMINAL *termp;
     SCREEN *sp;
 
+    START_TRACE();
     T((T_CALLED("tinfo::drv_CanHandle(%p)"), TCB));
 
     assert(TCB != 0 && tname != 0);
@@ -154,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
@@ -1186,7 +1229,7 @@ drv_read(TERMINAL_CONTROL_BLOCK * TCB, int *buf)
     if ((pthread_self) && (pthread_kill) && (pthread_equal))
        _nc_globals.read_thread = pthread_self();
 # endif
-    n = read(sp->_ifd, &c2, (size_t) 1);
+    n = (int) read(sp->_ifd, &c2, (size_t) 1);
 #if USE_PTHREADS_EINTR
     _nc_globals.read_thread = 0;
 #endif