]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_baudrate.c
ncurses 6.2 - patch 20200906
[ncurses.git] / ncurses / tinfo / lib_baudrate.c
index bfd2229e3f168a7029df7f6c86aa1433deef29eb..311c41ac97fa4743e88b47cc664d24409080cb01 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 1998-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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -39,7 +40,7 @@
 
 #include <curses.priv.h>
 #include <termcap.h>           /* ospeed */
 
 #include <curses.priv.h>
 #include <termcap.h>           /* ospeed */
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
 #include <sys/param.h>
 #endif
 
 #include <sys/param.h>
 #endif
 
  * of the indices up to B115200 fit nicely in a 'short', allowing us to retain
  * ospeed's type for compatibility.
  */
  * of the indices up to B115200 fit nicely in a 'short', allowing us to retain
  * ospeed's type for compatibility.
  */
-#if NCURSES_OSPEED_COMPAT && ((defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || defined(__NetBSD__) || defined(__OpenBSD__))
+#if NCURSES_OSPEED_COMPAT && \
+       ((defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || \
+       defined(__NetBSD__) || \
+       ((defined(__OpenBSD__) && OpenBSD < 201510)) || \
+       defined(__APPLE__))
 #undef B0
 #undef B50
 #undef B75
 #undef B0
 #undef B50
 #undef B75
@@ -79,7 +84,7 @@
 #undef USE_OLD_TTY
 #endif /* USE_OLD_TTY */
 
 #undef USE_OLD_TTY
 #endif /* USE_OLD_TTY */
 
-MODULE_ID("$Id: lib_baudrate.c,v 1.36 2015/04/18 22:08:58 tom Exp $")
+MODULE_ID("$Id: lib_baudrate.c,v 1.45 2020/09/05 21:15:32 tom Exp $")
 
 /*
  *     int
 
 /*
  *     int
@@ -90,10 +95,11 @@ MODULE_ID("$Id: lib_baudrate.c,v 1.36 2015/04/18 22:08:58 tom Exp $")
  */
 
 struct speed {
  */
 
 struct speed {
-    NCURSES_OSPEED s;          /* values for 'ospeed' */
-    int sp;                    /* the actual speed */
+    int given_speed;           /* values for 'ospeed' */
+    int actual_speed;          /* the actual speed */
 };
 
 };
 
+#if !defined(EXP_WIN32_DRIVER)
 #define DATA(number) { B##number, number }
 
 static struct speed const speeds[] =
 #define DATA(number) { B##number, number }
 
 static struct speed const speeds[] =
@@ -117,6 +123,9 @@ static struct speed const speeds[] =
 #elif defined(EXTA)
     {EXTA, 19200},
 #endif
 #elif defined(EXTA)
     {EXTA, 19200},
 #endif
+#ifdef B28800
+    DATA(28800),
+#endif
 #ifdef B38400
     DATA(38400),
 #elif defined(EXTB)
 #ifdef B38400
     DATA(38400),
 #elif defined(EXTB)
@@ -127,32 +136,80 @@ static struct speed const speeds[] =
 #endif
     /* ifdef to prevent overflow when OLD_TTY is not available */
 #if !(NCURSES_OSPEED_COMPAT && defined(__FreeBSD__) && (__FreeBSD_version > 700000))
 #endif
     /* ifdef to prevent overflow when OLD_TTY is not available */
 #if !(NCURSES_OSPEED_COMPAT && defined(__FreeBSD__) && (__FreeBSD_version > 700000))
+#ifdef B76800
+    DATA(76800),
+#endif
 #ifdef B115200
     DATA(115200),
 #endif
 #ifdef B115200
     DATA(115200),
 #endif
+#ifdef B153600
+    DATA(153600),
+#endif
 #ifdef B230400
     DATA(230400),
 #endif
 #ifdef B230400
     DATA(230400),
 #endif
+#ifdef B307200
+    DATA(307200),
+#endif
 #ifdef B460800
     DATA(460800),
 #endif
 #ifdef B460800
     DATA(460800),
 #endif
+#ifdef B500000
+    DATA(500000),
+#endif
+#ifdef B576000
+    DATA(576000),
+#endif
 #ifdef B921600
     DATA(921600),
 #endif
 #ifdef B921600
     DATA(921600),
 #endif
+#ifdef B1000000
+    DATA(1000000),
+#endif
+#ifdef B1152000
+    DATA(1152000),
+#endif
+#ifdef B1500000
+    DATA(1500000),
+#endif
+#ifdef B2000000
+    DATA(2000000),
+#endif
+#ifdef B2500000
+    DATA(2500000),
+#endif
+#ifdef B3000000
+    DATA(3000000),
+#endif
+#ifdef B3500000
+    DATA(3500000),
+#endif
+#ifdef B4000000
+    DATA(4000000),
+#endif
 #endif
 };
 #endif
 };
