On Tue, Sep 19, 2000 at 10:04:55 -0700, Sigbjorn Finne wrote:
> POSIX.1 only defines #defined constants upto B38400, so anything
> beyond that is non-standard [...]
... which does not necessarily imply, that GHC is not going to
support it ;-)
Marcus Shawcroft wrote:
>> Can these missing rates be added to hslib without breaking other
>> platforms?
patch attached... the non-standard baud rates are added, and a
function ``isBaudRateSupported'' for testing, whether they are
supported...
NOTE:
For now, I'm not going to apply the patch to the CVS tree... There are
several reasons for it:
* at first, as Sigbjorn pointed out, they are not covered by POSIX.1
and therefore this DOES become a policy issue... I'd like to hear
the opinion of The GHC Team (which is at ICFP currently, AFAIK)...
* The Posix* modules are said to be rewritten once the new FFI has
settled enough, so I don't want to spent too much time on them
now...
* I added instances (Enum, Bounded, Eq) to BaudRate. Sure, I could do
without them, but they're nevertheless useful... but this is an
incompatible change, it *might* break existing code...
BTW: Is there any particular reason, why the other Posix* data
types lack these instances? At least Eq should be supported,
IMHO...
Cheers,
Michael
--
() ASCII ribbon campaign | Chair for Computer Science II | GPG: F65C68CD
/\ against HTML mail | RWTH Aachen, Germany | PGP: 1D0DD0B9
"I WILL NOT BURY THE NEW KID"
-- Bart Simpson in 9F03
---
/home/michaelw/.backup/PosixTTY.lhs!!!mnt!sda5!src!devel!ghc4!ghc-current!hslibs!posix!.~1~
Mon Apr 10 17:19:42 2000
+++ hslibs/posix/PosixTTY.lhs Tue Sep 19 23:00:50 2000
@@ -35,12 +35,14 @@
withOutputSpeed,
withTime,
withoutCC,
- withoutMode
+ withoutMode,
+ isBaudRateSupported
) where
import GlaExts
import IOExts ( unsafePerformIO )
+import Maybe (fromMaybe)
import IO
import PosixUtil
@@ -284,6 +286,23 @@
| B9600
| B19200
| B38400
+ | B57600
+ | B115200
+ | B230400
+ | B460800
+ | B500000
+ | B576000
+ | B921600
+ | B1000000
+ | B1152000
+ | B1500000
+ | B2000000
+ | B2500000
+ | B3000000
+ | B3500000
+ | B4000000
+ deriving (Enum,Bounded,Eq)
+
inputSpeed :: TerminalAttributes -> BaudRate
inputSpeed termios = unsafePerformIO $ do
@@ -406,45 +425,53 @@
-- Convert Haskell BaudRate to unsigned integral type (Word)
baud2Word :: BaudRate -> Word
-baud2Word B0 = ``B0''
-baud2Word B50 = ``B50''
-baud2Word B75 = ``B75''
-baud2Word B110 = ``B110''
-baud2Word B134 = ``B134''
-baud2Word B150 = ``B150''
-baud2Word B200 = ``B200''
-baud2Word B300 = ``B300''
-baud2Word B600 = ``B600''
-baud2Word B1200 = ``B1200''
-baud2Word B1800 = ``B1800''
-baud2Word B2400 = ``B2400''
-baud2Word B4800 = ``B4800''
-baud2Word B9600 = ``B9600''
-baud2Word B19200 = ``B19200''
-baud2Word B38400 = ``B38400''
+baud2Word B0 = ``B0''
+baud2Word B50 = ``B50''
+baud2Word B75 = ``B75''
+baud2Word B110 = ``B110''
+baud2Word B134 = ``B134''
+baud2Word B150 = ``B150''
+baud2Word B200 = ``B200''
+baud2Word B300 = ``B300''
+baud2Word B600 = ``B600''
+baud2Word B1200 = ``B1200''
+baud2Word B1800 = ``B1800''
+baud2Word B2400 = ``B2400''
+baud2Word B4800 = ``B4800''
+baud2Word B9600 = ``B9600''
+baud2Word B19200 = ``B19200''
+baud2Word B38400 = ``B38400''
+baud2Word B57600 = ``B57600''
+baud2Word B115200 = ``B115200''
+baud2Word B230400 = ``B230400''
+baud2Word B460800 = ``B460800''
+baud2Word B500000 = ``B500000''
+baud2Word B576000 = ``B576000''
+baud2Word B921600 = ``B921600''
+baud2Word B1000000 = ``B1000000''
+baud2Word B1152000 = ``B1152000''
+baud2Word B1500000 = ``B1500000''
+baud2Word B2000000 = ``B2000000''
+baud2Word B2500000 = ``B2500000''
+baud2Word B3000000 = ``B3000000''
+baud2Word B3500000 = ``B3500000''
+baud2Word B4000000 = ``B4000000''
-- And convert a word back to a baud rate
--- We really need some cpp macros here.
word2Baud :: Word -> BaudRate
-word2Baud x =
- if x == ``B0'' then B0
- else if x == ``B50'' then B50
- else if x == ``B75'' then B75
- else if x == ``B110'' then B110
- else if x == ``B134'' then B134
- else if x == ``B150'' then B150
- else if x == ``B200'' then B200
- else if x == ``B300'' then B300
- else if x == ``B600'' then B600
- else if x == ``B1200'' then B1200
- else if x == ``B1800'' then B1800
- else if x == ``B2400'' then B2400
- else if x == ``B4800'' then B4800
- else if x == ``B9600'' then B9600
- else if x == ``B19200'' then B19200
- else if x == ``B38400'' then B38400
- else error "unknown baud rate"
+word2Baud x = fromMaybe (error "unknown baud rate")
+ (lookup x baudRateMap)
+ where
+ baudRateMap :: [(Word,BaudRate)]
+ baudRateMap = map (\ x -> (baud2Word x,x)) [minBound .. maxBound]
+
+-- test, whether baud rate is supported
+-- (depends on setting unsupported baud rates to B0)
+
+isBaudRateSupported :: BaudRate -> Bool
+isBaudRateSupported B0 = True
+isBaudRateSupported x = word2Baud (baud2Word x) == x
-- Clear termios i_flag
---
/home/michaelw/.backup/HsPosix.h!!!mnt!sda5!src!devel!ghc4!ghc-current!hslibs!posix!cbits!.~1~
Wed May 31 16:32:09 2000
+++ hslibs/posix/cbits/HsPosix.h Tue Sep 19 22:48:49 2000
@@ -48,6 +48,58 @@
#include <termios.h>
#endif /* HAVE_TERMIOS_H */
+
+/*
+ * the following baud rates are not POSIX.1 compliant,
+ * so if they are not defined, they are set to B0.
+ */
+#ifndef B57600
+# define B57600 B0
+#endif
+#ifndef B115200
+# define B115200 B0
+#endif
+#ifndef B230400
+# define B230400 B0
+#endif
+#ifndef B460800
+# define B460800 B0
+#endif
+#ifndef B500000
+# define B500000 B0
+#endif
+#ifndef B576000
+# define B576000 B0
+#endif
+#ifndef B921600
+# define B921600 B0
+#endif
+#ifndef B1000000
+# define B1000000 B0
+#endif
+#ifndef B1152000
+# define B1152000 B0
+#endif
+#ifndef B1500000
+# define B1500000 B0
+#endif
+#ifndef B2000000
+# define B2000000 B0
+#endif
+#ifndef B2500000
+# define B2500000 B0
+#endif
+#ifndef B3000000
+# define B3000000 B0
+#endif
+#ifndef B3500000
+# define B3500000 B0
+#endif
+#ifndef B4000000
+# define B4000000 B0
+#endif
+
+
#ifdef HAVE_GRP_H
#include <grp.h>
#endif /* HAVE_GRP_H */