import Text.RegexPR import System.Environment import Control.Arrow main :: IO () main = do cnt <- getContents putStrLn "#ifndef _HELLO_H_" putStrLn "#define _HELLO_H_" mapM_ putStrLn $ filter ( not . isSelf ) $ filter isInclude $ lines cnt putStrLn "" mapM_ ( putStrLn . drop 2 ) $ filter isEnum $ lines cnt putStrLn "" mapM_ ( putStrLn . (++ ";") . concatTup2 " " . second toFunDec ) $ getPres isFunDec "" $ lines cnt putStrLn "#endif" isEnum :: String -> Bool isEnum = not . null . getbrsRegexPR "\\/\\/enum\\s+\\S+\\s+{" concatTup2 :: [ a ] -> ( [ a ], [ a ] ) -> [ a ] concatTup2 c ( x1, x2 ) = x1 ++ c ++ x2 isSelf :: String -> Bool isSelf = not . null . getbrsRegexPR "#include\\s+\"hello.h\"" isInclude :: String -> Bool isInclude = not . null . getbrsRegexPR "#include " toFunDec :: String -> String toFunDec = head . getbrsRegexPR "^\\S+\\(.*\\)" isFunDec :: String -> Bool isFunDec = not . null . getbrsRegexPR "^\\S+\\(" getPres :: ( a -> Bool ) -> a -> [ a ] -> [ ( a, a ) ] getPres _ _ [ ] = [ ] getPres p xp ( x : xs ) | p x = ( xp, x ) : getPres p x xs | otherwise = getPres p x xs headOrNull :: [ [ a ] ] -> [ a ] headOrNull ( x : _ ) = x headOrNull [ ] = [ ]