+#endif /* !EXP_WIN32_DRIVER */
 
 NCURSES_EXPORT(int)
 _nc_baudrate(int OSpeed)
 {
 
 NCURSES_EXPORT(int)
 _nc_baudrate(int OSpeed)
 {
+#if defined(EXP_WIN32_DRIVER)
+    /* On Windows this is a noop */
+    (void) OSpeed;
+    return (OK);
+#else
 #if !USE_REENTRANT
     static int last_OSpeed;
     static int last_baudrate;
 #endif
 
     int result = ERR;
 #if !USE_REENTRANT
     static int last_OSpeed;
     static int last_baudrate;
 #endif
 
     int result = ERR;
-    unsigned i;
 
 
+    if (OSpeed < 0)
+       OSpeed = (NCURSES_OSPEED) OSpeed;
+    if (OSpeed < 0)
+       OSpeed = (unsigned short) OSpeed;
 #if !USE_REENTRANT
     if (OSpeed == last_OSpeed) {
        result = last_baudrate;
 #if !USE_REENTRANT
     if (OSpeed == last_OSpeed) {
        result = last_baudrate;
@@ -160,9 +217,14 @@ _nc_baudrate(int OSpeed)
 #endif
     if (result == ERR) {
        if (OSpeed >= 0) {
 #endif
     if (result == ERR) {
        if (OSpeed >= 0) {
+           unsigned i;
+
            for (i = 0; i < SIZEOF(speeds); i++) {
            for (i = 0; i < SIZEOF(speeds); i++) {
-               if ((int) speeds[i].s == OSpeed) {
-                   result = speeds[i].sp;
+               if (speeds[i].given_speed > OSpeed) {
+                   break;
+               }
+               if (speeds[i].given_speed == OSpeed) {
+                   result = speeds[i].actual_speed;
                    break;
                }
            }
                    break;
                }
            }
@@ -175,22 +237,27 @@ _nc_baudrate(int OSpeed)
 #endif
     }
     return (result);
 #endif
     }
     return (result);
+#endif /* !EXP_WIN32_DRIVER */
 }
 
 NCURSES_EXPORT(int)
 _nc_ospeed(int BaudRate)
 {
     int result = 1;
 }
 
 NCURSES_EXPORT(int)
 _nc_ospeed(int BaudRate)
 {
     int result = 1;
-    unsigned i;
-
+#if defined(EXP_WIN32_DRIVER)
+    (void) BaudRate;
+#else
     if (BaudRate >= 0) {
     if (BaudRate >= 0) {
+       unsigned i;
+
        for (i = 0; i < SIZEOF(speeds); i++) {
        for (i = 0; i < SIZEOF(speeds); i++) {
-           if (speeds[i].sp == BaudRate) {
-               result = speeds[i].s;
+           if (speeds[i].actual_speed == BaudRate) {
+               result = speeds[i].given_speed;
                break;
            }
        }
     }
                break;
            }
        }
     }
+#endif
     return (result);
 }
 
     return (result);
 }
 
@@ -201,6 +268,9 @@ NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0)
 
     T((T_CALLED("baudrate(%p)"), (void *) SP_PARM));
 
 
     T((T_CALLED("baudrate(%p)"), (void *) SP_PARM));
 
+#if defined(EXP_WIN32_DRIVER)
+    result = OK;
+#else
     /*
      * In debugging, allow the environment symbol to override when we're
      * redirecting to a file, so we can construct repeatable test-cases
     /*
      * In debugging, allow the environment symbol to override when we're
      * redirecting to a file, so we can construct repeatable test-cases
@@ -208,7 +278,7 @@ NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0)
      */
 #ifdef TRACE
     if (IsValidTIScreen(SP_PARM)
      */
 #ifdef TRACE
     if (IsValidTIScreen(SP_PARM)
-       && !NC_ISATTY(fileno(SP_PARM ? SP_PARM->_ofp : stdout))
+       && !NC_ISATTY(fileno((SP_PARM && SP_PARM->_ofp) ? SP_PARM->_ofp : stdout))
        && getenv("BAUDRATE") != 0) {
        int ret;
        if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
        && getenv("BAUDRATE") != 0) {
        int ret;
        if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
@@ -234,7 +304,7 @@ NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0)
     } else {
        result = ERR;
     }
     } else {
        result = ERR;
     }
-
+#endif /* !EXP_WIN32_DRIVER */
     returnCode(result);
 }
 
     returnCode(result);
 }