[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:43:17 UTC 2010


The following commit has been merged in the master branch:
commit 47aaf9849bbab1fc0ed56944d8e153f5c0f00a13
Author: John Goerzen <jgoerzen at complete.org>
Date:   Thu Oct 7 08:36:06 2004 +0100

    Split off binary functions since some environments don't support them
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-40)

diff --git a/ChangeLog b/ChangeLog
index a2aff95..8c9da54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,26 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-07 02:36:06 GMT	John Goerzen <jgoerzen at complete.org>	patch-40
+
+    Summary:
+      Split off binary functions since some environments don't support them
+    Revision:
+      missingh--head--1.0--patch-40
+
+
+    new files:
+     libsrc/MissingH/IO/.arch-ids/=id libsrc/MissingH/IO/Binary.hs
+     testsrc/IOtest.hs
+
+    modified files:
+     ChangeLog Makefile Setup.description libsrc/MissingH/IO.hs
+     testsrc/Tests.hs
+
+    new directories:
+     libsrc/MissingH/IO libsrc/MissingH/IO/.arch-ids
+
+
 2004-10-07 02:19:34 GMT	John Goerzen <jgoerzen at complete.org>	patch-39
 
     Summary:
diff --git a/Makefile b/Makefile
index 97c6bc3..d1b0f13 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-SOURCES := $(wildcard libsrc/MissingH/*.hs)
+SOURCES := $(wildcard libsrc/MissingH/*.hs) $(wildcard libsrc/MissingH/*/*.hs)
 OBJS := $(SOURCES:.hs=.o)
 
 all: libmissingH.a
diff --git a/Setup.description b/Setup.description
index c8af6f4..513540a 100644
--- a/Setup.description
+++ b/Setup.description
@@ -5,5 +5,5 @@ License: GPL
 Maintainer: John Goerzen <jgoerzen at complete.org>
 Stability: Alpha
 Copyright: Copyright (c) 2004 John Goerzen
-Modules: MissingH.List, MissingH.Str, MissingH.IO
+Modules: MissingH.List, MissingH.Str, MissingH.IO, MissingH.IO.Binary
 HS-Source-Dir: libsrc
diff --git a/libsrc/MissingH/IO.hs b/libsrc/MissingH/IO.hs
index e4bb99c..b20d01d 100644
--- a/libsrc/MissingH/IO.hs
+++ b/libsrc/MissingH/IO.hs
@@ -18,36 +18,25 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 {- | This module provides various helpful utilities for dealing with I\/O.
 
+There are more functions in "MissingH.IO.Binary".
+
 Written by John Goerzen, jgoerzen\@complete.org
 -}
 
 module MissingH.IO(-- * Entire File\/Handle Utilities
                        -- ** Opened Handle Data Copying
                        hLineCopy, lineCopy,
-                       hBlockCopy, blockCopy,
                        -- ** Disk File Data Copying
                        copyFileLinesToFile,
-                       copyFileBlocksToFile,
                        -- * Line Processing Utilities
                        hPutStrLns, hGetLines,
-                       -- * Binary Single-Block I\/O
-                       hPutBufStr, putBufStr, hGetBufStr, getBufStr,
-                       hFullGetBufStr, fullGetBufStr,
-                       -- * Binary Multi-Block I\/O
-                       hGetBlocks, getBlocks, hFullGetBlocks, fullGetBlocks,
                        -- * Lazy Interaction
                        -- ** Character-based
                        hInteract,
                        -- ** Line-based
                        hLineInteract, lineInteract,
-                       -- ** Binary Block-based
-                       hBlockInteract, blockInteract,
-                       hFullBlockInteract, fullBlockInteract
                         ) where
 
-import Foreign.Ptr
-import Foreign.ForeignPtr
-import Foreign.C.String
 import System.IO.Unsafe
 import System.IO
 
@@ -138,145 +127,6 @@ hLineInteract finput foutput func =
     lines <- hGetLines finput
     hPutStrLns foutput (func lines)
 
