Changeset 11937 for third-party

Show
Ignore:
Timestamp:
08/06/06 07:55:48 (2 years ago)
Author:
audreyt
Message:

* third-party/: Update fps to the released version of 0.7.

(you may need to nuke dist/build/ and rebuild after this change.)

Location:
third-party/fps
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • third-party/fps/Data/ByteString.hs

    r10591 r11937  
    168168        zip,                    -- :: ByteString -> ByteString -> [(Word8,Word8)] 
    169169        zipWith,                -- :: (Word8 -> Word8 -> c) -> ByteString -> ByteString -> [c] 
     170        zipWith', 
    170171        unzip,                  -- :: [(Word8,Word8)] -> (ByteString,ByteString) 
    171172 
     
    182183        -- ** Using ByteStrings as CStrings 
    183184        useAsCString,           -- :: ByteString -> (CString -> IO a) -> IO a 
    184         unsafeUseAsCString,     -- :: ByteString -> (CString -> IO a) -> IO a 
    185         unsafeUseAsCStringLen,  -- :: ByteString -> (CStringLen -> IO a) -> IO a 
     185        useAsCStringLen,        -- :: ByteString -> (CStringLen -> IO a) -> IO a 
    186186 
    187187        -- ** Copying ByteStrings 
     
    194194 
    195195        -- ** Standard input and output 
    196  
    197 #if defined(__GLASGOW_HASKELL__) 
    198196        getLine,                -- :: IO ByteString 
    199 #endif 
    200197        getContents,            -- :: IO ByteString 
    201198        putStr,                 -- :: ByteString -> IO () 
    202199        putStrLn,               -- :: ByteString -> IO () 
     200        interact,               -- :: (ByteString -> ByteString) -> IO () 
    203201 
    204202        -- ** Files 
     
    209207 
    210208        -- ** I\/O with Handles 
    211 #if defined(__GLASGOW_HASKELL__) 
    212209        getArgs,                -- :: IO [ByteString] 
    213210        hGetLine,               -- :: Handle -> IO ByteString 
    214211        hGetLines,              -- :: Handle -> IO [ByteString] 
    215         hGetNonBlocking,        -- :: Handle -> Int -> IO ByteString 
    216 #endif 
    217212        hGetContents,           -- :: Handle -> IO ByteString 
    218213        hGet,                   -- :: Handle -> Int -> IO ByteString 
     214        hGetNonBlocking,        -- :: Handle -> Int -> IO ByteString 
    219215        hPut,                   -- :: Handle -> ByteString -> IO () 
    220216        hPutStr,                -- :: Handle -> ByteString -> IO () 
     
    236232                                ,scanl,scanl1,scanr,scanr1 
    237233                                ,readFile,writeFile,appendFile,replicate 
    238                                 ,getContents,getLine,putStr,putStrLn 
     234                                ,getContents,getLine,putStr,putStrLn,interact 
    239235                                ,zip,zipWith,unzip,notElem) 
    240236 
     
    261257 
    262258-- hGetBuf and hPutBuf not available in yhc or nhc 
    263 import System.IO                (stdin,stdout,hClose,hFileSize 
    264                                 ,hGetBuf,hPutBuf,openBinaryFile 
    265                                 ,Handle,IOMode(..)) 
     259import System.IO                (stdin,stdout,hClose,hFileSize,hIsEOF 
     260                                ,hGetBuf,hPutBuf,Handle,IOMode(..),openBinaryFile) 
    266261 
    267262import Data.Monoid              (Monoid, mempty, mappend, mconcat) 
     
    269264#if !defined(__GLASGOW_HASKELL__) 
    270265import System.IO.Unsafe 
     266import qualified System.Environment 
     267import qualified System.IO      (hGetLine) 
    271268#endif 
    272269 
     
    449446{-# INLINE unpack #-} 
    450447 
     448-- 
     449-- critical this isn't strict in the acc 
     450-- as it will break in the presence of list fusion. this is a known 
     451-- issue with seq and build/foldr rewrite rules, which rely on lazy 
     452-- demanding to avoid bottoms in the list. 
     453-- 
     454unpackFoldr :: ByteString -> (Word8 -> a -> a) -> a -> a 
     455unpackFoldr (PS fp off len) f ch = withPtr fp $ \p -> do 
     456    let loop q n    _   | q `seq` n `seq` False = undefined -- n.b. 
     457        loop _ (-1) acc = return acc 
     458        loop q n    acc = do 
     459           a <- peekByteOff q n 
     460           loop q (n-1) (a `f` acc) 
     461    loop (p `plusPtr` off) (len-1) ch 
     462{-# INLINE [0] unpackFoldr #-} 
     463 
    451464unpackList :: ByteString -> [Word8] 
    452465unpackList (PS fp off len) = withPtr fp $ \p -> do 
     
    461474"unpack-list"  [1]  forall p  . unpackFoldr p (:) [] = unpackList p 
    462475 #-} 
    463  
    464 unpackFoldr :: ByteString -> (Word8 -> a -> a) -> a -> a 
    465 unpackFoldr (PS fp off len) f ch = withPtr fp $ \p -> do 
    466     let STRICT3(loop) 
    467         loop _ (-1) acc = return acc 
    468         loop q n    acc = do 
    469            a <- peekByteOff q n 
    470            loop q (n-1) (a `f` acc) 
    471     loop (p `plusPtr` off) (len-1) ch 
    472 {-# INLINE [0] unpackFoldr #-} 
    473  
    474 -- TODO just use normal foldr here. 
    475 -- 
    476 -- or 
    477 -- unpack xs | null xs = [] 
    478 --           | otherwise = unsafeHead xs : unpack (unsafeTail xs) 
    479 -- 
    480 -- ? 
    481476 
    482477#endif 
     
    747742-- | Map a function over a 'ByteString' and concatenate the results 
    748743concatMap :: (Word8 -> ByteString) -> ByteString -> ByteString 
    749 concatMap f = foldr (append . f) empty 
    750 -- A silly function for ByteStrings anyway. 
     744concatMap f = concat . foldr ((:) . f) [] 
     745 
     746-- foldr (append . f) empty 
    751747 
    752748-- | /O(n)/ Applied to a predicate and a ByteString, 'any' determines if 
     
    833829------------------------------------------------------------------------ 
    834830 
     831-- | The 'mapAccumL' function behaves like a combination of 'map' and 
     832-- 'foldl'; it applies a function to each element of a ByteString, 
     833-- passing an accumulating parameter from left to right, and returning a 
     834-- final value of this accumulator together with the new list. 
    835835mapAccumL :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 
    836836#if !defined(LOOPU_FUSION) 
     
    841841{-# INLINE mapAccumL #-} 
    842842 
     843-- | The 'mapAccumR' function behaves like a combination of 'map' and 
     844-- 'foldr'; it applies a function to each element of a ByteString, 
     845-- passing an accumulating parameter from right to left, and returning a 
     846-- final value of this accumulator together with the new ByteString. 
    843847mapAccumR :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 
    844848mapAccumR f z = unSP . loopDown (mapAccumEFL f) z 
     
    15271531-- the first argument, instead of a tupling function.  For example, 
    15281532-- @'zipWith' (+)@ is applied to two ByteStrings to produce the list of 
    1529 -- corresponding sums. 
     1533-- corresponding sums.  
    15301534zipWith :: (Word8 -> Word8 -> a) -> ByteString -> ByteString -> [a] 
    15311535zipWith f ps qs 
    15321536    | null ps || null qs = [] 
    15331537    | otherwise = f (unsafeHead ps) (unsafeHead qs) : zipWith f (unsafeTail ps) (unsafeTail qs) 
     1538 
     1539-- 
     1540-- | A specialised version of zipWith for the common case of a 
     1541-- simultaneous map over two bytestrings, to build a 3rd. Rewrite rules 
     1542-- are used to automatically covert zipWith into zipWith' when a pack is 
     1543-- performed on the result of zipWith, but we also export it for 
     1544-- convenience. 
     1545-- 
     1546zipWith' :: (Word8 -> Word8 -> Word8) -> ByteString -> ByteString -> ByteString 
     1547zipWith' f (PS fp s l) (PS fq t m) = inlinePerformIO $ 
     1548    withForeignPtr fp $ \a -> 
     1549    withForeignPtr fq $ \b -> 
     1550    create len $ zipWith_ 0 (a `plusPtr` s) (b `plusPtr` t) 
     1551  where 
     1552    zipWith_ :: Int -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> IO () 
     1553    STRICT4(zipWith_) 
     1554    zipWith_ n p1 p2 r 
     1555       | n >= len = return () 
     1556       | otherwise = do 
     1557            x <- peekByteOff p1 n 
     1558            y <- peekByteOff p2 n 
     1559            pokeByteOff r n (f x y) 
     1560            zipWith_ (n+1) p1 p2 r 
     1561 
     1562    len = min l m 
     1563{-# INLINE zipWith' #-} 
     1564 
     1565{-# RULES 
     1566 
     1567"Specialise zipWith" forall (f :: Word8 -> Word8 -> Word8) p q . 
     1568    pack (zipWith f p q) = zipWith' f p q 
     1569  #-} 
    15341570 
    15351571-- | /O(n)/ 'unzip' transforms a list of pairs of bytes into a pair of 
     
    16141650    return $! PS fp 0 (fromIntegral len) 
    16151651 
    1616 -- | /O(n) construction/ Use a @ByteString@ with a function requiring a null-terminated @CString@. 
    1617 --   The @CString@ should not be freed afterwards. This is a memcpy(3). 
     1652-- | /O(n) construction/ Use a @ByteString@ with a function requiring a 
     1653-- null-terminated @CString@.  The @CString@ will be freed 
     1654-- automatically. This is a memcpy(3). 
    16181655useAsCString :: ByteString -> (CString -> IO a) -> IO a 
    16191656useAsCString (PS ps s l) = bracket alloc (c_free.castPtr) 
    1620     where 
    1621       alloc = withForeignPtr ps $ \p -> do 
    1622                 buf <- c_malloc (fromIntegral l+1) 
    1623                 memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 
    1624                 poke (buf `plusPtr` l) (0::Word8) -- n.b. 
    1625                 return $! castPtr buf 
    1626  
    1627 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CString@. 
    1628 -- Warning: modifying the @CString@ will affect the @ByteString@. 
    1629 -- Why is this function unsafe? It relies on the null byte at the end of 
    1630 -- the ByteString to be there. This is /not/ the case if your ByteString 
    1631 -- has been spliced from a larger string (i.e. with take or drop). 
    1632 -- Unless you can guarantee the null byte, you should use the safe 
    1633 -- version, which will copy the string first. 
    1634 -- 
    1635 unsafeUseAsCString :: ByteString -> (CString -> IO a) -> IO a 
    1636 unsafeUseAsCString (PS ps s _) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s) 
     1657    where alloc = withForeignPtr ps $ \p -> do 
     1658            buf <- c_malloc (fromIntegral l+1) 
     1659            memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 
     1660            poke (buf `plusPtr` l) (0::Word8) -- n.b. 
     1661            return (castPtr buf) 
     1662 
     1663-- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CStringLen@. 
     1664useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 
     1665useAsCStringLen = unsafeUseAsCStringLen 
     1666 
     1667-- 
     1668-- why were we doing this? 
     1669-- 
     1670-- useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 
     1671-- useAsCStringLen (PS ps s l) = bracket alloc (c_free.castPtr.fst) 
     1672--     where 
     1673--       alloc = withForeignPtr ps $ \p -> do 
     1674--                 buf <- c_malloc (fromIntegral l+1) 
     1675--                 memcpy (castPtr buf) (castPtr p `plusPtr` s) (fromIntegral l) 
     1676--                 poke (buf `plusPtr` l) (0::Word8) -- n.b. 
     1677--                 return $! (castPtr buf, l) 
     1678-- 
    16371679 
    16381680-- | /O(n)/ Make a copy of the 'ByteString' with its own storage.  
     
    16571699    memcpy p (castPtr cstr) (fromIntegral len) 
    16581700 
    1659 -- | /O(1) construction/ Use a @ByteString@ with a function requiring a @CStringLen@. 
    1660 -- Warning: modifying the @CStringLen@ will affect the @ByteString@. 
    1661 -- This is analogous to unsafeUseAsCString, and comes with the same safety requirements. 
    1662 unsafeUseAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 
    1663 unsafeUseAsCStringLen (PS ps s l) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s,l) 
    1664  
    16651701-- --------------------------------------------------------------------- 
    16661702-- line IO 
    16671703 
    1668 #if defined(__GLASGOW_HASKELL__) 
    1669  
    1670 -- | getLine, read a line from stdin. 
     1704-- | Read a line from stdin. 
    16711705getLine :: IO ByteString 
    16721706getLine = hGetLine stdin 
    16731707 
    16741708-- | Lazily construct a list of lines of ByteStrings. This will be much 
    1675 -- better on memory consumption than using lines =<< getContents. 
     1709-- better on memory consumption than using 'hGetContents >>= lines' 
     1710-- If you're considering this, a better choice might be to use 
     1711-- Data.ByteString.Lazy 
    16761712hGetLines :: Handle -> IO [ByteString] 
    16771713hGetLines h = go 
    16781714    where 
    16791715        go = unsafeInterleaveIO $ do 
    1680                 ms <- catch (hGetLine h >>= return . Just) 
    1681                             (\_ -> return Nothing) 
    1682                 case ms of 
    1683                     Nothing -> return [] 
    1684                     Just s  -> do ss <- go 
    1685                                   return (s:ss) 
    1686  
    1687 -- | hGetLine. read a ByteString from a handle 
     1716                e <- hIsEOF h 
     1717                if e 
     1718                  then return [] 
     1719                  else do 
     1720                x  <- hGetLine h 
     1721                xs <- go 
     1722                return (x:xs) 
     1723 
     1724-- | Read a line from a handle 
     1725 
    16881726hGetLine :: Handle -> IO ByteString 
     1727#if !defined(__GLASGOW_HASKELL__) 
     1728hGetLine h = do 
     1729  string <- System.IO.hGetLine h 
     1730  return $ packWith c2w string 
     1731#else 
    16891732hGetLine h = wantReadableHandle "Data.ByteString.hGetLine" h $ \ handle_ -> do 
    16901733    case haBufferMode handle_ of 
     
    17871830hGet h i = createAndTrim i $ \p -> hGetBuf h p i 
    17881831 
    1789 #if defined(__GLASGOW_HASKELL__) 
    17901832-- | hGetNonBlocking is identical to 'hGet', except that it will never block 
    17911833-- waiting for data to become available, instead it returns only whatever data 
    17921834-- is available. 
    17931835hGetNonBlocking :: Handle -> Int -> IO ByteString 
     1836#if defined(__GLASGOW_HASKELL__) 
    17941837hGetNonBlocking _ 0 = return empty 
    17951838hGetNonBlocking h i = createAndTrim i $ \p -> hGetBufNonBlocking h p i 
     1839#else 
     1840hGetNonBlocking = hGet 
    17961841#endif 
    17971842 
     
    18311876getContents = hGetContents stdin 
    18321877 
     1878-- | The interact function takes a function of type @ByteString -> ByteString@ 
     1879-- as its argument. The entire input from the standard input device is passed 
     1880-- to this function as its argument, and the resulting string is output on the 
     1881-- standard output device. It's great for writing one line programs! 
     1882interact :: (ByteString -> ByteString) -> IO () 
     1883interact transformer = putStr . transformer =<< getContents 
     1884 
    18331885-- | Read an entire file strictly into a 'ByteString'.  This is far more 
    18341886-- efficient than reading the characters into a 'String' and then using 
    18351887-- 'pack'.  It also may be more efficient than opening the file and 
    1836 -- reading it using hGet. 
     1888-- reading it using hGet. Files are read using 'binary mode' on Windows, 
     1889-- for 'text mode' use the Char8 version of this function. 
    18371890readFile :: FilePath -> IO ByteString 
    18381891readFile f = bracket (openBinaryFile f ReadMode) hClose 
     
    18411894-- | Write a 'ByteString' to a file. 
    18421895writeFile :: FilePath -> ByteString -> IO () 
    1843 writeFile f ps = bracket (openBinaryFile f WriteMode) hClose 
    1844     (\h -> hPut h ps) 
     1896writeFile f txt = bracket (openBinaryFile f WriteMode) hClose 
     1897    (\h -> hPut h txt) 
    18451898 
    18461899-- | Append a 'ByteString' to a file. 
    18471900appendFile :: FilePath -> ByteString -> IO () 
    18481901appendFile f txt = bracket (openBinaryFile f AppendMode) hClose 
    1849     (\hdl -> hPut hdl txt) 
     1902    (\h -> hPut h txt) 
    18501903 
    18511904{- 
     
    19071960-} 
    19081961 
     1962-- 
     1963-- | A ByteString equivalent for getArgs. More efficient for large argument lists 
     1964-- 
     1965getArgs :: IO [ByteString] 
    19091966#if defined(__GLASGOW_HASKELL__) 
    1910 -- 
    1911 -- | A ByteString equivalent for getArgs. More efficient for large argument lists 
    1912 -- 
    1913 getArgs :: IO [ByteString] 
    19141967getArgs = 
    19151968  alloca $ \ p_argc -> 
     
    19191972    argv <- peek p_argv 
    19201973    P.map packCString `fmap` peekArray (p - 1) (advancePtr argv 1) 
     1974#else 
     1975getArgs = do 
     1976  stringArgs <- System.Environment.getArgs 
     1977  return $ List.map (packWith c2w) stringArgs 
    19211978#endif 
    19221979 
  • third-party/fps/Data/ByteString/Base.hs

    r10593 r11937  
    3131        createAndTrim,          -- :: Int -> (Ptr Word8 -> IO Int) -> IO  ByteString 
    3232        createAndTrim',         -- :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a) 
     33        mallocByteString,       -- :: Int -> IO (ForeignPtr a) 
    3334 
    3435        unsafeCreate,           -- :: Int -> (Ptr Word8 -> IO ()) ->  ByteString 
     36        unsafeUseAsCString,     -- :: ByteString -> (CString -> IO a) -> IO a 
     37        unsafeUseAsCStringLen,  -- :: ByteString -> (CStringLen -> IO a) -> IO a 
    3538 
    3639        fromForeignPtr,         -- :: ForeignPtr Word8 -> Int -> ByteString 
     
    8689import Foreign.Storable         (Storable(..)) 
    8790import Foreign.C.Types 
    88 import Foreign.C.String         (CString) 
     91import Foreign.C.String         (CString, CStringLen) 
    8992 
    9093import Control.Exception        (assert) 
     
    200203{-# INLINE unsafeCreate #-} 
    201204 
    202 -- | Wrapper of mallocForeignPtrBytes. 
     205-- | Create ByteString of size @l@ and use action @f@ to fill it's contents. 
    203206create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString 
    204207create l f = do 
    205 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 
    206     fp <- mallocForeignPtrBytes l 
    207 #else 
    208     fp <- mallocPlainForeignPtrBytes l 
    209 #endif 
     208    fp <- mallocByteString l 
    210209    withForeignPtr fp $ \p -> f p 
    211210    return $! PS fp 0 l 
     
    221220createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString 
    222221createAndTrim l f = do 
    223 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 
    224     fp <- mallocForeignPtrBytes l 
    225 #else 
    226     fp <- mallocPlainForeignPtrBytes l 
    227 #endif 
     222    fp <- mallocByteString l 
    228223    withForeignPtr fp $ \p -> do 
    229224        l' <- f p 
     
    234229createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a) 
    235230createAndTrim' l f = do 
    236 #if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 
    237     fp <- mallocForeignPtrBytes l 
    238 #else 
    239     fp <- mallocPlainForeignPtrBytes l 
    240 #endif 
     231    fp <- mallocByteString l 
    241232    withForeignPtr fp $ \p -> do 
    242233        (off, l', res) <- f p 
     
    246237                            memcpy p' (p `plusPtr` off) (fromIntegral l') 
    247238                    return $! (ps, res) 
     239 
     240-- | Wrapper of mallocForeignPtrBytes with faster implementation 
     241-- for GHC 6.5 builds newer than 06/06/06 
     242mallocByteString :: Int -> IO (ForeignPtr a) 
     243mallocByteString l = do 
     244#if defined(SLOW_FOREIGN_PTR) || !defined(__GLASGOW_HASKELL__) 
     245    mallocForeignPtrBytes l 
     246#else 
     247    mallocPlainForeignPtrBytes l 
     248#endif 
    248249 
    249250#if defined(__GLASGOW_HASKELL__) 
     
    362363                          go (i + 1) 
    363364 
     365-- | /O(1) construction/ Use a @ByteString@ with a function requiring a 
     366-- @CString@.  Warning: modifying the @CString@ will affect the 
     367-- @ByteString@.  Why is this function unsafe? It relies on the null 
     368-- byte at the end of the ByteString to be there. Unless you can 
     369-- guarantee the null byte, you should use the safe version, which will 
     370-- copy the string first. 
     371unsafeUseAsCString :: ByteString -> (CString -> IO a) -> IO a 
     372unsafeUseAsCString (PS ps s _) ac = withForeignPtr ps $ \p -> ac (castPtr p `plusPtr` s) 
     373 
     374-- | /O(1) construction/ Use a @ByteString@ with a function requiring a 
     375-- @CStringLen@. 
     376unsafeUseAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a 
     377unsafeUseAsCStringLen (PS ps s l) f = withForeignPtr ps $ \p -> f (castPtr p `plusPtr` s,l) 
     378 
    364379-- --------------------------------------------------------------------- 
    365380--  
  • third-party/fps/Data/ByteString/Char8.hs

    r10591 r11937  
    181181        sort,                   -- :: ByteString -> ByteString 
    182182 
    183         -- * Unchecked access 
     183        -- * Conversion 
    184184        w2c,                    -- :: Word8 -> Char 
    185185        c2w,                    -- :: Char  -> Word8 
     
    188188        readInt,                -- :: ByteString -> Maybe Int 
    189189 
     190        -- * Low level CString conversions 
     191 
     192        -- ** Packing CStrings and pointers 
     193        packCString,            -- :: CString -> ByteString 
     194        packCStringLen,         -- :: CString -> ByteString 
     195        packMallocCString,      -- :: CString -> ByteString 
     196 
     197        -- ** Using ByteStrings as CStrings 
     198        useAsCString,           -- :: ByteString -> (CString -> IO a) -> IO a 
     199        useAsCStringLen,        -- :: ByteString -> (CStringLen -> IO a) -> IO a 
     200 
    190201        -- * Copying ByteStrings 
    191202        copy,                   -- :: ByteString -> ByteString 
     203        copyCString,            -- :: CString -> IO ByteString 
     204        copyCStringLen,         -- :: CStringLen -> IO ByteString 
    192205 
    193206        -- * I\/O with @ByteString@s 
    194207 
    195208        -- ** Standard input and output 
    196  
    197 #if defined(__GLASGOW_HASKELL__) 
    198209        getLine,                -- :: IO ByteString 
    199 #endif 
    200210        getContents,            -- :: IO ByteString 
    201211        putStr,                 -- :: ByteString -> IO () 
    202212        putStrLn,               -- :: ByteString -> IO () 
     213        interact,               -- :: (ByteString -> ByteString) -> IO () 
    203214 
    204215        -- ** Files 
     
    209220 
    210221        -- ** I\/O with Handles 
    211 #if defined(__GLASGOW_HASKELL__) 
    212222        getArgs,                -- :: IO [ByteString] 
    213223        hGetLine,               -- :: Handle -> IO ByteString 
    214224        hGetLines,              -- :: Handle -> IO ByteString 
    215225        hGetNonBlocking,        -- :: Handle -> Int -> IO ByteString 
    216 #endif 
    217226        hGetContents,           -- :: Handle -> IO ByteString 
    218227        hGet,                   -- :: Handle -> Int -> IO ByteString 
     
    242251                                ,dropWhile,span,break,elem,filter,unwords 
    243252                                ,words,maximum,minimum,all,concatMap,scanl,scanl1 
    244                                 ,foldl1,foldr1,readFile,writeFile,appendFile,replicate 
    245                                 ,getContents,getLine,putStr,putStrLn 
     253                                ,appendFile,readFile,writeFile 
     254                                ,foldl1,foldr1,replicate 
     255                                ,getContents,getLine,putStr,putStrLn,interact 
    246256                                ,zip,zipWith,unzip,notElem) 
    247257 
     
    256266                       ,findSubstrings,copy,group 
    257267 
    258                        ,getContents, putStr, putStrLn 
    259                        ,readFile, {-mmapFile,-} writeFile, appendFile 
     268                       ,getLine, getContents, putStr, putStrLn, interact 
    260269                       ,hGetContents, hGet, hPut, hPutStr, hPutStrLn 
     270                       ,getArgs, hGetLine, hGetLines, hGetNonBlocking 
     271                       ,packCString,packCStringLen, packMallocCString 
     272                       ,useAsCString,useAsCStringLen, copyCString,copyCStringLen 
    261273#if defined(__GLASGOW_HASKELL__) 
    262                        ,getLine, getArgs, hGetLine, hGetLines, hGetNonBlocking 
    263274                       ,unpackList 
    264275#endif 
     
    275286import qualified Data.List as List (intersperse) 
    276287 
     288import System.IO                (openFile,hClose,hFileSize,IOMode(..)) 
     289import Control.Exception        (bracket) 
    277290import Foreign 
    278291 
     
    826839{-# INLINE lines #-} 
    827840 
    828 {-# Bogus rule, wrong if there's not \n at end of line 
     841{- Bogus rule, wrong if there's not \n at end of line 
    829842 
    830843"length.lines/count"  
    831844    P.length . lines = count '\n' 
    832845 
    833   #-} 
     846  -} 
    834847 
    835848{- 
     
    10011014filter' :: (Char -> Bool) -> ByteString -> ByteString 
    10021015filter' f = B.filter' (f . w2c) 
     1016 
     1017-- | Read an entire file strictly into a 'ByteString'.  This is far more 
     1018-- efficient than reading the characters into a 'String' and then using 
     1019-- 'pack'.  It also may be more efficient than opening the file and 
     1020-- reading it using hGet. 
     1021readFile :: FilePath -> IO ByteString 
     1022readFile f = bracket (openFile f ReadMode) hClose 
     1023    (\h -> hFileSize h >>= hGet h . fromIntegral) 
     1024 
     1025-- | Write a 'ByteString' to a file. 
     1026writeFile :: FilePath -> ByteString -> IO () 
     1027writeFile f txt = bracket (openFile f WriteMode) hClose 
     1028    (\h -> hPut h txt) 
     1029 
     1030-- | Append a 'ByteString' to a file. 
     1031appendFile :: FilePath -> ByteString -> IO () 
     1032appendFile f txt = bracket (openFile f AppendMode) hClose 
     1033    (\h -> hPut h txt) 
     1034 
  • third-party/fps/Data/ByteString/Lazy.hs

    r10591 r11937  
    1 {-# OPTIONS_GHC -cpp -optc-O1 -fffi -fglasgow-exts -fno-warn-incomplete-patterns #-} 
    2 -- 
    3 -- -optc-O2 breaks with 4.0.4 gcc on debian 
     1{-# OPTIONS_GHC -cpp -fffi -fglasgow-exts -fno-warn-incomplete-patterns #-} 
    42-- 
    53-- Module      : ByteString.Lazy 
     
    7068        map,                    -- :: (Word8 -> Word8) -> ByteString -> ByteString 
    7169        reverse,                -- :: ByteString -> ByteString 
    72         intersperse,            -- :: Word8 -> ByteString -> ByteString 
     70--      intersperse,            -- :: Word8 -> ByteString -> ByteString 
    7371        transpose,              -- :: [ByteString] -> [ByteString] 
    7472 
     
    9795 
    9896        -- ** Accumulating maps 
    99         mapAccumL,              -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 
    100 --      mapAccumR,              -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 
    101         mapIndexed,             -- :: (Int64 -> Word8 -> Word8) -> ByteString -> ByteString 
     97        mapAccumL,  -- :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString) 
     98        mapIndexed, -- :: (Int64 -> Word8 -> Word8) -> ByteString -> ByteString 
    10299 
    103100        -- ** Infinite ByteStrings 
     
    189186        hGet,                   -- :: Handle -> Int -> IO ByteString 
    190187        hGetN,                &n