diff --git a/Debian/Changes.hs b/Debian/Changes.hs
--- a/Debian/Changes.hs
+++ b/Debian/Changes.hs
@@ -104,7 +104,7 @@
       Just (before, _, _, _) -> Just (Left ("Parse error in changelog at:\n" ++ show before ++ "\nin:\n" ++ text))
     where
       entryRE = mkRegex $ bol ++ blankLines ++ headerRE ++ nonSigLines ++ blankLines ++ signature ++ blankLines
-      nonSigLines = "(((  .*)|([ \t]*)\n)+)"
+      nonSigLines = "(((  .*|\t.*| \t.*)|([ \t]*)\n)+)"
       -- In the debian repository, sometimes the extra space in front of the
       -- day-of-month is missing, sometimes an extra one is added.
       signature = "( -- ([^\n]*)  (..., ? ?.. ... .... ........ .....))[ \t]*\n"
diff --git a/Debian/Extra/CIO.hs b/Debian/Extra/CIO.hs
deleted file mode 100644
--- a/Debian/Extra/CIO.hs
+++ /dev/null
@@ -1,61 +0,0 @@
-module Debian.Extra.CIO
-    ( tMessage
-    , vMessage
-    , printStdout
-    , printStderr
-    , printOutput
-    , dotOutput
-    ) where
-
-import qualified Data.ByteString.Char8 as B
-import Extra.CIO
-import Prelude hiding (putStr)
-import System.Unix.Process
-
--- |Print a message without forcing the command's output
-tMessage :: CIO m => String -> a -> m a
-tMessage message output = ePutStrBl message >> return output
-
--- |Print a message without forcing the command's output
-vMessage :: CIO m => Int -> String -> a -> m a
-vMessage v message output = vEPutStrBl v message >> return output
-
--- |Print stdout to stdout
-printStdout :: CIO m => [Output] -> m [Output]
-printStdout output =
-    bol >> mapM print output
-    where
-      print x@(Stdout s) = putStr (B.unpack s) >> return x
-      print x = return x
-
--- |Print stderr to stderr
-printStderr :: CIO m => [Output] -> m [Output]
-printStderr output =
-    eBOL >> mapM print output
-    where
-      print x@(Stderr s) = ePutStr (B.unpack s) >> return x
-      print x = return x
-
--- |Print all the output to the appropriate output channel
-printOutput :: CIO m => [Output] -> m [Output]
-printOutput output =
-    eBOL >> mapM print output
-    where
-      print x@(Stdout s) = putStr (B.unpack s) >> return x
-      print x@(Stderr s) = ePutStr (B.unpack s) >> return x
-      print x = return x
-
--- |Print one dot to stderr for every COUNT characters of output.
-dotOutput :: CIO m => Int -> [Output] -> m [Output]
-dotOutput groupSize output =
-    mapM (\ (count, elem) -> ePutStr (replicate count '.') >> return elem) pairs
-    where
-      pairs = zip (dots 0 (map length output)) output
-      dots _ [] = []
-      dots rem (count : more) =
-          let (count', rem') = divMod (count + rem) groupSize in
-          count' : dots rem' more
-      length (Stdout s) = B.length s
-      length (Stderr s) = B.length s
-      length _ = 0
-
diff --git a/Debian/GenBuildDeps.hs b/Debian/GenBuildDeps.hs
--- a/Debian/GenBuildDeps.hs
+++ b/Debian/GenBuildDeps.hs
@@ -22,13 +22,13 @@
 
 import		 Control.Monad (filterM)
 import		 Debian.Control
+import           Data.Either
 import		 Data.Graph (Graph,buildG,topSort,reachable, transposeG, vertices, edges)
 import		 Data.List
 import qualified Data.Map as Map
 import		 Data.Maybe
 import qualified Data.Set as Set
 import		 Debian.Relation
-import		 Extra.Either (concatEithers)
 import		 System.Directory (getDirectoryContents, doesFileExist)
 import		 System.IO
 
@@ -39,6 +39,14 @@
 type DepInfo = (SrcPkgName,	-- source package name
                 Relations,	-- dependency relations
                 [BinPkgName])	-- binary package names
+
+-- |Turn a list of eithers into an either of lists
+-- copied from Extra.Either
+concatEithers :: [Either a b] -> Either [a] [b]
+concatEithers xs =
+    case partitionEithers xs of 
+      ([], rs) -> Right rs
+      (ls, _) -> Left ls
 
 -- |Return the dependency info for a source package with the given dependency relaxation.
 -- |According to debian policy, only the first paragraph in debian\/control can be a source package
diff --git a/Debian/URI.hs b/Debian/URI.hs
--- a/Debian/URI.hs
+++ b/Debian/URI.hs
@@ -9,11 +9,12 @@
 import Control.OldException (Exception(..),  try)
 --import Control.Monad.Trans (MonadIO)
 import qualified Data.ByteString.Lazy.Char8 as L
-import Extra.Net (webServerDirectoryContents)
+import Data.Maybe (catMaybes)
 import Network.URI
 import System.Directory (getDirectoryContents)
 import System.Exit
 import System.Unix.Process (lazyCommand, collectOutput)
+import Text.Regex (mkRegex, matchRegex)
 
 uriToString' uri = uriToString id uri ""
 
