]> git.tdb.fi Git - libs/gl.git/blob - scripts/extgen.py
For a few lingering whitespace issues
[libs/gl.git] / scripts / extgen.py
1 #!/usr/bin/python
2
3 import sys
4
5 ext = sys.argv[1]
6
7 funcs = []
8 cur_func = None
9 for line in file("gl.spec"):
10         if line[0]=='#' or line.find(':')>=0:
11                 continue
12         elif line[0]=='\t' and cur_func:
13                 parts = line.split()
14                 if parts[0]=="category" and parts[1]==ext:
15                         funcs.append(cur_func)
16         else:
17                 paren = line.find('(')
18                 if paren>0:
19                         cur_func = line[:paren]
20
21 out = file(ext.lower()+".h", "w")
22 out.write("#ifndef MSP_GL_%s_\n"%ext.upper())
23 out.write("#define MSP_GL_%s_\n"%ext.upper())
24
25 out.write("""
26 #include "gl.h"
27 #include <GL/glext.h>
28
29 namespace Msp {
30 namespace GL {
31
32 """)
33
34 for f in funcs:
35         out.write("extern PFNGL%sPROC gl%s;\n"%(f.upper(), f))
36
37 out.write("\nvoid init_%s();\n"%ext.lower())
38
39 out.write("""
40 } // namespace GL
41 } // namespace Msp
42
43 #endif
44 """)
45
46 out = file(ext.lower()+".cpp", "w")
47 out.write("#include \"extension.h\"\n")
48 out.write("#include \"%s.h\"\n"%ext.lower())
49
50 out.write("""
51 namespace Msp {
52 namespace GL {
53
54 """)
55
56 for f in funcs:
57         out.write("PFNGL%sPROC gl%s = 0;\n"%(f.upper(), f))
58
59 out.write("\nvoid init_%s()\n{\n"%ext.lower())
60 for f in funcs:
61         out.write("\tgl%s = reinterpret_cast<PFNGL%sPROC>(get_proc_address(\"gl%s\"));\n"%(f, f.upper(), f))
62 out.write("}\n")
63
64 out.write("""
65 } // namespace GL
66 } // namespace Msp
67 """)