Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: runtime/tools/create_resources.py

Issue 26969005: Output character literals rather than ints in create_resources.py (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 # 4 #
5 # This python script creates string literals in a C++ source file from a C++ 5 # This python script creates string literals in a C++ source file from a C++
6 # source template and one or more resource files. 6 # source template and one or more resource files.
7 7
8 import os 8 import os
9 import sys 9 import sys
10 from os.path import join 10 from os.path import join
(...skipping 21 matching lines...) Expand all
32 32
33 resource_url = '/%s' % resource_file_name 33 resource_url = '/%s' % resource_file_name
34 result += '// %s\n' % resource_file 34 result += '// %s\n' % resource_file
35 result += 'const char ' 35 result += 'const char '
36 resource_name = re.sub(r'(/|\.|-)', '_', resource_file_name) + '_' 36 resource_name = re.sub(r'(/|\.|-)', '_', resource_file_name) + '_'
37 result += resource_name 37 result += resource_name
38 result += '[] = {\n ' 38 result += '[] = {\n '
39 fileHandle = open(resource_file, 'rb') 39 fileHandle = open(resource_file, 'rb')
40 lineCounter = 0 40 lineCounter = 0
41 for byte in fileHandle.read(): 41 for byte in fileHandle.read():
42 result += ' %d,' % ord(byte) 42 result += r" '\x%02x'," % ord(byte)
43 lineCounter += 1 43 lineCounter += 1
44 if lineCounter == 10: 44 if lineCounter == 10:
45 result += '\n ' 45 result += '\n '
46 lineCounter = 0 46 lineCounter = 0
47 if lineCounter != 0: 47 if lineCounter != 0:
48 result += '\n ' 48 result += '\n '
49 result += ' 0\n};\n\n' 49 result += ' 0\n};\n\n'
50 resources.append( 50 resources.append(
51 (resource_url, resource_name, os.stat(resource_file).st_size) ); 51 (resource_url, resource_name, os.stat(resource_file).st_size) );
52 52
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 return 0 143 return 0
144 except Exception, inst: 144 except Exception, inst:
145 sys.stderr.write('create_resources.py exception\n') 145 sys.stderr.write('create_resources.py exception\n')
146 sys.stderr.write(str(inst)) 146 sys.stderr.write(str(inst))
147 sys.stderr.write('\n') 147 sys.stderr.write('\n')
148 return -1 148 return -1
149 149
150 if __name__ == '__main__': 150 if __name__ == '__main__':
151 sys.exit(main(sys.argv)) 151 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698