diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c)2011, Jens Stimpfle
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Jens Stimpfle nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/LinkChecker.cabal b/LinkChecker.cabal
new file mode 100644
--- /dev/null
+++ b/LinkChecker.cabal
@@ -0,0 +1,67 @@
+-- LinkChecker.cabal auto-generated by cabal init. For additional
+-- options, see
+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
+-- The name of the package.
+Name:                LinkChecker
+
+-- The package version. See the Haskell package versioning policy
+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
+-- standards guiding when and how versions should be incremented.
+Version:             0.1
+
+-- A short (one-line) description of the package.
+Synopsis:            Check a bunch of local html files for broken links
+
+-- A longer description of the package.
+Description:         CLI tool to check for broken links in your static html files. Checking is done using HTTP HEAD requests, and only one request per URL is done per running instance (even if linked from several different files).
+
+-- URL for the project homepage or repository.
+Homepage:            http://janzzstimmpfle.de/~jens/software/LinkChecker/
+
+-- The license under which the package is released.
+License:             BSD3
+
+-- The file containing the license text.
+License-file:        LICENSE
+
+-- The package author(s).
+Author:              Jens Stimpfle
+
+-- An email address to which users can send suggestions, bug reports,
+-- and patches.
+Maintainer:          jens@janzzstimmpfle.de
+
+-- A copyright notice.
+-- Copyright:           
+
+Category:            Web
+
+Build-type:          Simple
+
+-- Extra files to be distributed with the package, such as examples or
+-- a README.
+-- Extra-source-files:  
+
+-- Constraint on the version of Cabal needed to build this package.
+Cabal-version:       >=1.2
+
+
+Executable linkchecker
+  -- .hs or .lhs file containing the Main module.
+  Main-is:             LinkChecker.hs
+  
+  -- Packages needed in order to build this package.
+  Build-depends:       tagsoup >=0.12.2,
+                       containers >=0.3.0.0,
+                       HTTP >=4000.0.0,
+                       network >=2.2.1.7,
+                       haskell98,
+                       base >=4.0.0.0 && <5.0.0.0,
+                       mtl >=2.0.1.0
+  
+  -- Modules not exported by this package.
+  -- Other-modules:       
+  
+  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
+  -- Build-tools:         
+  
diff --git a/LinkChecker.hs b/LinkChecker.hs
new file mode 100644
--- /dev/null
+++ b/LinkChecker.hs
@@ -0,0 +1,181 @@
+import                  Text.HTML.TagSoup as T
+import                  Control.Monad
+import                  Control.Monad.Reader
+import                  Control.Monad.State
+import                  Data.Maybe
+import                  Data.Char
+import                  Data.List
+import                  System
+import                  Network.Stream
+import                  Network.URI
+import                  Network.HTTP
+import qualified        Data.Map        as M
+
+-- Stolen from GHC.Exts
+sortWith :: Ord b => (a -> b) -> [a] -> [a]
+sortWith f = sortBy (\x y -> compare (f x) (f y))
+
+main :: IO ()
+main =
+    fmap makeConfig getArgs
+    >>= runReaderT (
+        (ask >>= liftIO . putStrLn . ("\n"++) . (++"\n") . show)
+        >> makeFilesList
+        >>= processFiles
+        >>= displayResults)
+
+data Config = Config
+    { configSeparator   :: Char
+    , configMappings    :: [(String,URI)]
+    , configNoReportCodes :: [Integer]
+    } deriving Show
+
+-- For storing URIs in Data.Map
+instance Ord URI where
+    x <  y = show x <  show y
+    x <= y = show x <= show y
+
+type FileProcessingResult = (FilePath, Either String [HrefProcessingResult])
+type HrefProcessingResult = (Href, URIProcessingResult)
+type Href                 = String
+type URIProcessingResult  = Result (Response String)
+type URIMap               = M.Map URI URIProcessingResult
+
+defaultConfig :: Config
+defaultConfig =
+    Config { configSeparator = '\n'
+           , configMappings = []
+           , configNoReportCodes = [200]
+           }
+
+makeConfig :: [String] -> Config
+makeConfig arguments = foldl (flip ($)) defaultConfig (makeConfig' arguments)
+ where
+  makeConfig' :: [String] -> [Config -> Config]
+  makeConfig' args = case args of
+    []          -> []
+    ("-0":rest) ->
+            (\x -> x { configSeparator = '\NUL' })
+            : makeConfig' rest
+    ("--map" : fpath : uri : rest) ->
+            (\x -> x { configMappings = reverse $ sortWith fst $ configMappings x
+                                    ++ [( fpath
+                                        , fromMaybe
+                                            (error $ "Not a valid URL: " ++ uri)
+                                            (parseAbsoluteURI uri)
+                                        )] })
+            : makeConfig' rest
+    ("-n":xs) ->
+            let (consumed,rest) = span (\x -> all isDigit x && length x == 3) xs
+            in if null consumed
+             then error "No valid args for -n option (3-digit numbers)"
+             else (\x -> x { configNoReportCodes = map (read::String->Integer) consumed })
+                  : makeConfig' rest
+    garbage -> error $ "Unconsumed commandline arguments: " ++ show garbage
+
+makeFilesList :: ReaderT Config IO [String]
+makeFilesList = do
+    config <- ask
+    liftIO $ fmap (linesWith $ configSeparator config) getContents
+    where
+        linesWith sep contents = let (l, s') = break (== sep) contents
+                        in  l : case s' of
+                                     []      -> []
+                                     (_:s'') -> lines s''
+
+processFiles :: [FilePath] -> ReaderT Config IO [FileProcessingResult]
+processFiles fpaths =
+    evalStateT (mapM (\p -> sanitize p $ processFile p) fpaths) M.empty
+ where
+    -- We must catch io errors per-file to avoid throwing away the other results
+    sanitize fp func = do
+        s <- get
+        config <- lift ask
+        liftIO $ catch
+                    (runReaderT (evalStateT func s) config)
+                    (\e -> return (fp, Left $ show e))
+
+processFile :: FilePath -> StateT URIMap (ReaderT Config IO) FileProcessingResult
+processFile fpath = do
+    (b, hrefs) <- liftIO $ extractHrefs fpath
+    config <- lift ask
+    let
+        -- take longest (first) match and create baseURI as combination of implicit and explicit base href
+        bestMatch       = listToMaybe $ filter (\(str,_) -> str `isPrefixOf` fpath) (configMappings config)
+        implicitBaseURI = fromMaybe nullURI $ bestMatch >>= makeUpURI fpath
+         where
+            makeUpURI string mapping = ((`relativeTo` snd mapping) . fromMaybe nullURI . parseURIReference) $ drop (length $ fst mapping) string
+        baseURI = fromMaybe nullURI (fromMaybe nullURI (parseAbsoluteURI $ fromMaybe "" b) `relativeTo` implicitBaseURI)
+    ret <- mapM (processHref baseURI) hrefs
+    return (fpath, Right ret)
+
+processHref :: URI -> Href -> StateT URIMap (ReaderT Config IO) HrefProcessingResult
+processHref baseURI href = do
+    oldMap <- get
+    let maybeURI = parseURIReference href
+    if isNothing maybeURI then
+        return (href, Left $ ErrorParse "Couldn't parse href")
+     else if not (null $ uriScheme $ fromJust maybeURI) && uriScheme (fromJust maybeURI) /= "http:" then
+        return (href, Left $ ErrorParse "Not evaluating non-http locator")
+     else do
+        let
+            requestURI = fromJust $ fromJust maybeURI `relativeTo` baseURI -- relativeTo never returns Nothing. wtf
+        liftIO $ putStrLn $ "Checking: " ++ show requestURI
+        reqres <- maybe
+                   (do
+                       res <- liftIO $ simpleHTTP $ Request requestURI HEAD [] ""
+                       put $ M.insert requestURI res oldMap
+                       return res)
+                   return
+                   (M.lookup requestURI oldMap)
+        -- HACK: prepend requestURI to Href if not fully qualified
+        if (null $ uriScheme $ fromJust maybeURI) ||
+           (isNothing $ uriAuthority $ fromJust maybeURI)
+         then return ("(" ++ show requestURI ++ ") " ++ href, reqres)
+         else return (href, reqres)
+
+extractHrefs :: FilePath -> IO (Maybe String,[String])
+extractHrefs fpath = do
+    tags <- fmap parseTags $ readFile fpath
+    return $ collect $ map examine tags
+ where
+    examine x = case x of
+        TagOpen "base" attrs    -> (listToMaybe $ findHrefs attrs, [])
+        TagOpen _ attrs         -> (Nothing, findHrefs attrs)
+        _                       -> (Nothing, [])
+    collect = foldl (\(a,b) (x,y) -> (x `mplus` a, b ++ y)) (Nothing,[])
+    findHrefs = mapMaybe $ \a -> case a of
+                     ("href",val) -> Just val
+                     _            -> Nothing
+
+displayResults :: [FileProcessingResult] -> ReaderT Config IO ()
+displayResults = mapM_ displayResult where
+
+    displayResult :: FileProcessingResult -> ReaderT Config IO ()
+    displayResult (fpath, fileresult) = do
+        config <- ask
+        let reports = case fileresult of
+             Left err          -> "Error: " ++ show err
+             Right hrefresults ->
+                let results = filter (mustReport config . snd) hrefresults in
+                if null results
+                 then ""
+                 else unlines $ map showHrefResult results
+        liftIO $ unless (null reports) $ do
+                    putStrLn ""
+                    putStrLn $ underline ("Results for " ++ fpath)
+                    putStrLn reports
+
+    showHrefResult (hr,urires) = case urires of
+            Left connError -> hr ++ "\t" ++ show connError
+            Right response -> hr ++ "\t" ++ (head . lines . show) response
+    underline x = x ++ "\n" ++ map (\_ -> '~') x
+
+mustReport :: Config -> URIProcessingResult -> Bool
+mustReport config res =
+    case res of
+        Left _ -> True
+        Right response -> not $ (assembleRspCode (rspCode response) `elem` configNoReportCodes config)
+    where
+        assembleRspCode :: (Int,Int,Int) -> Integer
+        assembleRspCode (a,b,c) = fromIntegral (100 * a + 10 * b + c)
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
