------------------------------------------------------------------------------
-- The ADP Compiler 
-- Copyright (C) 2001-2007 Peter Steffen, Marco Ruether, Christian Lang,
-- Georg Sauthoff
--
-- Send comments/bug reports to: P.Steffen <psteffen@techfak.uni-bielefeld.de>.
-- Updates: http://www.techfak.uni-bielefeld.de/~psteffen/
------------------------------------------------------------------------------

> module Main (

>   main

> ) where

> import System
> import Compile
> import CGI
> import LatexRecs_cgi
> import Optimize_cgi
> import Compile_cgi
> import Alggen_cgi

This is just a wrapper file, used to build
a compiler version runnable from the commandline

> main = do
>        qs <- getQueryString
>        case qs of
>             Nothing -> do
>                        args <- getArgs
>                        (_, errline) <- cmain args
>                        if errline /= -1 then exitWith (ExitFailure 1) else return ()
>                        return ()
>             Just s -> do
>                       cgiVars <- getCgiVars
>                       env     <- return $ cgiVars ++ urlDecode s
>                       res     <- case lookup "cgitype" env of
>                                   Just "LatexRecs" -> main_latexrecs_cgi env
>                                   Just "Optimize"  -> main_optimize_cgi env
>                                   Just "Compile"   -> main_compile_cgi env
>                                   Just "Alggen"    -> main_alggen_cgi env
>                                   x                -> error $ "unknown cgitype " ++ show x
>                       putStr res


> myGetEnv :: String -> IO String
> myGetEnv v = catch (getEnv v) (const (return ""))
>                       
> getQueryString :: IO (Maybe String)
> getQueryString = do
>    method <- myGetEnv "REQUEST_METHOD"
>    case method of
>       "POST" -> do len <- myGetEnv "CONTENT_LENGTH"
>                    inp <- getContents
>                    return $ Just (take (read len) inp)
>       "GET"  -> do s <- myGetEnv "QUERY_STRING"
>                    return $ Just s
>       otherwise -> return Nothing


