3 # ***** BEGIN GPL LICENSE BLOCK *****
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # The Original Code is Copyright (C) 2009 Blender Foundation.
20 # All rights reserved.
22 # Contributor(s): Jörg Müller
24 # ***** END GPL LICENCE BLOCK *****
29 print("Usage: datatoc <data_file>")
32 filename = sys.argv[1]
35 fpin = open(filename, "rb");
37 print("Unable to open input <{0}>".format(sys.argv[1]))
40 size = fpin.seek(0, 2)
43 if filename[0] == ".":
44 filename = filename[1:]
46 cname = filename + ".c"
47 print("Making C file <{0}>".format(cname))
49 filename = filename.replace(".", "_")
52 fpout = open(cname, "w")
54 print("Unable to open output <{0}>".format(cname))
57 fpout.write("/* DataToC output of file <{0}> */\n\n".format(filename))
58 fpout.write("int datatoc_{0}_size= {1};\n".format(filename, size))
60 fpout.write("char datatoc_{0}[]= {{\n".format(filename))
67 fpout.write("{0:3d},".format(ord(fpin.read(1))))
69 fpout.write("\n 0};\n\n")