------------------------------------------------------------------------------
-- 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 TLFrame(

>   getFrame,
>   rev_TLFrame

> ) where

> import Constants   -- globale Konstanten
> import Tools
> import TL
> import TLData
> import Char
> import Track

> rev_TLFrame =  "$Revision: 718 $"

> getFrame uc ml tl bt sc = case (ml, tl) of
>               (MST, C)      -> (c_headerST,    c_trailerST)
>               (MTT, C)      -> (c_headerTT,    c_trailerTT)
>               (MST, F)      -> (f_headerST,    f_trailerST)
>               (MTT, F)      -> (f_headerTT,    f_trailerTT)
>               (MST, Pascal) -> (pascal_header, pascal_trailer)

>   where

>   c_headerST = unlines $ [
>       "#include <stdio.h>",
>       "#include <stdlib.h>",
>       "#include <string.h>",
>       "#include <errno.h>",
>       "",
>       "#include \"options.h\"",
>       "#include \"adplib.h\"",
>       "",
>       "@C_ADDITIONAL_HEADER@",
>       "",
>       "static void *hlp;  /* help pointer */",
>       "static void *hlp2; /* help pointer */",
>       "",
>       "static tsequence *seq;",
>       "static toptions  *opts;",
>       "static char *z;",
>       "static int   n;"]

>   c_headerTT = c_headerST


>   c_trailerST = unlines $ [
>       "int main_@MODULENAME@(toptions *_opts, tsequence *_seq)",
>       "{",
>       "   opts = _opts;",
>       "   seq  = _seq;",
>       "   z    = _seq->seq - 1;",
>       "   n    = _seq->length;",
>       "",
>       "   adplib_init(opts,seq,&z,&n);",
>       "   result_prettyprint = (char *) myalloc(adp_statmem, 30*n*sizeof(char));",
>       "   @MODULEMAININIT@",
>       "   mainloop();",
>       "   @MODULEMAINFINISH@",
>       "}"]


>   c_trailerTT = c_trailerST

>   f_headerST = insertQuotes (
>    "character*70000 :: arg             \n"++
>    "character       :: z(1:70000)      \n"++
>    "integer         :: n               \n")

>   f_headerTT = insertQuotes (
>    "character*70000 :: arg             \n"++
>    "character       :: x(1:70000)      \n"++
>    "integer         :: m               \n"++
>    "character       :: y(1:70000)      \n"++
>    "integer         :: n               \n")

>   f_trailerST = insertQuotes (
>    "CALL getarg(1, arg)        \n"++
>    "n=1                        \n"++
>    "DO WHILE(arg(n:n)/=' ')    \n"++
>    "  z(n) = arg(n:n)          \n"++
>    "  n=n+1                    \n"++
>    "END DO                     \n"++
>    "n=n-1                      \n"++
>    "                           \n"++
>    "CALL mainloop()            \n")

>   f_trailerTT = insertQuotes (
>    "CALL getarg(1, arg)        \n"++
>    "m=1                        \n"++
>    "DO WHILE(arg(m:m)/=' ')    \n"++
>    "  x(m) = arg(m:m)          \n"++
>    "  m=m+1                    \n"++
>    "END DO                     \n"++
>    "m=m-1                      \n"++
>    "                           \n"++
>    "CALL getarg(2, arg)        \n"++
>    "n=1                        \n"++
>    "DO WHILE(arg(n:n)/=' ')    \n"++
>    "  y(n) = arg(n:n)          \n"++
>    "  n=n+1                    \n"++
>    "END DO                     \n"++
>    "n=n-1                      \n"++
>    "                           \n"++
>    "CALL mainloop()            \n")


>   pascal_header = 
>    "\n"

>   pascal_trailer = 
>    "\n"

> insertQuotes :: String -> String
> insertQuotes [] = []
> insertQuotes ('@':s) = (chr 34):insertQuotes s
> insertQuotes (c:s)   = c:insertQuotes s


