]> git.tdb.fi Git - libs/gl.git/blob - scripts/resgen.py
Add a builtin module for standard shaders
[libs/gl.git] / scripts / resgen.py
1 #!/usr/bin/python
2
3 import sys
4 import os
5
6 def makename(text):
7         result = ""
8         for c in text:
9                 if c.isalnum():
10                         result += c
11                 else:
12                         result += '_'
13         return result
14
15 def escape(text):
16         result = ""
17         for c in text:
18                 if c=='\t':
19                         result += "\\t"
20                 elif c=='\n':
21                         result += "\\n"
22                 elif c=='"':
23                         result += "\\\""
24                 else:
25                         result += c
26         return result
27
28 name = makename(os.path.split(sys.argv[1])[1])
29 lines = open(sys.argv[1]).readlines()
30 out = open(sys.argv[2], "w")
31 out.write("""namespace Msp {
32 namespace GL {
33 """)
34 out.write("extern const char {}_data[] =\n".format(name))
35 for l in lines:
36         out.write("\t\"{}\"\n".format(escape(l)))
37 out.write(""";
38
39 } // namespace GL
40 } // namespace Msp
41 """)