Repository navigation
Expand file tree
/
Copy pathopengl-api.hs
More file actions
77 lines (65 loc) · 2.63 KB
/
Copy pathopengl-api.hs
File metadata and controls
77 lines (65 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{-# Language DeriveDataTypeable, NamedFieldPuns #-}
module Main where
import Paths_opengl_api (version)
import Data.Version (showVersion)
import System.Console.CmdArgs.Implicit
import Control.Applicative ((<$>))
import Text.OpenGL.Spec
import Text.OpenGL.ExtHeader
import Text.OpenGL.GenChecks (mkChecks)
versionString :: String
versionString =
"opengl-api " ++ showVersion version ++"\n\
\Copyright (c) 2010-2011 Vo Minh Thu.\n\
\This is open source software. See the LICENSE file for conditions."
main :: IO ()
main = (>>= processCmd) . cmdArgs $
modes
[ header, checks
]
&= summary versionString
&= program "opengl-api"
data Cmd =
Header { tmFn :: String, esFn :: String, fsFn :: String }
| Checks { tmFn :: String, esFn :: String, fsFn :: String }
deriving (Show, Eq, Data, Typeable)
header :: Cmd
header = Header
{ tmFn = "gl.tm" &= typFile &= help "The type map file"
&= explicit &= name "t" &= name "type-map"
, esFn = "enumext.spec" &= typFile &= help "The enumerations file"
&= explicit &= name "e" &= name "enumerations"
, fsFn = "gl.spec" &= typFile &= help "The functions file"
&= explicit &= name "f" &= name "functions"
} &= help "Produce a C header file (normally called glext.h)."
checks :: Cmd
checks = Checks
{ tmFn = "gl.tm" &= typFile &= help "The type map file"
&= explicit &= name "t" &= name "type-map"
, esFn = "enumext.spec" &= typFile &= help "The enumerations file"
&= explicit &= name "e" &= name "enumerations"
, fsFn = "gl.spec" &= typFile &= help "The functions file"
&= explicit &= name "f" &= name "functions"
} &= help "Produce a drop-in replacement for gl.h with glGetError checks."
processCmd :: Cmd -> IO ()
processCmd (Header {tmFn,esFn,fsFn})= do
tm' <- tmLines <$> readFile tmFn
es' <- enumLines <$> readFile esFn
fs' <- funLines <$> readFile fsFn
case (tm',es',fs') of
(Left err,_,_) -> putStrLn $ tmFn ++":\n" ++ show err
(_,Left err,_) -> putStrLn $ esFn ++ ":\n" ++ show err
(_,_,Left err) -> putStrLn $ fsFn ++ ":\n" ++ show err
(Right tm,Right es,Right fs) -> putStrLn $ mkHeader tm es fs 63
processCmd (Checks {tmFn,esFn,fsFn})= do
tm' <- tmLines <$> readFile tmFn
es' <- enumLines <$> readFile esFn
fs' <- funLines <$> readFile fsFn
case (tm',es',fs') of
(Left err,_,_) -> putStrLn $ tmFn ++":\n" ++ show err
(_,Left err,_) -> putStrLn $ esFn ++ ":\n" ++ show err
(_,_,Left err) -> putStrLn $ fsFn ++ ":\n" ++ show err
(Right tm,Right es,Right fs) -> do
let (h,_) = mkChecks tm es fs
writeFile "gl-checks.h" h
-- writeFile "gl-checks.c" c -- TODO make one with macro only, and one with macro + c code