--- . **************************************************
--- . Binary Files
--- . **************************************************
-
-
-{- | As a wrapper around the standard function 'System.IO.hPutBuf',
-this function takes a standard Haskell 'String' instead of the far less
-convenient 'Ptr a'.  The entire contents of the string will be written
-as a binary buffer using 'hPutBuf'.  The length of the output will be
-the length of the string. -}
-hPutBufStr :: Handle -> String -> IO ()
-hPutBufStr f s = withCString s (\cs -> hPutBuf f cs (length s))
-
--- | An alias for 'hPutBufStr' 'stdout'
-putBufStr :: String -> IO ()
-putBufStr = hPutBufStr stdout
-
-{- | As a wrapper around the standard function 'System.IO.hGetBuf',
-this function returns a standard Haskell string instead of modifying
-a 'Ptr a' buffer.  The length is the maximum length to read and the
-semantice are the same as with 'hGetBuf'; namely, the empty string
-is returned with EOF is reached, and any given read may read fewer
-bytes than the given length. -}
-hGetBufStr :: Handle -> Int -> IO String
-hGetBufStr f count = do
-   fbuf <- mallocForeignPtrArray (count + 1)
-   withForeignPtr fbuf (\buf -> do
-                        bytesread <- hGetBuf f buf count
-                        haskstring <- peekCStringLen (buf, bytesread)
-                        return haskstring)
-
--- | An alias for 'hGetBufStr' 'stdin'
-getBufStr :: Int -> IO String
-getBufStr = hGetBufStr stdin
-
-{- | Like 'hGetBufStr', but guarantees that it will only return fewer than
-the requested number of bytes when EOF is encountered. -}
-hFullGetBufStr :: Handle -> Int -> IO String
-hFullGetBufStr f 0 = return ""
-hFullGetBufStr f count = do
-                         thisstr <- hGetBufStr f count
-                         if thisstr == "" -- EOF
-                            then return ""
-                            else do
-                                 remainder <- hFullGetBufStr f (count - (length thisstr))
-                                 return (thisstr ++ remainder)
-
--- | An alias for 'hFullGetBufStr' 'stdin'
-fullGetBufStr :: Int -> IO String
-fullGetBufStr = hFullGetBufStr stdin
-
-{- | Writes the list of blocks to the given file handle -- a wrapper around
-'hPutBufStr'. -}
-hPutBlocks :: Handle -> [String] -> IO ()
-hPutBlocks _ [] = return ()
-hPutBlocks h (x:xs) = do
-                      hPutBufStr h x
-                      hPutBlocks h xs
-
--- | An alias for 'hPutBlocks' 'stdout'
-putBlocks :: [String] -> IO ()
-putBlocks = hPutBlocks stdout
-
-{- | Returns a lazily-evaluated list of all blocks in the input file,
-as read by 'hGetBufStr'.  There will be no 0-length block in this list.
-The list simply ends at EOF. -}
-hGetBlocks :: Handle -> Int -> IO [String]
-hGetBlocks = hGetBlocksUtil hGetBufStr
-
--- | An alias for 'hGetBlocks' 'stdin'
-getBlocks :: Int -> IO [String]
-getBlocks = hGetBlocks stdin
-
-{- | Same as 'hGetBlocks', but using 'hFullGetBufStr' underneath. -}
-hFullGetBlocks :: Handle -> Int -> IO [String]
-hFullGetBlocks = hGetBlocksUtil hFullGetBufStr
-
--- | An alias for 'hFullGetBlocks' 'stdin'
-fullGetBlocks :: Int -> IO [String]
-fullGetBlocks = hFullGetBlocks stdin
-
-hGetBlocksUtil :: (Handle -> Int -> IO String) -> Handle -> Int -> IO [String]
-hGetBlocksUtil readfunc h count =
-    unsafeInterleaveIO (do
-                       block <- readfunc h count
-                       if block == ""
-                          then return []
-                          else do
-                               remainder <- hGetBlocksUtil readfunc h count
-                               return (block : remainder)
-                       )
-
-{- | Binary block-based interaction.  This is useful for scenarios that
-take binary blocks, manipulate them in some way, and then write them
-out.  Take a look at 'hBlockCopy' for an example.  The integer argument
-is the size of input binary blocks.  This function uses 'hGetBlocks'
-internally.
--}
-hBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
-hBlockInteract = hBlockInteractUtil hGetBlocks
-
--- | An alias for 'hBlockInteract' over 'stdin' and 'stdout'
-blockInteract :: Int -> ([String] -> [String]) -> IO ()
-blockInteract x = hBlockInteract x stdin stdout
-
-{- | Same as 'hBlockInteract', but uses 'hFullGetBlocks' instead of
-'hGetBlocks' internally. -}
-hFullBlockInteract :: Int -> Handle -> Handle -> ([String] -> [String]) -> IO ()
-hFullBlockInteract = hBlockInteractUtil hFullGetBlocks
-
--- | An alias for 'hFullBlockInteract' over 'stdin' and 'stdout'
-fullBlockInteract :: Int -> ([String] -> [String]) -> IO ()
-fullBlockInteract x = hFullBlockInteract x stdin stdout
-
-hBlockInteractUtil :: (Handle -> Int -> IO [String]) -> Int ->
-                      Handle -> Handle -> ([String] -> [String]) -> IO ()
-hBlockInteractUtil blockreader blocksize hin hout func =
-    do
-    blocks <- blockreader hin blocksize
-    hPutBlocks hout (func blocks)
-
-{- | Copies everything from the input handle to the output handle using binary
-blocks of the given size.  This is actually a beautiful implementation:
-
-> hBlockCopy bs hin hout = hBlockInteract bs hin hout id
-
-('id' is the built-in Haskell function that just returns whatever is given
-to it)
--}
-
-hBlockCopy :: Int -> Handle -> Handle -> IO ()
-hBlockCopy bs hin hout = hBlockInteract bs hin hout id
-
-{- | Copies from 'stdin' to 'stdout' using binary blocks of the given size.
-An alias for 'hBlockCopy' over 'stdin' and 'stdout'
--}
-blockCopy :: Int -> IO ()
-blockCopy bs = hBlockCopy bs stdin stdout
-
 {- | Copies from one handle to another in text mode (with lines).
 Like 'hBlockCopy', this implementation is nice:
 
@@ -309,20 +159,3 @@ copyFileLinesToFile infn outfn = do
                                  return ()
                                  
 
-{- | Copies one filename to another in binary mode.
-
-Please note that the Unix permission bits on the output file cannot
-be set due to a limitation of the Haskell 'System.IO.openBinaryFile'
-function.  Therefore, you may need to adjust those bits after the copy
-yourself.
-
-This function is implemented using 'hBlockCopy' internally. -}
-copyFileBlocksToFile :: Int -> FilePath -> FilePath -> IO ()
-copyFileBlocksToFile bs infn outfn = do
-                                     hin <- openBinaryFile infn ReadMode
-                                     hout <- openBinaryFile outfn WriteMode
-                                     hBlockCopy bs hin hout
-                                     hClose hin
-                                     hClose hout
-                                     return ()
-
diff --git a/libsrc/MissingH/IO.hs b/libsrc/MissingH/IO/Binary.hs
similarity index 65%
copy from libsrc/MissingH/IO.hs
copy to libsrc/MissingH/IO/Binary.hs
index e4bb99c..2ebea85 100644
--- a/libsrc/MissingH/IO.hs
+++ b/libsrc/MissingH/IO/Binary.hs
@@ -1,4 +1,4 @@
-{- arch-tag: I/O utilities main file
+{- arch-tag: I/O utilities, binary tools
 Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and/or modify
@@ -18,28 +18,37 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 {- | This module provides various helpful utilities for dealing with I\/O.
 
+Important note: /binary functions are not supported in all Haskell
+implementations/.  Do not import or use this module unless you know you
+are using an implementation that supports them.  At this time, here
+is the support status:
+
+ * GHC 6.2: yes
+ 
+ * GHC 6.x, earlier versions: unknown
+
+ * GHC 5.x: no
+
+ * nhc98: no
+
+ * Hugs: no
+
+Non-binary functions may be found in "MissingH.IO".
+
 Written by John Goerzen, jgoerzen\@complete.org
 -}
 
-module MissingH.IO(-- * Entire File\/Handle Utilities
+module MissingH.IO.Binary(-- * Entire File\/Handle Utilities
                        -- ** Opened Handle Data Copying
-                       hLineCopy, lineCopy,
                        hBlockCopy, blockCopy,
                        -- ** Disk File Data Copying
-                       copyFileLinesToFile,
                        copyFileBlocksToFile,
-                       -- * Line Processing Utilities
-                       hPutStrLns, hGetLines,
                        -- * Binary Single-Block I\/O
                        hPutBufStr, putBufStr, hGetBufStr, getBufStr,
                        hFullGetBufStr, fullGetBufStr,
                        -- * Binary Multi-Block I\/O
                        hGetBlocks, getBlocks, hFullGetBlocks, fullGetBlocks,
                        -- * Lazy Interaction
-                       -- ** Character-based
-                       hInteract,
-                       -- ** Line-based
-                       hLineInteract, lineInteract,
                        -- ** Binary Block-based
                        hBlockInteract, blockInteract,
                        hFullBlockInteract, fullBlockInteract
@@ -51,93 +60,6 @@ import Foreign.C.String
 import System.IO.Unsafe
 import System.IO
 
-{- | Given a list of strings, output a line containing each item, adding
-newlines as appropriate.  The list is not expected to have newlines already.
--}
-
-hPutStrLns :: Handle -> [String] -> IO ()
-hPutStrLns _ [] = return ()
-hPutStrLns h (x:xs) = do
-                      hPutStrLn h x
-                      hPutStrLns h xs
-
-{- | Given a handle, returns a list of all the lines in that handle.
-Thanks to lazy evaluation, this list does not have to be read all at once.
-
-Combined with 'hPutStrLns', this can make a powerful way to develop
-filters.  See the 'lineInteract' function for more on that concept.
-
-Example:
-
-> main = do
->        l <- hGetLines stdin
->        hPutStrLns stdout $ filter (startswith "1") l
-
--}
-
-hGetLines :: Handle -> IO [String]
-
-hGetLines h = unsafeInterleaveIO (do
-                                  ieof <- hIsEOF h
-                                  if (ieof) 
-                                     then return []
-                                     else do
-                                          line <- hGetLine h
-                                          remainder <- hGetLines h
-                                          return (line : remainder)
-                                 )
-
-
-{- | This is similar to the built-in 'System.IO.interact', but works
-on any handle, not just stdin and stdout.
-
-In other words:
-
-> interact = hInteract stdin stdout
--}
-hInteract :: Handle -> Handle -> (String -> String) -> IO ()
-hInteract finput foutput func = do
-                                content <- hGetContents finput
-                                hPutStr stdout (func content)
-
-{- | Line-based interaction.  This is similar to wrapping your
-interact functions with 'lines' and 'unlines'.  This equality holds:
-
-> lineInteract = hLineInteract stdin stdout
-
-Here's an example:
-
-> main = lineInteract (filter (startswith "1"))
-
-This will act as a simple version of grep -- all lines that start with 1
-will be displayed; all others will be ignored.
--}
-lineInteract :: ([String] -> [String]) -> IO ()
-lineInteract = hLineInteract stdin stdout
-
-{- | Line-based interaction over arbitrary handles.  This is similar
-to wrapping hInteract with 'lines' and 'unlines'.
-
-One could view this function like this:
-
-> hLineInteract finput foutput func = 
->     let newf = unlines . func . lines in
->         hInteract finput foutput newf
-
-Though the actual implementation is this for efficiency:
-
-> hLineInteract finput foutput func =
->     do
->     lines <- hGetLines finput
->     hPutStrLns foutput (func lines)
--}
-
-hLineInteract :: Handle -> Handle -> ([String] -> [String]) -> IO ()
-hLineInteract finput foutput func =
-    do
-    lines <- hGetLines finput
-    hPutStrLns foutput (func lines)
-
 -- . **************************************************
 -- . Binary Files
 -- . **************************************************
@@ -277,38 +199,6 @@ An alias for 'hBlockCopy' over 'stdin' and 'stdout'
 blockCopy :: Int -> IO ()
 blockCopy bs = hBlockCopy bs stdin stdout
 
-{- | Copies from one handle to another in text mode (with lines).
-Like 'hBlockCopy', this implementation is nice:
-
-> hLineCopy hin hout = hLineInteract hin hout id
--}
-
-hLineCopy :: Handle -> Handle -> IO()
-hLineCopy hin hout = hLineInteract hin hout id
-
-{- | Copies from 'stdin' to 'stdout' using lines.  An alias for 'hLineCopy'
-over 'stdin' and 'stdout'. -}
-
-lineCopy :: IO ()
-lineCopy = hLineCopy stdin stdout
-
-{- | Copies one filename to another in text mode.
-
-Please note that the Unix permission bits are set at a default; you may
-need to adjust them after the copy yourself.
-
-This function is implemented using 'hLineCopy' internally. -}
-
-copyFileLinesToFile :: FilePath -> FilePath -> IO ()
-copyFileLinesToFile infn outfn = do
-                                 hin <- openFile infn ReadMode
-                                 hout <- openFile outfn WriteMode
-                                 hLineCopy hin hout
-                                 hClose hin
-                                 hClose hout
-                                 return ()
-                                 
-
 {- | Copies one filename to another in binary mode.
 
 Please note that the Unix permission bits on the output file cannot
diff --git a/testsrc/runtests.hs b/testsrc/IOtest.hs
similarity index 87%
copy from testsrc/runtests.hs
copy to testsrc/IOtest.hs
index 07e3b72..ef23d84 100644
--- a/testsrc/runtests.hs
+++ b/testsrc/IOtest.hs
@@ -1,4 +1,4 @@
-{- arch-tag: Test runner
+{- arch-tag: IO tests main file
 Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
 
 This program is free software; you can redistribute it and/or modify
@@ -16,10 +16,13 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 -}
 
-module Main where 
-
+module IOtest(foo) where
 import HUnit
-import Tests
+import MissingH.IO
+import Testutil
+
+foo = hInteract
+
+
 
-main = runTestTT tests
 
diff --git a/testsrc/Tests.hs b/testsrc/Tests.hs
index 0916b67..65449c8 100644
--- a/testsrc/Tests.hs
+++ b/testsrc/Tests.hs
@@ -20,6 +20,7 @@ module Tests(tests) where
 import HUnit
 import qualified Listtest
 import qualified Strtest
+import qualified IOtest
 
 test1 = TestCase ("x" @=? "x")
 

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list