@@ -31,6 +32,19 @@
                                         " cat " ++ show (uriPath uri))
       _ -> cmdOutput ("curl -s -g '" ++ uriToString' uri ++ "'")
 
+-- | Parse the text returned when a directory is listed by a web
+-- server.  This is currently only known to work with Apache.
+-- NOTE: there is a second copy of this function in
+-- Extra:Extra.Net. Please update both locations if you make changes.
+webServerDirectoryContents :: L.ByteString -> [String]
+webServerDirectoryContents text =
+    catMaybes . map (second . matchRegex re) . lines . L.unpack $ text
+    where
+      re = mkRegex "( <A HREF|<a href)=\"([^/][^\"]*)/\""
+      second (Just [_, b]) = Just b
+      second _ = Nothing
+
+
 dirFromURI :: URI -> IO (Either Exception [String])
 dirFromURI uri =
     case (uriScheme uri, uriAuthority uri) of
@@ -39,6 +53,8 @@
                                         " ls -1 " ++ uriPath uri) >>=
                              return . either Left (Right . lines . L.unpack)
       _ -> cmdOutput ("curl -s -g '" ++ uriToString' uri ++ "/'") >>= return . either Left (Right . webServerDirectoryContents)
+
+
 
 cmdOutput :: String -> IO (Either Exception L.ByteString)
 cmdOutput cmd =
diff --git a/Debian/VersionPolicy.hs b/Debian/VersionPolicy.hs
deleted file mode 100644
--- a/Debian/VersionPolicy.hs
+++ /dev/null
@@ -1,267 +0,0 @@
--- |This module contains functions governing the assignment of version
--- numbers, patterned after Ubuntu version number policy:
---
--- (1) To distinguish packages which have been pulled out of one vendor's
--- repository to build for another, we add a vendor name and a build
--- number, so version "1.2-3" becomes "1.2-3vendorname1".  Subsequent
--- builds (perhaps due to changes in build dependencies) would be numbered
--- "1.2-3vendorname2" and so on.
---
--- (2) In addition, packages which are backported, (i.e. built for a
--- non-development release such as Debian etch or Ubuntu feisty) need
--- another tag to distinguish them from the version that would go into
--- the development release (sid or, as of this writing, heron.)  So if
--- we pulled the source for version "1.2-3vendorname4" out of our pool
--- to build for feisty, it would become "1.2-3vendorname4~feisty1".
---
--- (3) The first two policies combine if we
--- are building a package pulled directly from the other vendor into
--- our feisty pool, then "1.2-3" would become 1.2-3vendorname0~feisty1.
--- Subsequent builds of "1.2-3" (perhaps due to changes in build
--- dependencies) would get increasing build numbers,
--- "1.2-3vendorname0~feisty2" etc.
---
--- (4) If the original version number does not end with a digit, a "0" is
--- inserted before the vendor name to facilitate parsing of these tags.
---
--- (5) Finally, an additional tag format is supported for the benefit of
--- one autobuilder client, where before the vendor name an "r" and an
--- integer are inserted.
-module Debian.VersionPolicy
-    ( VersionTag
-    , parseTag
-    , getTag
-    , dropTag
-    , setTag
-    , appendTag
-    , tagCmp
-    , tagMax
-    , bumpTag
-    , newTag
-    , compareSourceAndDist
-    ) where
-
-import Debian.Version
-import Text.Regex
-import Data.List
-import Data.Maybe
-
--- |We implement two types of version number tags.  One has the format
---   @r<releasenumber>vendor<buildnumber>~release<buildnumber>@
--- the other simply
---   @vendor<buildnumber>~release<buildnumber>@
--- There are notes from a meeting that explains why ReleaseTagBuild is
--- more future friendly, but it is also more ugly.
-data VersionTag
-    = VersionTag { extraNumber :: Maybe Int		-- The number following the "r" (do not
-							-- use in new applications.)
-                 , vendorTag :: (String, Int)		-- The vendor name and build number
-                 , releaseTag :: Maybe (String, Int)	-- The release name and build number
-                 } deriving (Show, Eq)
-
--- | Parse a Debian revision string (the portion of the version number
--- following the final dash) into a prefix and a VersionTag.
-parseTag :: String -> DebianVersion -> (DebianVersion, Maybe VersionTag)
-parseTag vendor version =
-    let (e, v, r) = evr version in
-    let (prefix, tag) =
-            case r of
-              Nothing -> (Nothing, Nothing)
-              Just s ->
-                  case matchRegex re s of
-                    Nothing -> (Just s, Nothing)
-                    Just [prefix1, prefix2, buildNo, "", _, _, _, _] ->
-                        (Just (prefix1 ++ prefix2),
-                         Just (VersionTag { extraNumber = Nothing
-                                          , vendorTag = (vendor, read buildNo)
-                                          , releaseTag = Nothing }))
-                    Just [prefix1, prefix2, buildNo, _, releaseName, _, _, releaseNo] ->
-                        (Just (prefix1 ++ prefix2),
-                         Just (VersionTag { extraNumber = Nothing
-                                          , vendorTag = (vendor, read buildNo)
-                                          , releaseTag = Just (releaseName, read releaseNo) }))
-                    Just result -> error $ "Internal error: " ++ show result in
-    -- Try to parse the r5 from the end of the prefix.
-    let (prefix', tag') =
-            case (maybe Nothing (matchRegex extraRE) prefix, tag) of
-              (Just [prefix1, prefix2, digits], Just tag) -> 
-                  (Just (prefix1 ++ prefix2), Just (tag {extraNumber = Just (read digits)}))
-              _ -> (prefix, tag) in
-    (buildDebianVersion e v (if prefix' == Just "0" then Nothing else prefix'), tag')
-    where
-      re = mkRegex (prefixRE ++ digitsRE ++ vendorRE ++ "(" ++ releaseRE ++ ")?$")
-      prefixRE = "^(.*[^0-9])?"
-      digitsRE = "([0-9]+)"
-      vendorRE = vendor ++ "([0-9]+)"
-      releaseRE = "~(([^0-9]+)|(bpo[0-9]+\\+))([0-9]+)"
-      extraRE = mkRegex "^(.*)([0-9]+)r([0-9]+)"
-
--- | The tag returned by splitTag
-getTag :: String -> DebianVersion -> Maybe VersionTag
-getTag vendor version = snd (parseTag vendor version)
-
--- | The prefix returned by splitTag
-dropTag :: String -> DebianVersion -> DebianVersion
-dropTag vendor version = fst (parseTag vendor version)
-
--- |Modify a version number by adding or changing the vendor tag.  The
--- result will be newer than the distVersion (the newest already
--- uploaded version.)  It will also be different from (though not
--- necessarily newer than) any of the elements of allVersions
-setTag :: (String -> String)
-       -- ^ The release name alias function.  As an example, this would map
-       -- the repository etch to the tag bpo40+, as specified by Debian policy.
-       -> String
-       -- ^ The vendor tag
-       -> Maybe String
-       -- ^ The build release, or Nothing if this is a development release
-       -> Maybe Int
-       -- ^ Use old "r0vendor1" format
-       -> Maybe DebianVersion
-       -- ^ The newst version that is already present in the dist.  We need
-       -- to generate a version number newer than this.
-       -> [DebianVersion]
-       -- ^ All the versions that are currently available in the pool.  The
-       -- result must not be a member of this list.
-       -> DebianVersion
-       -- ^ The version number that appears in the newest change log
-       -- entry of the source package.  The result will be this number
-       -- with a version tag added.  If this version is older than the
-       -- current version with its tag stripped, the package cannot be
-       -- built.
-       -> Either String DebianVersion
-       -- ^ The modified version number
-{-setTag alias vendor release extra distVersion allVersions sourceVersion =
-    error ("vendor=" ++ show vendor ++ ", release=" ++ show release ++ ", extra=" ++ show extra ++ ", distVersion=" ++ show distVersion ++ ", allVersions=" ++ show allVersions ++ ", sourceVersion=" ++ show sourceVersion)-}
-setTag alias vendor release extra distVersion allVersions sourceVersion =
-    let oldTag = 
-            case maybe Nothing (Just . parseTag vendor) distVersion of
-              Nothing -> Right Nothing
-              Just (distUpstreamVersion, distTag) ->
-                  case compare sourceUpstreamVersion distUpstreamVersion of
-                    LT -> Left ("Source version " ++ show sourceVersion ++
-                                " is too old to trump uploaded version " ++ show distUpstreamVersion)
-                    GT -> Right Nothing
-                    EQ -> Right distTag in
-    either Left (Right . appendTag alias sourceUpstreamVersion . Just . findAvailableTag . newTag) oldTag
-    where
-      -- The new tag must
-      --  1) be newer than the old tag
-      --  2) be at least as new as the tag in the source code changelog.
-      --  3) have the appropriate releaseTag
-      -- The oldTag may not have an appropriate releaseTag, because the
-      -- distribution may have recently switched from development to
-      -- non-development.  In that case we will have to bump the
-      -- vendor build number, not the release build number, and then
-      -- add the release tag.
-      newTag Nothing =
-          VersionTag {vendorTag = (vendor, 1), releaseTag = maybe Nothing (\ relName -> Just (relName, 1)) release, extraNumber = extra}
-      newTag (Just distTag) =
-          let distTag' = fixReleaseName release (bumpTag distTag) in
-          let sourceTag' = maybe Nothing (Just . setReleaseName release) sourceTag in
-          case tagMax [Just distTag', sourceTag'] of
-            Nothing -> error $ "Internal error"
-            Just tag -> tag
-      (sourceUpstreamVersion, sourceTag) = parseTag vendor sourceVersion
-      -- All the tags of existing packages whose upstream version matches the source
-      allTags = catMaybes (map snd (filter (\ (v, _) -> v == sourceUpstreamVersion) (map (parseTag vendor) allVersions)))
-      -- Repeatedly increment candidate until it differs from the
-      -- elements of all.  Note that this is not the same as taking
-      -- the maximum element and incrementing it, the value we want
-      -- only needs to be not less than candidate.
-      findAvailableTag :: VersionTag -> VersionTag
-      findAvailableTag candidate =
-          if elem candidate allTags then findAvailableTag (bumpTag candidate) else candidate
-
-tagCmp (Just tagA) (Just tagB) =
-    let (_, a) = vendorTag tagA
-        (_, b) = vendorTag tagB in
-    case compare a b of
-      EQ -> case (releaseTag tagA, releaseTag tagB) of
-              (Just (_, a), Just (_, b)) -> compare a b
-              (Nothing, Nothing) -> EQ
-              (Nothing, _) -> LT
-              (_, Nothing) -> GT
-      x -> x
-tagCmp Nothing Nothing = EQ
-tagCmp Nothing _ = LT
-tagCmp _ Nothing = GT
-
-tagMax :: [Maybe VersionTag] -> Maybe VersionTag
-tagMax tags = head (sortBy (flip tagCmp) tags)
-
-bumpTag tag@(VersionTag {releaseTag = Just (relName, relBuild)}) = tag {releaseTag = Just (relName, relBuild + 1)}
-bumpTag tag@(VersionTag {vendorTag = (name, build), releaseTag = Nothing}) = tag {vendorTag = (name, build + 1)}
-
--- If one of the version number candidates has the wrong release name
--- this function fixes it, ensuring that the new tag isn't trumped by
--- the old.
-fixReleaseName release tag@(VersionTag {vendorTag = (vendorName, vendorBuild)}) =
-    case (release, releaseTag tag) of
-      (Just relName, Just (oldRelName, _)) | relName == oldRelName -> tag
-      -- If the release name doesn't match we need to bump the vendor build
-      (Just relName, _) -> tag {vendorTag = (vendorName, vendorBuild+1), releaseTag = Just (relName, 1)}
-      -- Removing an existing release tag always increases the version
-      (Nothing, Just _) -> tag {releaseTag = Nothing}
-      (Nothing, Nothing) -> tag {vendorTag = (vendorName, vendorBuild+1)}
-
--- This is similer to fixReleaseName, but we don't require the result to
--- trump the argument.  This is applied to the source package version number,
--- which is not necessarily present in the dist.
-setReleaseName release tag =
-    case (release, releaseTag tag) of
-      (Just relName, Just (oldRelName, _)) | relName == oldRelName -> tag
-      (Just relName, Just _) -> tag {releaseTag = Just (relName, 1)}
-      (Just relName, Nothing) -> tag {releaseTag = Just (relName, 1)}
-      (Nothing, _) -> tag {releaseTag = Nothing}
-
--- Create a tag which is one click newer.
-newTag vendor Nothing extra = VersionTag { extraNumber = extra, vendorTag = (vendor, 1), releaseTag = Nothing }
-newTag vendor (Just name) extra = VersionTag { extraNumber = extra, vendorTag = (vendor, 0), releaseTag = Just (name, 1) }
-
--- | Format a tag as a string.
-showTag :: (String -> String) -> VersionTag -> String
-showTag alias (VersionTag { extraNumber = extra
-                          , vendorTag = (vendor, vendorBuildNumber)
-                          , releaseTag = releaseInfo }) =
-   maybe "" (("r" ++) . show) extra ++
-         vendor ++ show vendorBuildNumber ++
-         maybe "" (\ (relname, relbuild) -> "~" ++ alias relname ++ show relbuild) releaseInfo
-
--- | Append a vendor tag to a string containing the revision portion
--- of a debian version number.
-appendTag :: (String -> String) -> DebianVersion -> Maybe VersionTag -> DebianVersion
-appendTag _ ver Nothing = ver
-appendTag alias ver (Just tag) =
-    case revision ver of
-      Nothing -> setRevision ver (Just ("0" ++ showTag alias tag))
-      Just rev -> case matchRegex numericSuffixRE rev of
-                    Just [_, ""] -> setRevision ver (Just (rev ++ "0" ++ showTag alias tag))
-                    Just [_, _] -> setRevision ver (Just (rev ++ showTag alias tag))
-                    _ -> error "internal error"
-    where numericSuffixRE = mkRegex "^(.*[^0-9])?([0-9]*)$"
-
--- | Change the revision part of a Debian version number.  (This may
--- belong in Debian.Version.)
-setRevision :: DebianVersion -> Maybe String -> DebianVersion
-setRevision ver rev = buildDebianVersion (epoch ver) (version ver) rev
-
--- Compare the version seen in the source code changelog to a version
--- seen in the distribution.  Since the autobuilder adds tags to the
--- version number of the packages it builds, the distribution version
--- may have been built from the source version even if they differ.
--- Specifically, we must assume that if the version matches when we
--- strip off one or both sections of the tag on the distribution
--- version number.
-compareSourceAndDist vendor s d =
-    let (verS, tagS) = parseTag vendor s
-        (verD, tagD) = parseTag vendor d in
-    let venS = maybe Nothing (Just . vendorTag) tagS
-        venD = maybe Nothing (Just . vendorTag) tagD
-        relS = maybe Nothing releaseTag tagS
-        relD = maybe Nothing releaseTag tagD in
-    case () of
-      _ | verS /= verD -> compare verS verD
-        | isNothing venS && isJust venD -> EQ
-        | isNothing relS && isJust relD -> EQ
-        | True -> compare s d
diff --git a/Distribution/Package/Debian.hs b/Distribution/Package/Debian.hs
--- a/Distribution/Package/Debian.hs
+++ b/Distribution/Package/Debian.hs
@@ -606,6 +606,7 @@
           nub $
           [[D.Rel "debhelper" (Just (D.GRE (parseDebianVersion "7.0"))) Nothing],
            [D.Rel "haskell-devscripts" (Just (D.GRE (parseDebianVersion "0.6.15+nmu7"))) Nothing],
+           [D.Rel "hscolour" Nothing Nothing],
            [D.Rel "cdbs" Nothing Nothing],
            [D.Rel "ghc6" (Just (D.GRE (parseDebianVersion "6.8"))) Nothing]] ++ 
           (if debLibProf flags then [[D.Rel "ghc6-prof" Nothing Nothing]] else []) ++
