#!/usr/bin/env runhaskell import Data.ByteString import Data.ByteString.Lazy.Char8 as BS hiding (filter,take,concat,map,drop,length) import Data.Char import System.Environment import System.Exit import System.IO main :: IO () main = do args <- getArgs case args of [] -> showUsage ["-h"] -> showUsage ["--help"] -> showUsage ["--version"] -> showUsage [check] -> do cf <- readF check nf <- readF "-" doCheck (BS.pack "_") cf nf [check, name] -> do cf <- readF check nf <- readF name doCheck (BS.pack "_") cf nf _ -> showUsage showUsage :: IO () showUsage = do System.IO.hPutStr stderr "Usage : check_attr_name []\n" System.IO.hPutStr stderr "Version : VERSION\n" System.IO.hPutStr stderr "Open usp Tukubai (LINUX+FREEBSD)\n" doCheck :: BS.ByteString -> BS.ByteString -> BS.ByteString -> IO () doCheck ngstr cf nf = return () validate_check_digits :: [Char] -> IO () validate_check_digits digits = do digits <- readF "-" output <- validate_check_even_digits digits * 3 + validate_check_odd_digits digits BS.putStrLn output validate_check_even_digits :: [Char] -> Int validate_check_even_digits [] = 0 validate_check_even_digits (x1:(_:(x2:(_:xs)))) = (digitToInt x1) + (digitToInt x2) + validate_check_even_digits xs validate_check_odd_digits :: [Char] -> Int validate_check_odd_digits [] = 0 validate_check_odd_digits (_:odd_digits) = validate_check_even_digits odd_digits readF :: String -> IO BS.ByteString readF "-" = BS.getContents readF f = BS.readFile f