1 module MyIO(getFilename,process) where
    2 import Numbers
    3 import Vectors
    4 import IO--1.3
    5 import System(getArgs)--1.3
    6 
    7 type InputCont = [String] -> IO ()
    8 
    9 getFilename :: (String -> InputCont) -> InputCont
   10 getFilename success inp = 
   11         getArgs >>= \ args ->
   12         case  args  of
   13                 "help":_ -> usage
   14                 [filename] -> success filename inp
   15                 [] -> fromInp inp
   16                 _ -> usage
   17   where
   18         test filename inp ('t':'r':_) = success filename inp
   19         test filename inp ('f':'r':_) = success filename inp
   20         test filename inp _ = 
   21                 hPutStr stderr ("Can not read: "++filename++"\n") >>
   22                 hPutStr stderr "Give the filename of an object: " >>
   23                 fromInp inp
   24         fromInp = error "fromInp"
   25 {-OLD:
   26         fromInp [] = return ()
   27         fromInp (filename:rest) =
   28                statusFile filename >>
   29                test filename rest
   30 -}
   31 
   32 usage = hPutStr stderr "Usage: hiddenline [filename of object]\n"
   33 
   34 
   35 getDirection,getit :: (Vector -> InputCont) -> InputCont
   36 getDirection success inp =
   37         hPutStr stderr ("Give a view direction in the form of: x,y,z\n"++
   38                            "or 'quit' to stop\n") >>
   39         getit success inp
   40 
   41 getit success          [] = return ()
   42 getit success ("quit":ls) = return ()
   43 getit success      (l:ls) =
   44  case reads ("vec ["++l++"]") of
   45   [(v,_)] -> success v ls
   46   _       -> hPutStr stderr "again: " >> getit success ls
   47 
   48 
   49 process :: (Vector -> String -> String) -> String -> InputCont
   50 process f filename =
   51         getDirection 
   52                 (\ viewdir ls ->
   53                    readFile filename >>= \ cs ->
   54                    printFrom viewdir (process f filename) cs ls
   55                 )
   56         where printFrom viewdir cont cs ls =
   57                 putStr (f viewdir cs) >> cont ls