diff --git a/cbits/gwinsz.c b/cbits/gwinsz.c
new file mode 100644
--- /dev/null
+++ b/cbits/gwinsz.c
@@ -0,0 +1,9 @@
+#include <sys/ioctl.h>
+
+unsigned long c_get_window_size(void) {
+	struct winsize w;
+	if (ioctl (0, TIOCGWINSZ, &w) >= 0)
+		return (w.ws_row << 16) + w.ws_col;
+	else
+		return 0x190050;
+}
diff --git a/debian.cabal b/debian.cabal
--- a/debian.cabal
+++ b/debian.cabal
@@ -1,12 +1,12 @@
 Name:           debian
-Version:        3.35
+Version:        3.40
 License:        BSD3
 License-File:	debian/copyright
 Author:         David Fox
 Category:	System
 Maintainer:     david@seereason.com
-Homepage:       http://src.seereason.com/ghc610/haskell-debian-3
-Build-Depends:  base >= 4 && < 5, syb, bytestring, containers, directory, filepath, mtl, network, old-locale, parsec, pretty, process, regex-compat, regex-posix, time, unix, bzlib, Extra >= 0.4, HaXml, Unixutils, zlib
+Homepage:       http://src.seereason.com/ghc6103/haskell-debian-3
+Build-Depends:  base >= 4 && < 5, syb, bytestring, containers, directory, filepath, mtl, network, old-locale, parsec >= 3, pretty, process, regex-compat, regex-posix, time, unix, bzlib, HaXml, Unixutils, zlib
 Build-Type:	Simple
 Synopsis:       Modules for working with the Debian package system
 Description:
