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
+ | B50
+ | B576000
+ | B921600
+ | B100
+ | B1152000
+ | B150
+ | B200
+ | B250
+ | B300
+ | B350
+ | B400
+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 B50 = ``B50''
+baud2Word B576000 = ``B576000''
+baud2Word B921600 = ``B921600''
+baud2Word B100 = ``B100''
+baud2Word B1152000 = ``B1152000''
+baud2Word B150 = ``B150''
+baud2Word B200 = ``B200''
+baud2Word B250 = ``B250''
+baud2Word B300 = ``B300''
+baud2Word B350 = ``B350''
+baud2Word B400 = ``B400''
-- 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")
+