[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:46:55 UTC 2010


The following commit has been merged in the master branch:
commit f1643e4503d5beac0d1144617e0f318c454e621c
Author: John Goerzen <jgoerzen at complete.org>
Date:   Mon Nov 15 10:49:20 2004 +0100

    Checkpointing printf
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-50)

diff --git a/ChangeLog b/ChangeLog
index f7f58dc..a474659 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,23 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-15 03:49:20 GMT	John Goerzen <jgoerzen at complete.org>	patch-50
+
+    Summary:
+      Checkpointing printf
+    Revision:
+      missingh--head--0.5--patch-50
+
+
+    modified files:
+     ChangeLog Makefile libsrc/MissingH/Printf.hs
+     libsrc/MissingH/Printf/Types.hs testsrc/Printftest.hs
+
+    renamed files:
+     libsrc/MissingH/Printf/Types.lhs
+       ==> libsrc/MissingH/Printf/Types.hs
+
+
 2004-11-15 03:23:15 GMT	John Goerzen <jgoerzen at complete.org>	patch-49
 
     Summary:
diff --git a/Makefile b/Makefile
index 773081c..2e62cc6 100644
--- a/Makefile
+++ b/Makefile
@@ -17,10 +17,10 @@
 
 SOURCES := $(wildcard libsrc/MissingH/*.hs) \
 	$(wildcard libsrc/MissingH/*/*.hs) \
-	$(wildcard libsrc/MissingH/*/*.lhs) \
-	$(wildcard libsrc/MissingH/*/*/*.hs) \
+	$(wildcard libsrc/MissingH/*/*/*.hs) 
+LHSSOURCES := $(wildcard libsrc/MissingH/*/*.lhs) \
 	$(wildcard libsrc/MissingH/*/*/*.lhs)
-O1 := $(SOURCES:.hs=.o)
+O1 := $(SOURCES:.hs=.o) $(LHSSOURCES)
 OBJS := $(O1:.lhs=.o)
 
 all: libmissingH.a
@@ -38,7 +38,6 @@ libmissingH.a: $(OBJS)
 %.o: %.lhs
 	ghc -fglasgow-exts -ilibsrc --make `echo $< | sed -e s,libsrc/,, -e s,.lhs$$,, -e s,/,.,g`
 
-
 doc:
 	-rm -rf html
 	mkdir html
diff --git a/libsrc/MissingH/Printf.hs b/libsrc/MissingH/Printf.hs
index 7d1a3b1..7a2a0e2 100644
--- a/libsrc/MissingH/Printf.hs
+++ b/libsrc/MissingH/Printf.hs
@@ -29,6 +29,60 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 This module provides various helpful utilities for using a C-style printf().
 
 Written by John Goerzen, jgoerzen\@complete.org
