From a28b8057a7b0c41413d76df220e1ddef71c32987 Mon Sep 17 00:00:00 2001 From: simonpj Date: Tue, 18 Mar 1997 17:00:21 +0000 Subject: [PATCH] [project @ 1997-03-18 17:00:20 by simonpj] Add Locale.lhs --- ghc/lib/required/IO.lhs | 24 ++++++++++++++++++------ ghc/lib/required/Locale.lhs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 ghc/lib/required/Locale.lhs diff --git a/ghc/lib/required/IO.lhs b/ghc/lib/required/IO.lhs index c727c00..b85de98 100644 --- a/ghc/lib/required/IO.lhs +++ b/ghc/lib/required/IO.lhs @@ -277,7 +277,7 @@ lazyReadLine :: Handle -> PrimIO String lazyReadChar :: Handle -> PrimIO String lazyReadBlock handle = - ioToST (readHandle handle) >>= \ htype -> + ioToST (readHandle handle) >>= \ htype -> case htype of -- There cannae be an ErrorHandle here ClosedHandle -> @@ -305,7 +305,7 @@ lazyReadBlock handle = returnPrimIO (unpackPS some ++ more) lazyReadLine handle = - ioToST (readHandle handle) >>= \ htype -> + ioToST (readHandle handle) >>= \ htype -> case htype of -- There cannae be an ErrorHandle here ClosedHandle -> @@ -333,7 +333,7 @@ lazyReadLine handle = returnPrimIO (unpackPS some ++ more) lazyReadChar handle = - ioToST (readHandle handle) >>= \ htype -> + ioToST (readHandle handle) >>= \ htype -> case htype of -- There cannae be an ErrorHandle here ClosedHandle -> @@ -355,6 +355,7 @@ lazyReadChar handle = unsafeInterleavePrimIO (lazyReadChar handle) >>= \ more -> returnPrimIO (chr char : more) + \end{code} @@ -417,10 +418,21 @@ hPutStr handle str = writeHandle handle htype >> fail (IOError (Just handle) IllegalOperation "handle is not open for writing") other -> + {- + The code below is not correct for line-buffered terminal streams, + as the output stream is not flushed when terminal input is requested + again, just upon seeing a newline character. A temporary fix for the + most common line-buffered output stream, stdout, is to assume the + buffering it was given when created (no buffering). This is not + as bad as it looks, since stdio buffering sits underneath this. + + ToDo: fix me + -} getBufferMode other `thenIO_Prim` \ other -> (case bufferMode other of Just LineBuffering -> - writeLines (filePtr other) str + writeChars (filePtr other) str + --writeLines (filePtr other) str Just (BlockBuffering (Just size)) -> writeBlocks (filePtr other) size str Just (BlockBuffering Nothing) -> @@ -486,8 +498,8 @@ hPutStr handle str = ((C# x):xs) -> write_char arr# n x >> - {- Flushing lines - should we bother? -} - if n ==# bufLen {- || (chopOnNewLine && (x `eqChar#` '\n'#)) -} then + {- Flushing lines - should we bother? Yes, for line-buffered output. -} + if n ==# bufLen || (chopOnNewLine && (x `eqChar#` '\n'#)) then _ccall_ writeFile arr fp (I# (n +# 1#)) >>= \ rc -> if rc == 0 then shoveString 0# xs diff --git a/ghc/lib/required/Locale.lhs b/ghc/lib/required/Locale.lhs new file mode 100644 index 0000000..cea6caa --- /dev/null +++ b/ghc/lib/required/Locale.lhs @@ -0,0 +1,39 @@ +% +% (c) The GRASP/AQUA Project, Glasgow University, 1995-97 +% +\section[Time]{Haskell 1.4 Locale Library} + + +\begin{code} +module Locale(TimeLocale(..), defaultTimeLocale) where + +data TimeLocale = TimeLocale { + wDays :: [(String, String)], -- full and abbreviated week days + months :: [(String, String)], -- full and abbreviated months + amPm :: (String, String), -- AM/PM symbols + dateTimeFmt, dateFmt, -- formatting strings + timeFmt, time12Fmt :: String + } deriving (Eq, Ord, Show) + +defaultTimeLocale :: TimeLocale +defaultTimeLocale = TimeLocale { + wDays = [("Sunday", "Sun"), ("Monday", "Mon"), + ("Tuesday", "Tue"), ("Wednesday", "Wed"), + ("Thursday", "Thu"), ("Friday", "Fri"), + ("Saturday", "Sat")], + + months = [("January", "Jan"), ("February", "Feb"), + ("March", "Mar"), ("April", "Apr"), + ("May", "May"), ("June", "Jun"), + ("July", "Jul"), ("August", "Aug"), + ("September", "Sep"), ("October", "Oct"), + ("November", "Nov"), ("December", "Dec")], + + amPm = ("AM", "PM"), + dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y", + dateFmt = "%m/%d/%y", + timeFmt = "%H:%M:%S", + time12Fmt = "%I:%M:%S %p" + } + +\end{code} -- 1.7.10.4