@@ -26,7 +26,6 @@
 	Debian.Control.ByteString,
 	Debian.Control.String,
 	Debian.Deb,
-	Debian.Extra.CIO,
 	Debian.Extra.Files,
 	Debian.GenBuildDeps,
 	Debian.Relation,
@@ -39,7 +38,6 @@
 	Debian.Version.Common,
 	Debian.Version.String,
 	Debian.Version.ByteString,
-	Debian.VersionPolicy,
 	Debian.Report,
         Debian.Time,
         Debian.URI,
@@ -51,9 +49,7 @@
 	Distribution.Package.Debian.Main,
 	Distribution.Package.Debian
 extra-source-files:
-	tests/Main.hs debian/changelog  
-	debian/compat debian/control debian/copyright
-	debian/rules
+	tests/Main.hs
 
 Executable: fakechanges
 Main-is: utils/FakeChanges.hs
@@ -62,6 +58,9 @@
 Executable: debian-report
 Main-is: utils/Report.hs
 ghc-options: -O2 -threaded -W
+C-Sources:	     cbits/gwinsz.c
+Include-Dirs:        cbits
+Install-Includes:    gwinsz.h
 
 Executable: cabal-debian
 Main-is: utils/CabalDebian.hs
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644
--- a/debian/changelog
+++ /dev/null
@@ -1,493 +0,0 @@
-haskell-debian (3.35) unstable; urgency=low
-
-  * removed dependencies on Extra.HaXml
-  * Updated to base >= 4 && < 5
-  * Fixed test suite
-
- -- Jeremy Shaw <jeremy@seereason.com>  Wed, 01 Jul 2009 09:48:00 -0500
-
-haskell-debian (3.34) unstable; urgency=low
-
-  * cabal-debian: move -doc packages to Build-Depends-Indep
-  * cabal-debian: properly nub Build-Depends and Build-Depends-Indep
-
- -- Jeremy Shaw <jeremy@seereason.com>  Sun, 03 May 2009 12:15:52 -0500
-
-haskell-debian (3.33) unstable; urgency=low
-
-  * cabal-debian: Setion: libdevel -> haskell
-
- -- Jeremy Shaw <jeremy@seereason.com>  Thu, 16 Apr 2009 16:22:35 -0500
-
-haskell-debian (3.32) unstable; urgency=low
-
-  * Add fields to Debian.Changes.ChangedFileSpec for SHA1 and SHA256
-    checksums.
-
- -- David Fox <dsf@seereason.com>  Fri, 03 Apr 2009 07:14:59 -0700
-
-haskell-debian (3.31) unstable; urgency=low
-
-  * update to use newer haskell-devscripts which includes hlibrary.mk
-  * change libghc6-*-doc to haskell-*-doc
-  * move haskell-*-doc to Section: doc
-  * build haskell-*-doc for Architecture 'all' instead of 'any'
-  * make ghc6-doc and haddock Build-Depends-Indep
-  * update Standards-Version to 3.8.1
-  * depend on cdbs and haskell-devscripts instead of haskell-cdbs
-  * only use one space at the beginning of lines in the long description
-  * add ${misc:Depends} to Depends lines
-
- -- Jeremy Shaw <jeremy@seereason.com>  Mon, 23 Mar 2009 20:18:41 -0500
-
-haskell-debian (3.30) unstable; urgency=low
-
-  * Move the modules for dealing with the repository into a new package
-    named haskell-debian-repo.  The cabal-debian tool remains in this
-    package, so this split means that the repo package can change without
-    triggering massive rebuilding due to build dependencies on
-    cabal-debian.
-
- -- David Fox <dsf@seereason.com>  Wed, 18 Feb 2009 06:36:25 -0800
-
-haskell-debian (3.29) unstable; urgency=low
-
-  * Add System.Chroot to list of exported modules
-  * Reduce number of modules loaded by CabalDebian.
-
- -- David Fox <dsf@seereason.com>  Tue, 10 Feb 2009 17:06:47 -0800
-
-haskell-debian (3.28) unstable; urgency=low
-
-  * Add System.Chroot.useEnv, and use it to allow contact with the ssh
-    agent from inside of changeroots.
-
- -- David Fox <dsf@seereason.com>  Mon, 09 Feb 2009 11:18:59 -0800
-
-haskell-debian (3.27) unstable; urgency=low
-
-  * Added apt-get-build-deps. not librarized yet :(
-
- -- Jeremy Shaw <jeremy@seereason.com>  Fri, 06 Feb 2009 18:52:36 -0600
-
-haskell-debian (3.26) unstable; urgency=low
-
-  * Improve the code that decides whether the sources.list has changed,
-    to avoid recreating the build environment as often.
-
- -- David Fox <dsf@seereason.com>  Thu, 05 Feb 2009 08:56:32 -0800
-
-haskell-debian (3.25) unstable; urgency=low
-
-  * Use State monad instead of RWS monad for AptIO
-  * Rename IOState to AptState
-
- -- David Fox <dsf@seereason.com>  Wed, 04 Feb 2009 09:34:24 -0800
-
-haskell-debian (3.24) unstable; urgency=low
-
-  * Use Data.Time instead of System.Time
-  * Fix code to compute the elapsed time for the dpkg-buildpackage.
-  * Restore some generated dependencies that got dropped out of
-    cabal-debian.
-
- -- David Fox <dsf@seereason.com>  Sat, 31 Jan 2009 08:45:51 -0800
-
-haskell-debian (3.23) unstable; urgency=low
-
-  * Eliminate the use of EnvPath in most places, just use a regular
-    path instead.  There were very few places where we actually were
-    inside a changeroot.
-
- -- David Fox <dsf@seereason.com>  Thu, 29 Jan 2009 16:48:23 -0800
-
-haskell-debian (3.22) unstable; urgency=low
-
-  * cabal-debian now has autodetection of ghc6 bundled packages
-
- -- Jeremy Shaw <jeremy@seereason.com>  Thu, 29 Jan 2009 15:26:25 -0600
-
-haskell-debian (3.21) unstable; urgency=low
-
-  * Don't write out postinst and postrm for the doc package, they are
-    now automatically added by haskell-cdbs.
-
- -- David Fox <dsf@seereason.com>  Tue, 27 Jan 2009 10:14:20 -0800
-
-haskell-debian (3.20) unstable; urgency=low
-
-  * Modify the buildable function in GenBuildDeps so it returns more
-    info about the ready packages and what packages each one blocks.
-
- -- David Fox <dsf@seereason.com>  Tue, 27 Jan 2009 06:55:39 -0800
-
-haskell-debian (3.19) unstable; urgency=low
-
-  * Make cabal-debian depend on haskell-cdbs, it used to be the opposite.
-
- -- David Fox <dsf@seereason.com>  Sun, 25 Jan 2009 15:22:41 -0800
-
-haskell-debian (3.18) unstable; urgency=low
-
-  * Modify cabal-debian to it creates debianizations that use the new
-    haskell-cdbs package instead of our modified haskell-devscripts with
-    the cdbs file hlibrary.mk added in.
-  * Have cabal-debian explain what changes it is making to the dependency
-    list.
-
- -- David Fox <dsf@seereason.com>  Sat, 24 Jan 2009 07:27:47 -0800
-
-haskell-debian (3.17) unstable; urgency=low
-
-  * Have cabal-debian --substvar print its result to stderr.
-
- -- David Fox <dsf@seereason.com>  Fri, 23 Jan 2009 10:33:48 -0800
-
-haskell-debian (3.16) unstable; urgency=low
-
-  * Back out register/unregister stuff, just have cabal-debian die if the
-    package doesn't have a library section.
-
- -- David Fox <dsf@seereason.com>  Thu, 22 Jan 2009 15:33:43 -0800
-
-haskell-debian (3.15) unstable; urgency=low
-
-  * Don't leave package registered after computing lbi.
-
- -- David Fox <dsf@seereason.com>  Thu, 22 Jan 2009 14:19:23 -0800
-
-haskell-debian (3.14) unstable; urgency=low
-
-  * Fix a bug that resulted in a fromJust Nothing error.
-
- -- David Fox <dsf@seereason.com>  Thu, 22 Jan 2009 09:59:16 -0800
-
-haskell-debian (3.13) unstable; urgency=low
-
-  * Add the cabal-debian executable to this package to ease bootstrapping.
-
- -- David Fox <dsf@seereason.com>  Fri, 16 Jan 2009 06:41:40 -0800
-
-haskell-debian (3.12) unstable; urgency=low
-
-  * Export some functions and types from Debian.Apt.Index that were
-    already being used by other applications
-  * Allow relation parser to skip empty relations like such as: a, ,c
-
- -- Jeremy Shaw <jeremy@n-heptane.com>  Fri, 09 Jan 2009 18:22:09 -0600
-
-haskell-debian (3.11) unstable; urgency=low
-
-  * Gather code to retrieve the text an URI points to into the Debian.URI
-    module.
-
- -- David Fox <dsf@seereason.com>  Tue, 04 Nov 2008 13:53:33 -0800
-
-haskell-debian (3.10) unstable; urgency=low
-
-  * Change name and arch of doc package.
-
- -- David Fox <dsf@seereason.com>  Sat, 20 Sep 2008 12:07:38 -0700
-
-haskell-debian (3.9) unstable; urgency=low
-
-  * Compute exactly which packages participate in dependency cycles.
-
- -- David Fox <dsf@seereason.com>  Mon, 18 Aug 2008 12:42:56 -0700
-
-haskell-debian (3.8) unstable; urgency=low
-
-  * Don't add an extra newline at the end of the Files section when
-    editing the .changes file.
-
- -- David Fox <dsf@seereason.com>  Mon, 21 Jul 2008 10:57:49 -0700
-
-haskell-debian (3.7) unstable; urgency=low
-
-  * Eliminate all direct uses of TIO, we always use CIO m => so
-    that all functions can be called from the regular IO monad.
-
- -- David Fox <dsf@seereason.com>  Sat, 19 Jul 2008 10:27:49 -0700
-
-haskell-debian (3.6) unstable; urgency=low
-
-  * Remove useless arguments from insertRelease.
-  * Replace debianization
-
- -- David Fox <dsf@seereason.com>  Tue, 01 Jul 2008 10:41:22 -0700
-
-haskell-debian (3.5) unstable; urgency=low
-
-  * Debianization generated by cabal-debian
-
- -- David Fox <dsf@seereason.com>  Sat, 28 Jun 2008 15:49:07 -0700
-
-haskell-debian (3.4) unstable; urgency=low
-
-  * Even correcter code for doing Relax-Depends.  The relaxDeps function
-    is now seperate from the other build depenency functions, which makes
-    things a bit simpler and easier to document.
-
- -- David Fox <dsf@seereason.com>  Wed, 18 Jun 2008 21:00:36 +0000
-
-haskell-debian (3.3) unstable; urgency=low
-
-  * Add code to correctly implement Relax-Depends for non-global
-    dependencies.
-
- -- David Fox <dsf@seereason.com>  Sat, 31 May 2008 07:31:15 +0000
-
-haskell-debian (3.2) unstable; urgency=low
-
-  * Redo the buildable function in GenBuildDeps.
-  * Improve message from OSImage.updateLists.
-
- -- David Fox <dsf@seereason.com>  Sat, 24 May 2008 13:06:09 +0000
-
-haskell-debian (3.1-1) unstable; urgency=low
-
-  * Version number follies.
-
- -- David Fox <dsf@seereason.com>  Thu, 22 May 2008 16:18:47 -0700
-
-haskell-debian (3.1) unstable; urgency=low
-
-  * Re-worked the build dependency computation
-
- -- David Fox <dsf@seereason.com>  Thu, 22 May 2008 10:59:22 -0700
-
-haskell-debian (3.0) unstable; urgency=low
-
-  * Re-organization of module heirarchy.
-
- -- David Fox <dsf@seereason.com>  Mon, 19 May 2008 12:47:25 -0700
-
-haskell-debian (2.28) unstable; urgency=low
-
-  * Eliminate use of haskell-ugly library.
-
- -- David Fox <dsf@seereason.com>  Wed, 14 May 2008 12:30:40 -0700
-
-haskell-debian (2.27) unstable; urgency=low
-
-  * Changes for switch to lazy bytestrings in haskell-unixutils.
-
- -- David Fox <dsf@seereason.com>  Tue, 06 May 2008 05:52:51 -0700
-
-haskell-debian (2.26) unstable; urgency=low
-
-  * Improve error report from "Missing control file or changelog"
-
- -- David Fox <dsf@seereason.com>  Mon, 05 May 2008 05:59:27 -0700
-
-haskell-debian (2.25) unstable; urgency=low
-
-  * Packaging changes for haskell-devscripts 0.6.10.
-
- -- David Fox <dsf@seereason.com>  Sat, 29 Mar 2008 10:25:54 -0700
-
-haskell-debian (2.24) unstable; urgency=low
-
-  * New version of dupload reads both /etc/dupload.conf and ~/.dupload.conf, so
-    we have to explicitly unset $preupload in ~/.dupload.conf.
-
- -- David Fox <dsf@seereason.com>  Tue, 25 Mar 2008 05:49:08 -0700
-
-haskell-debian (2.23) unstable; urgency=low
-
-  * Fix a divide by zero error in Debian.Shell.  This should also improve
-    the behavior of the code that outputs one dot per 128 characters of
-    shell command output.
-
- -- David Fox <dsf@seereason.com>  Wed, 12 Mar 2008 16:55:59 +0000
-
-haskell-debian (2.22) unstable; urgency=low
-
-  * Add a chars/dot argument to Shell.dotOutput
-  * Moved some functions from Shell to haskell-unixutils
-  * Moved TIO module to haskell-extra
-
- -- David Fox <dsf@seereason.com>  Sun, 02 Mar 2008 10:14:13 -0800
-
-haskell-debian (2.21) unstable; urgency=low
-
-  * Change some writeFile calls to avoid lazyness in evaluating the
-    second argument, which appears to lead to locked file errors.
-
- -- David Fox <dsf@seereason.com>  Sun, 24 Feb 2008 11:06:53 -0800
-
-haskell-debian (2.20) unstable; urgency=low
-
-  * Message Improvements
-  * Discard duplicate dependency relations
-  * Fix rfc822DateFormat
-
- -- Jeremy Shaw <jeremy@n-heptane.com>  Wed, 20 Feb 2008 13:34:34 -0800
-
-haskell-debian (2.19) unstable; urgency=low
-
-  * Added more functions for working with index files
-
- -- Jeremy Shaw <jeremy@n-heptane.com>  Tue, 19 Feb 2008 16:07:46 -0800
-
-haskell-debian (2.18) unstable; urgency=low
-
-  * Hack: Debian.Local.Insert.addPackagesToIndexes work-around for optimizer bug
-  * Debian.Package: use controlFromIndex instead of calling zcat
-
- -- Jeremy Shaw <jeremy@n-heptane.com>  Mon, 11 Feb 2008 23:08:30 -0800
-
-haskell-debian (2.17) unstable; urgency=low
-
-  * TIO module fixes and cleanups.
-
- -- David Fox <dsf@seereason.com>  Thu, 07 Feb 2008 05:45:00 -0800
-
-haskell-debian (2.16) unstable; urgency=low
-
-  * Add setRepoMap to install cached repository info
-  * Print more info about what happened when a repository appears not to exist.
-
- -- David Fox <ddssff@gmail.com>  Wed, 06 Feb 2008 16:00:45 -0800
-
-haskell-debian (2.15) unstable; urgency=low
-
-  * Fix bug in Debian.VersionPolicy
-  * Split a simple TIO monad out of the AptIO monad.
-  * Simplify Repository type, eliminate parameterized Release etc.
-  * Improve type safety of the SourcesList related types
-
- -- David Fox <ddssff@gmail.com>  Wed, 06 Feb 2008 05:38:12 -0800
-
-haskell-debian (2.14) unstable; urgency=low
-
-  * Rewrite of Debian.VersionPolicy.
-  * Run unit tests during build
-
- -- David Fox <ddssff@gmail.com>  Mon, 28 Jan 2008 13:07:00 -0800
-
-haskell-debian (2.13) unstable; urgency=low
-
-  * Improvements in code currently used to compute the build dependencies.
-    This allows builds of packages which previously caused an combinatoric
-    explosion in memory and time use.  The specific modifications are to
-    avoid making a huge list of all the solution candidates that failed,
-    and to put the relations into a normal form which only involves equals
-    dependencies on packages that are actually available for installation.
-    Finally, a bug in handling of architecture specific dependencies was
-    fixed which might have been causing the extremely long and fruitless
-    searches for some packages' build dependencies.
-
- -- David Fox <ddssff@gmail.com>  Sat, 19 Jan 2008 19:28:32 +0000
-
-haskell-debian (2.12) unstable; urgency=low
-
-  * Add Debian.Apt.Dependecies and Debian.Apt.Package to debian.cabal
-
- -- Jeremy Shaw <jeremy.shaw@linspireinc.com>  Fri, 18 Jan 2008 17:13:24 -0800
-
-haskell-debian (2.11) unstable; urgency=low
-
-  * Added trump detector
-  * Added code to find parents and siblings of a binary package from the
-    Packages/Sources files
-  * Packaging updates
-
- -- Jeremy Shaw <jeremy.shaw@linspireinc.com>  Fri, 14 Dec 2007 13:55:20 -0800
-
-haskell-debian (2.10) unstable; urgency=low
-
-  * Added new interface, Apt.Debian.Methods.fetch which allows the UI
-    portion of fetching (status, authentication), to be controlled by
-    providing a set of callback functions.
-
- -- Jeremy Shaw <jeremy.shaw@linspireinc.com>  Tue, 20 Nov 2007 14:07:43 -0800
-
-haskell-debian (2.9) unstable; urgency=low
-
-  * Add caching of loaded package indexes based on the path and the
-    file status of the cached index file.  Also splits Debian.Types
-    into several modules.
-
- -- David Fox <dsf@seereason.org>  Fri,  9 Nov 2007 11:05:11 -0800
-
-haskell-debian (2.8) unstable; urgency=low
-
-  * Last version had bogus dependencies due to an unknown build error.
-    Make loading of package indexes less lazy in an attempt to reduce
-    memory usage.
-
- -- David Fox <dsf@seereason.org>  Wed,  7 Nov 2007 10:54:27 -0800
-
-haskell-debian (2.7) unstable; urgency=low
-
-  * Make loading of package indexes lazy.
-
- -- David Fox <dsf@seereason.org>  Mon, 22 Oct 2007 11:11:34 -0700
-
-haskell-debian (2.6) unstable; urgency=low
-
-  * Pass --immediate-configure-false to build-env so we can create
-    environments for gutsy, lenny, and sid.
-
- -- David Fox <dsf@seereason.org>  Sat, 20 Oct 2007 16:17:59 -0700
-
-haskell-debian (2.5) unstable; urgency=low
-
-  * Reduce amount of apt-get updating that occurs.
-
- -- David Fox <ddssff@gmail.com>  Sat, 20 Oct 2007 13:50:25 +0000
-
-haskell-debian (2.4) unstable; urgency=low
-
-  * Fix parsing of version tags in VersionPolicy.  It was always failing
-    and therefore not understanding versions we had generated.
-
- -- David Fox <ddssff@gmail.com>  Sat, 13 Oct 2007 04:44:39 -0700
-
-haskell-debian (2.3) unstable; urgency=low
-
-  * The EnvPath and EnvRoot types had show methods that were not
-    invertable by read.  Now they use deriving Show, and use rootPath
-    and the new outsidePath to convert EnvRoot and EnvPath to the
-    FilePath type.  This is a big looking change, but safe.
-  * Replace code that looked at the "Package" and "Version" fields
-    of a parsed control file with calls to packageName and
-    packageVersion, which just returns values already computed and
-    saved in the Package object.
-  * Use EnvPath instead of FilePath in places where it makes sense, such
-    as the copyDebianBuildTree and other places in Debian.SourceTree.
-    This change propagated down in various places, and the cutoff may be
-    a little out of whack in some places, but it is all typesafe (and
-    therefore wonderful?)
-
- -- David Fox <ddssff@gmail.com>  Thu, 11 Oct 2007 15:43:03 +0000
-
-haskell-debian (2.2) unstable; urgency=low
-
-  * Fix a bug in parsing of dependency relations when there is
-    whitespace after a right square brace.
-
- -- David Fox <ddssff@gmail.com>  Tue,  9 Oct 2007 21:00:24 +0000
-
-haskell-debian (2.1) unstable; urgency=low
-
-  * Fix show method of SliceList, the elements need to be
-    terminated by newlines.
-
- -- David Fox <ddssff@gmail.com>  Fri,  5 Oct 2007 00:11:33 -0700
-
-haskell-debian (2.0) unstable; urgency=low
-
-  * Change Apt. to Debian.
-  * Added Debian.Apt.Methods
-  * Added Debian.Deb
-  * Added Debian.Time
-
- -- Jeremy Shaw <jeremy.shaw@linspire.com>  Wed, 19 Sep 2007 15:14:10 -0700
-
-haskell-apt (1.0) unstable; urgency=low
-
-  * Initial Debian package.
-
- -- David Fox <ddssff@gmail.com>  Tue, 18 Sep 2007 09:33:24 -0700
diff --git a/debian/compat b/debian/compat
deleted file mode 100644
--- a/debian/compat
+++ /dev/null
@@ -1,1 +0,0 @@
-5
diff --git a/debian/control b/debian/control
deleted file mode 100644
--- a/debian/control
+++ /dev/null
@@ -1,110 +0,0 @@
-Source: haskell-debian
-Priority: optional
-Section: misc
-Maintainer: David Fox <dsf@seereason.com>
-Build-Depends: debhelper (>= 5.0),
-               haskell-cdbs, haskell-devscripts (>= 0.6.15),
-               ghc6 (>= 6.10),
-               ghc6-doc,
-               haddock (>= 2.1.0),
-               ghc6-prof,
-               libghc6-unixutils-prof (>= 1.18),
-               libghc6-unixutils-doc (>= 1.18),
-               libghc6-time-prof,
-               libghc6-time-doc,
-               libghc6-extra-prof (>= 1.26),
-               libghc6-extra-doc (>= 1.26),
-               libghc6-bzlib-prof,
-               libghc6-bzlib-doc,
-               libghc6-zlib-prof,
-               libghc6-zlib-doc,
-               libghc6-haxml-dev,
-               haxml-doc
-Standards-Version: 3.7.2.2
-Homepage: http://seereason.org/
-
-Package: libghc6-debian-dev
-Architecture: any
-Section: libdevel
-Depends: ${haskell:Depends}
-Description: Modules for working with the Debian package system
-  This library includes modules covering almost every aspect of the Debian
-  packaging system, including low level data types such as version numbers
-  and dependency relations, on up to the types necessary for computing and
-  installing build dependencies, building source and binary packages,
-  and inserting them into a repository.
-  .
-  Author: David Fox
-  .
-  This package contains the normal library files.
-
-Package: libghc6-debian-prof
-Architecture: any
-Section: libdevel
-Depends: ${haskell:Depends},
-         libghc6-debian-dev,
-         libghc6-extra-prof,
-         libghc6-haxml-dev,
-         libghc6-unixutils-prof,
-         libghc6-bzlib-prof,
-         libghc6-zlib-prof
-Description: Modules for working with the Debian package system
-  This library includes modules covering almost every aspect of the Debian
-  packaging system, including low level data types such as version numbers
-  and dependency relations, on up to the types necessary for computing and
-  installing build dependencies, building source and binary packages,
-  and inserting them into a repository.
-  .
-  Author: David Fox
-  .
-  This package contains the profiling library files.
-
-Package: libghc6-debian-doc
-Architecture: any
-Section: libdevel
-Depends: ${haskell:Depends},
-         libghc6-unixutils-doc,
-         libghc6-extra-doc,
-         libghc6-bzlib-doc,
-         libghc6-zlib-doc,
-         haxml-doc
-Description: Modules for working with the Debian package system
-  This library includes modules covering almost every aspect of the Debian
-  packaging system, including low level data types such as version numbers
-  and dependency relations, on up to the types necessary for computing and
-  installing build dependencies, building source and binary packages,
-  and inserting them into a repository.
-  .
-  Author: David Fox
-  .
-  This package contains the documentation files.
-
-Package: fakechanges
-Architecture: any
-Section: devel
-Depends: ${shlibs:Depends}, ${haskell:Depends}
-Description: create a fake .changes file
- Sometimes you have the .debs, .dsc, .tar.gz, .diff.gz, etc from a
- package build, but not the .changes file. This package lets you
- create a fake .changes file in case you need one.
-
-Package: debian-report
-Architecture: any
-Section: devel
-Depends: ${shlibs:Depends}, ${haskell:Depends}
-Description: create reports about Debian repositories
- Analyze Debian repositories and generate reports about their contents
- and relations. For example, a list of all packages in a distribution
- that are trumped by another distribution.
-
-Package: cabal-debian
-Architecture: any
-Section: devel
-Depends: ${shlibs:Depends}, ${haskell:Depends}, haskell-utils, haskell-cdbs, haskell-devscripts (>= 0.6.15), libghc6-cabal-prof
-Description: Tool for creating debianizations of Haskell packages based on the .cabal file.
-
-Package: apt-get-build-depends
-Architecture: any
-Section: devel
-Depends: ${shlibs:Depends}, ${haskell:Depends}, haskell-utils, haskell-cdbs, haskell-devscripts (>= 0.6.15), libghc6-cabal-prof
-Description: Tool which will parse the Build-Depends{-Indep} lines from debian/control and apt-get install the required packages
diff --git a/debian/rules b/debian/rules
deleted file mode 100644
--- a/debian/rules
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/make -f
-include /usr/share/cdbs/1/rules/hlibrary.mk
diff --git a/utils/Report.hs b/utils/Report.hs
--- a/utils/Report.hs
+++ b/utils/Report.hs
@@ -1,18 +1,22 @@
-{-# OPTIONS_GHC -fglasgow-exts #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
 module Main where
 
 import Control.Monad
 import Data.List
+import Data.Maybe (fromMaybe)
 import Debian.Apt.Methods
 import Debian.Report
 import Debian.Sources
-import Extra.Exit
-import System.Environment
+import Foreign.C.Types
+import System.Environment (getArgs, getProgName)
+import System.Exit (exitFailure)
 import Text.XML.HaXml
 import Text.XML.HaXml.Pretty (document)
 import Text.PrettyPrint.HughesPJ
 import System.IO
+import System.Posix.Env
 
+
 -- * main
 
 main :: IO ()
@@ -57,3 +61,36 @@
        case args of
          [dista, distb] -> return (dista, distb)
          _ -> exitWithHelp helpText
+    where
+      -- |exitFailure with nicely formatted help text on stderr
+      exitWithHelp :: (String -> Doc) -- ^ generate help text, the argument is the result of getProgName
+                   -> IO a -- ^ no value is returned, this function always calls exitFailure
+      exitWithHelp helpText =
+          do progName <- getProgName
+             hPutStrLn stderr =<< renderWidth (helpText progName)
+             exitFailure
+      -- |render a Doc using the current terminal width
+      renderWidth :: Doc -> IO String       
+      renderWidth doc =
+          do columns <- return . fromMaybe 80 =<< getWidth
+             return $ renderStyle (Style PageMode columns 1.0) doc
+
+foreign import ccall "gwinsz.h c_get_window_size" c_get_window_size :: IO CLong
+
+-- get the number of rows and columns using ioctl (0, TIOCGWINSZ, &w)
+-- @see also: getWidth
+getWinSize :: IO (Int,Int)
+getWinSize = do (a,b) <- (`divMod` 65536) `fmap` c_get_window_size
+                return (fromIntegral b, fromIntegral a)
+
+-- get the number of colums.
+-- First tries getWinSize, if that returns 0, then try the COLUMNS
+-- shell variable.
+getWidth :: IO (Maybe Int)
+getWidth =
+    do (cols, _) <- getWinSize
+       case cols of
+         0 -> return . fmap read =<< getEnv "COLUMNS"
+         _ -> return (Just cols)
+
+