+
+Some code in sub-modules written by Ian Lynagh
+
+Inspiration and ideas from haskell-xml-rpc by Bjorn Bringert
+
+Welcome to the Haskell printf support.  This module is designed to emulate the
+C printf(3) family of functions.  Here are some examples:
+
+
+>> vsprintf "Hello"
+> "Hello"
+>> vsprintf "Hello, %s\n" "John"
+> "Hello, John\n"
+>> vsprintf "%s, your age is %d\n" "John" (10::Integer)
+> "John, your age is 10\n"
+
+Or, using the list-passing method:
+
+>> sprintf "Hello" ([]::[Value])
+> "Hello"
+>> sprintf "Hello, %s\n" [v "John"]
+> "Hello, John\n"
+>> sprintf "%s, your age is %d\n" [v "John", v (10::Integer)]
+> "John, your age is 10\n"
+
+You can also work with I\/O with these:
+
+> let printer = do
+>               printf "Line1\n"
+>               printf "Line2: %s\n" "blah"
+
+This will print @Line1\\nLine2: blah\\n@ to standard output.
+
+As you can see, there are two different ways to access the printf functions:
+via the variable argument count support (the functions beginning with v)
+or via the list argument support.  There is a utility function, 'v', that
+is simply a shortcut for 'toValue'.
+
+These functions are very similar to the C functions, with the following caveats:
+
+* There is no support for the length specifiers (l, etc.) since these make no
+sense in Haskell.  Haskell's type system provides all the info we need.
+
+* If the type system cannot determine the type if an argument (as in the
+numeric literals above), you may have to explicitly cast it to something.
+In practice, this is only a problem in interactive situations like ghci or
+hugs.
+
+* If you are running in an interact situation, or something where the
+compiler cannot deduce the expected return type, you will need to cast it
+to @String at .  For instance, at the ghci prompt, you would have to say
+@(sprintf \"foo\")::String@ to make things work.  If you are using one of the
+I\/O variants, you will have to instead cast it to @IO ()@.
+
 -}
 
 module MissingH.Printf(-- * Variable-Argument Ouptut
@@ -82,6 +136,8 @@ mkflags x =
         in
         flags''
 
+{- | List version of 'vsprintf'. -}
+
 sprintf :: String -> [Value] -> String
 sprintf [] [] = []
 sprintf ('%' : '%' : xs) y = '%' : sprintf xs y
@@ -116,17 +172,28 @@ sprintf ('%' : xs) (y : ys) =
 
 sprintf (x:xs) y = x : sprintf xs y
 
+{- | Given a format string and zero or more arguments, return a string
+that has formatted them appropriately.  This is the variable argument version
+of 'sprintf'. -}
 vsprintf :: (PFRun a) => String -> a
 vsprintf f = pfrun $ sprintf f
 
+{- | Like 'sprintf', but instead of returning a string, directs output
+to the given Handle. -}
 fprintf :: Handle -> String -> [Value] -> IO ()
 fprintf h f v = hPutStr h $ sprintf f v
 
+{- | Like 'fprintf', but directs output to standard out instead of
+taking an explicit Handle. -}
 printf :: String -> [Value] -> IO ()
 printf f v = fprintf stdout f v
 
+{- | Like 'vsprintf', but instead of returning a string, directs output to
+the given Handle. -}
 vfprintf :: IOPFRun a => Handle -> String -> a
 vfprintf h f = iopfrun h $ sprintf f
 
+{- | Like 'vfprintf', but directs output to standard out instead of taking
+an explicit Handle. -}
 vprintf :: IOPFRun a => String -> a
 vprintf f = vfprintf stdout f
diff --git a/libsrc/MissingH/Printf/Types.lhs b/libsrc/MissingH/Printf/Types.hs
similarity index 97%
rename from libsrc/MissingH/Printf/Types.lhs
rename to libsrc/MissingH/Printf/Types.hs
index 586d3bf..1135b7c 100644
--- a/libsrc/MissingH/Printf/Types.lhs
+++ b/libsrc/MissingH/Printf/Types.hs
@@ -1,6 +1,5 @@
-arch-tag: Printf type declarations
+-- arch-tag: Printf type declarations
 
-\begin{code}
 module MissingH.Printf.Types where
 
 import System.IO
@@ -91,5 +90,5 @@ yvar i = 'y':show i
 
 nvar :: ArgNum -> String
 nvar i = 'n':show i
-\end{code}
+
 
diff --git a/testsrc/Printftest.hs b/testsrc/Printftest.hs
index 45f5634..d0090f3 100644
--- a/testsrc/Printftest.hs
+++ b/testsrc/Printftest.hs
@@ -45,8 +45,9 @@ test_vsprintf_strings =
     "abcde" @=? vsprintf "%.5s" "abcdefghij"
     "abcde" @=? vsprintf "%5.5s" "abcdefg"
     " abcde" @=? vsprintf "%6.5s" "abcdefg"
+    "abcde " @=? vsprintf "%-6.5s" "abcdefg"
     
-    
+  -- TODO: test numeric types  
     
 tests = TestList [TestLabel "vsprintf" (TestCase test_vsprintf),
                   TestLabel "vsprintf strings" (TestCase test_vsprintf_strings)

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list