header :: AST -> String -> Rendered
header ast modname
 = let hdr_def    = "__" ++ (map toUpper modname) ++ "_H__"
       out_h_name = modname ++ ".h"
   in Rendered
       { path = ["include"]
       , fname = out_h_name
       , contents = runPrinter $
           do sayln' $ "/**"
              sayln' $ " * @file " ++ out_h_name
              sayln' $ " */"
              sayln' $ ""
              sayln' $ "#ifndef " ++ hdr_def
              sayln' $ "#define " ++ hdr_def
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#include <tidl.h>"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start forward declarations */"
              sayln' $ ""
              mapM_ forwardDeclaration (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End forward declarations */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start array length constants */"
              sayln' $ ""
              mapM_ arrayLengthConstant (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End array length constants */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start type definitions */"
              sayln' $ ""
              mapM_ (\x -> typeDefinition x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End type definitions */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start function prototypes */"
              sayln' $ ""
              mapM_ (\x -> functionProtos x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End function prototypes */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#endif /* " ++ hdr_def ++ " */"
              sayln' $ ""
       }
header :: AST -> String -> Rendered
header ast modname
 = let hdr_def    = "__" ++ (map toUpper modname) ++ "_H__"
       out_h_name = modname ++ ".h"
   in Rendered
       { path = ["include"]
       , fname = out_h_name
       , contents = runPrinter $
           do sayln' $ "/**"
              sayln' $ " * @file " ++ out_h_name
              sayln' $ " */"
              sayln' $ ""
              sayln' $ "#ifndef " ++ hdr_def
              sayln' $ "#define " ++ hdr_def
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#include <tidl.h>"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start forward declarations */"
              sayln' $ ""
              mapM_ forwardDeclaration (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End forward declarations */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start array length constants */"
              sayln' $ ""
              mapM_ arrayLengthConstant (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End array length constants */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start type definitions */"
              sayln' $ ""
              mapM_ (\x -> typeDefinition x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End type definitions */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start function prototypes */"
              sayln' $ ""
              mapM_ (\x -> functionProtos x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End function prototypes */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#endif /* " ++ hdr_def ++ " */"
              sayln' $ ""
       }
header ast modname
 = let hdr_def    = "__" ++ (map toUpper modname) ++ "_H__"
       out_h_name = modname ++ ".h"
   in Rendered
       { path = ["include"]
       , fname = out_h_name
       , contents = runPrinter $
           do sayln' $ "/**"
              sayln' $ " * @file " ++ out_h_name
              sayln' $ " */"
              sayln' $ ""
              sayln' $ "#ifndef " ++ hdr_def
              sayln' $ "#define " ++ hdr_def
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#include <tidl.h>"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start forward declarations */"
              sayln' $ ""
              mapM_ forwardDeclaration (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End forward declarations */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start array length constants */"
              sayln' $ ""
              mapM_ arrayLengthConstant (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End array length constants */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start type definitions */"
              sayln' $ ""
              mapM_ (\x -> typeDefinition x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End type definitions */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "/* Start function prototypes */"
              sayln' $ ""
              mapM_ (\x -> functionProtos x >> sayln' "") (ast_defs ast)
              sayln' $ ""
              sayln' $ "/* End function prototypes */"
              sayln' $ ""
              sayln' $ ""
              sayln' $ "#endif /* " ++ hdr_def ++ " */"
              sayln' $ ""
       }