writeLibEnv :: HetcatsOpts -> FilePath -> LibEnv -> LibName -> OutType
            -> IO ()
writeLibEnv opts filePrefix lenv ln ot =
    let f = filePrefix ++ "." ++ show ot
        dg = lookupDGraph ln lenv in case ot of
      Prf -> toShATermString (ln, lookupHistory ln lenv)
             >>= writeVerbFile opts f
      XmlOut -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dGraph opts lenv ln dg
      JsonOut -> writeVerbFile opts f $ ppJson
          $ ToJson.dGraph opts lenv ln dg
      SymsXml -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dgSymbols dg
      OmdocOut -> do
          let Result ds mOmd = exportLibEnv (recurse opts) (outdir opts) ln lenv
          showDiags opts ds
          case mOmd of
               Just omd -> writeVerbFiles opts ".omdoc"
                           $ map (\ (libn, od) -> (libn, xmlOut od)) omd
               Nothing -> putIfVerbose opts 0 "could not translate to OMDoc"
      GraphOut (Dot showInternalNodeLabels) -> writeVerbFile opts f
        $ dotGraph f showInternalNodeLabels "" dg
      _ -> return ()
writeLibEnv :: HetcatsOpts -> FilePath -> LibEnv -> LibName -> OutType
            -> IO ()
writeLibEnv opts filePrefix lenv ln ot =
    let f = filePrefix ++ "." ++ show ot
        dg = lookupDGraph ln lenv in case ot of
      Prf -> toShATermString (ln, lookupHistory ln lenv)
             >>= writeVerbFile opts f
      XmlOut -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dGraph opts lenv ln dg
      JsonOut -> writeVerbFile opts f $ ppJson
          $ ToJson.dGraph opts lenv ln dg
      SymsXml -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dgSymbols dg
      OmdocOut -> do
          let Result ds mOmd = exportLibEnv (recurse opts) (outdir opts) ln lenv
          showDiags opts ds
          case mOmd of
               Just omd -> writeVerbFiles opts ".omdoc"
                           $ map (\ (libn, od) -> (libn, xmlOut od)) omd
               Nothing -> putIfVerbose opts 0 "could not translate to OMDoc"
      GraphOut (Dot showInternalNodeLabels) -> writeVerbFile opts f
        $ dotGraph f showInternalNodeLabels "" dg
      _ -> return ()
writeLibEnv opts filePrefix lenv ln ot =
    let f = filePrefix ++ "." ++ show ot
        dg = lookupDGraph ln lenv in case ot of
      Prf -> toShATermString (ln, lookupHistory ln lenv)
             >>= writeVerbFile opts f
      XmlOut -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dGraph opts lenv ln dg
      JsonOut -> writeVerbFile opts f $ ppJson
          $ ToJson.dGraph opts lenv ln dg
      SymsXml -> writeVerbFile opts f $ ppTopElement
          $ ToXml.dgSymbols dg
      OmdocOut -> do
          let Result ds mOmd = exportLibEnv (recurse opts) (outdir opts) ln lenv
          showDiags opts ds
          case mOmd of
               Just omd -> writeVerbFiles opts ".omdoc"
                           $ map (\ (libn, od) -> (libn, xmlOut od)) omd
               Nothing -> putIfVerbose opts 0 "could not translate to OMDoc"
      GraphOut (Dot showInternalNodeLabels) -> writeVerbFile opts f
        $ dotGraph f showInternalNodeLabels "" dg
      _ -> return ()