module Main where import Paths_yjtools_unix (getDataFileName) import Text.RegexPR (matchRegexPR) import System.Directory (getDirectoryContents) import Data.List (isSuffixOf) import Data.Maybe (fromJust) import Distribution.PackageDescription import Distribution.PackageDescription.Parse import Distribution.Verbosity import System.Environment (getArgs) main :: IO () main = do [ fn, crYear, mdfYear ] <- getArgs cabalCont <- getDirectoryContents "." >>= readFile . head . filter (isSuffixOf ".cabal") prgName <- getDirectoryContents "." >>= readCabal . head . filter (isSuffixOf ".cabal") >>= return . fst . head -- . filter ((==fn).modulePath.condTreeData.snd) . condExecutables let getField fld = snd . head . snd . fromJust . matchRegexPR ("(?i)" ++ fld ++ "\\:\\s*(.+)") synopsis = getField "synopsis" cabalCont header <- mkCopyright prgName synopsis (read crYear) (read mdfYear) "Yoshikuni Jujo" "PAF01143@nifty.ne.jp" putStr header cont <- readFile fn putStr $ take (length cont - length cont) "dummy" writeFile fn $ header ++ cont -- addCopyright :: FilePath -> String -> String -> Int -> Int -> String -> String -> IO () -- addCopyright fn prgName synopsis crYear mdfYear author address mkCopyright :: String -> String -> Int -> Int -> String -> String -> IO String mkCopyright prgName synopsis crYear mdfYear author address = do gplHeader <- getDataFileName "gpl_header.txt" >>= readFile return $ "{- " ++ prgName ++ ": " ++ synopsis ++ "\n" ++ "Copyright (C) " ++ show crYear ++ "-" ++ show mdfYear ++ " " ++ author ++ " <" ++ address ++ ">\n\n" ++ gplHeader ++ "-}\n\n" readCabal :: FilePath -> IO GenericPackageDescription readCabal = readPackageDescription normal