editProofs :: (Env,[String]) -> IO (Proof,String)
editProofs envh@(env@(calculus,tree),history) =
 do
 putStr "|- "
 hFlush stdout
 s <- getLine `E.catch` (\e -> if isEOFError e then return "q" else ioError e)
 let (comm,m0)  = case pCommand calculus s of
                    (x,""):_ -> (x,     "")
                    _        -> (CVoid, "No parse of command\n")
     (tree',m1) = exec comm env
     (env',msg) = ((calculus,tree'), m0 ++ m1)
     history'   = history ++ [s]
     envh'      = (env', history')
  in
   do
   putStr "\n"
   putStr msg
   putStr "\n"
   case comm of
      CAxioms file  -> do s <- readFileIf file
                          let (na@(_,a),m) = readAxioms s
                              a'    = axioms2calculus a in
                            do putStr m
                               writeAndLatexFile (file ++".rules") (prLatexAxioms na)
                               editProofs ((calculus ++ a', tree'),history')
      CLatex file   -> do writeAndLatexFile file (prLatexProof tree')
                          editProofs envh'
      CNatural file -> do let nat = proof2nat tree'
                          writeAndLatexFile file (prLatexFile (prNatProof nat))
                          editProofs envh'
      CHistory file -> do writeFile file (foldr (++++) "" (history ++ ["q"]))
                          editProofs envh'
      CChange calc' -> let (c,m) = changeCalculus calculus calc' in
                        do putStr m
                           editProofs ((c,tree'),history')
      CQuit         -> do writeFile "myhistory.txt"
                                    (foldr (++++) "" (history ++ ["q"]))
                          putStr "history written in myhistory.txt\n"
                          return (tree',"")
      CManual       -> do system "latex manual.tex >& /dev/null ; xdvi manual.dvi &"
                          editProofs envh'
      _             -> editProofs envh'

-----------------------
editProofs :: (Env,[String]) -> IO (Proof,String)
editProofs envh@(env@(calculus,tree),history) =
 do
 putStr "|- "
 hFlush stdout
 s <- getLine `E.catch` (\e -> if isEOFError e then return "q" else ioError e)
 let (comm,m0)  = case pCommand calculus s of
                    (x,""):_ -> (x,     "")
                    _        -> (CVoid, "No parse of command\n")
     (tree',m1) = exec comm env
     (env',msg) = ((calculus,tree'), m0 ++ m1)
     history'   = history ++ [s]
     envh'      = (env', history')
  in
   do
   putStr "\n"
   putStr msg
   putStr "\n"
   case comm of
      CAxioms file  -> do s <- readFileIf file
                          let (na@(_,a),m) = readAxioms s
                              a'    = axioms2calculus a in
                            do putStr m
                               writeAndLatexFile (file ++".rules") (prLatexAxioms na)
                               editProofs ((calculus ++ a', tree'),history')
      CLatex file   -> do writeAndLatexFile file (prLatexProof tree')
                          editProofs envh'
      CNatural file -> do let nat = proof2nat tree'
                          writeAndLatexFile file (prLatexFile (prNatProof nat))
                          editProofs envh'
      CHistory file -> do writeFile file (foldr (++++) "" (history ++ ["q"]))
                          editProofs envh'
      CChange calc' -> let (c,m) = changeCalculus calculus calc' in
                        do putStr m
                           editProofs ((c,tree'),history')
      CQuit         -> do writeFile "myhistory.txt"
                                    (foldr (++++) "" (history ++ ["q"]))
                          putStr "history written in myhistory.txt\n"
                          return (tree',"")
      CManual       -> do system "latex manual.tex >& /dev/null ; xdvi manual.dvi &"
                          editProofs envh'
      _             -> editProofs envh'

-----------------------
editProofs envh@(env@(calculus,tree),history) =
 do
 putStr "|- "
 hFlush stdout
 s <- getLine `E.catch` (\e -> if isEOFError e then return "q" else ioError e)
 let (comm,m0)  = case pCommand calculus s of
                    (x,""):_ -> (x,     "")
                    _        -> (CVoid, "No parse of command\n")
     (tree',m1) = exec comm env
     (env',msg) = ((calculus,tree'), m0 ++ m1)
     history'   = history ++ [s]
     envh'      = (env', history')
  in
   do
   putStr "\n"
   putStr msg
   putStr "\n"
   case comm of
      CAxioms file  -> do s <- readFileIf file
                          let (na@(_,a),m) = readAxioms s
                              a'    = axioms2calculus a in
                            do putStr m
                               writeAndLatexFile (file ++".rules") (prLatexAxioms na)
                               editProofs ((calculus ++ a', tree'),history')
      CLatex file   -> do writeAndLatexFile file (prLatexProof tree')
                          editProofs envh'
      CNatural file -> do let nat = proof2nat tree'
                          writeAndLatexFile file (prLatexFile (prNatProof nat))
                          editProofs envh'
      CHistory file -> do writeFile file (foldr (++++) "" (history ++ ["q"]))
                          editProofs envh'
      CChange calc' -> let (c,m) = changeCalculus calculus calc' in
                        do putStr m
                           editProofs ((c,tree'),history')
      CQuit         -> do writeFile "myhistory.txt"
                                    (foldr (++++) "" (history ++ ["q"]))
                          putStr "history written in myhistory.txt\n"
                          return (tree',"")
      CManual       -> do system "latex manual.tex >& /dev/null ; xdvi manual.dvi &"
                          editProofs envh'
      _             -> editProofs envh'

-----------------------