2 # -*- coding: utf-8 -*-
4 # ***** BEGIN GPL LICENSE BLOCK *****
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # The Original Code is Copyright (C) 2009 Blender Foundation.
21 # All rights reserved.
23 # Contributor(s): Jörg Müller
25 # ***** END GPL LICENCE BLOCK *****
30 sys.stdout.write("Usage: datatoc <data_file>\n")
33 filename = sys.argv[1]
36 fpin = open(filename, "rb");
38 sys.stdout.write("Unable to open input %s\n" % sys.argv[1])
41 fpin.seek(0, os.SEEK_END)
45 if filename[0] == ".":
46 filename = filename[1:]
48 cname = filename + ".c"
49 sys.stdout.write("Making C file <%s>\n" % cname)
51 filename = filename.split("/")[-1].split("\\")[-1]
52 filename = filename.replace(".", "_")
53 sys.stdout.write(str(size))
54 sys.stdout.write("\n")
56 fpout = open(cname, "w")
58 sys.stdout.write("Unable to open output %s\n" % cname)
61 fpout.write("/* DataToC output of file <%s> */\n\n" % filename)
62 fpout.write("int datatoc_%s_size= %d;\n" % (filename, size))
64 fpout.write("char datatoc_%s[]= {\n" % filename)
71 fpout.write("%3d," % ord(fpin.read(1)))
73 fpout.write("\n 0};\n\n")