]> git.tdb.fi Git - libs/gl.git/blob - scripts/resgen.py
Add missing includes
[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_char(c):
16         if c=='\t':
17                 return "\\t"
18         elif c=='\n':
19                 return "\\n"
20         elif c=='"':
21                 return "\\\""
22         else:
23                 return c
24
25 out = open(sys.argv[-1], "w")
26
27 out.write("""#include <msp/datafile/builtinsource.h>
28
29 namespace Msp {
30 namespace GL {
31
32 """)
33
34 objects = {}
35 for fn in sys.argv[1:-1]:
36         in_base = os.path.split(fn)[1]
37         name = makename(in_base)+"_data"
38         objects[in_base] = name
39         out.write("const char {}[] =\n".format(name))
40         data = open(fn).read()
41         line = ""
42         for c in data:
43                 line += escape_char(c)
44                 if len(line)>=68:
45                         out.write("\t\"{}\"\n".format(line))
46                         line = ""
47         out.write("\t\"{}\";\n\n".format(line))
48
49 out_base = os.path.splitext(os.path.split(sys.argv[-1])[1])[0]
50 out.write("void init_{}(DataFile::BuiltinSource &source)\n{{\n".format(makename(out_base)))
51 for n, d in objects.items():
52         out.write("\tsource.add_object(\"{}\", {});\n".format(n, d))
53 out.write("}\n")
54
55 out.write("""
56 } // namespace GL
57 } // namespace Msp
58 """)