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