This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
/
gen-skin.py
executable file
·78 lines (63 loc) · 1.64 KB
/
gen-skin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
#
# a python script used to generate the "default-skin.h' header file
# from a given skin directory
#
# usage:
# progname skin-directory-path > default-skin.h
#
import sys, os, string, re
header = """\
/* automatically generated, do not touch */
"""
footer = """\
static const FileEntry _file_entries[] =
{
"""
footer2 = """\
{ NULL, NULL, 0 }
};
"""
entries = []
def process_files( basepath, files ):
for file in files:
fp = open(basepath + "/" + file, "rb")
data = fp.read()
data_len = len(data)
data_add = 0
data_name = "_data_" + string.replace(file,".","_")
entries.append( (file, data_name, len(data)) )
print "static const unsigned char %s[%d] = {" % (data_name, data_len + data_add)
comma = " "
do_line = 0
do_comma = 0
count = 0
line = " "
for b in data:
d = ord(b)
if do_comma:
line = line + ","
do_comma = 0
if do_line:
print line
line = " "
do_line = 0
line = line + "%3d" % d
do_comma = 1
count += 1
if count == 16:
count = 0
do_line = 1
if len(line) > 0:
print line
print "};\n"
if len(sys.argv) != 2:
print "usage: progname skindirpath > default-skin.h"
else:
print header
skindir = sys.argv[1]
process_files( skindir, os.listdir(skindir) )
print footer
for e in entries:
print " { \"%s\", %s, %d }," % (e[0], e[1], e[2])
print footer2