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

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

Issue 9348112: Make gen files more human-readable by using a string initializer (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | « runtime/bin/io_in.cc ('k') | runtime/vm/corelib_impl_in.cc » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2011, 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 a string literal in a C++ source file from a C++ 5 # This python script creates a string literal in a C++ source file from a C++
6 # source template and text file. 6 # source template and text file.
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
11 import time 11 import time
12 from optparse import OptionParser 12 from optparse import OptionParser
13 13
14 14
15 def makeString(input_files): 15 def makeString(input_files):
16 printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\
17 !#$%&'()*+,-./:;<=>?@[]^_`{|}~ "
16 result = ' ' 18 result = ' '
19 lineNumber = 1
17 for string_file in input_files: 20 for string_file in input_files:
18 if string_file.endswith('dart'): 21 if string_file.endswith('dart'):
19 fileHandle = open(string_file, 'rb') 22 fileHandle = open(string_file, 'rb')
20 lineCounter = 0 23 quoted = False
21 result += ' // ' + string_file + '\n ' 24 result += '\n // ----- ' + string_file + ' -----\n\n'
22 for byte in fileHandle.read(): 25 for byte in fileHandle.read():
23 result += ' %d,' % ord(byte) 26 if not quoted:
24 lineCounter += 1 27 result += ' "'
25 if lineCounter == 10: 28 quoted = True
26 result += '\n ' 29 if byte in printable:
27 lineCounter = 0 30 result += byte
28 if lineCounter != 0: 31 elif byte == '\n':
29 result += '\n ' 32 if lineNumber % 10 == 0:
30 result += ' // Terminating null character.\n 0' 33 result += '\\n" /* L%d */\n' % lineNumber
34 else:
35 result += '\\n"\n'
36 lineNumber += 1
37 quoted = False
38 elif byte == '\"':
39 result += '\\"'
40 else:
41 result += '\\x%02x' % ord(byte)
31 return result 42 return result
32 43
33 44
34 def makeFile(output_file, input_cc_file, input_files): 45 def makeFile(output_file, input_cc_file, input_files):
35 bootstrap_cc_text = open(input_cc_file).read() 46 bootstrap_cc_text = open(input_cc_file).read()
36 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}", 47 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}",
37 makeString(input_files)) 48 makeString(input_files))
38 open(output_file, 'w').write(bootstrap_cc_text) 49 open(output_file, 'w').write(bootstrap_cc_text)
39 return True 50 return True
40 51
(...skipping 29 matching lines...) Expand all
70 81
71 return 0 82 return 0
72 except Exception, inst: 83 except Exception, inst:
73 sys.stderr.write('create_string_literal.py exception\n') 84 sys.stderr.write('create_string_literal.py exception\n')
74 sys.stderr.write(str(inst)) 85 sys.stderr.write(str(inst))
75 sys.stderr.write('\n') 86 sys.stderr.write('\n')
76 return -1 87 return -1
77 88
78 if __name__ == '__main__': 89 if __name__ == '__main__':
79 sys.exit(main(sys.argv)) 90 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « runtime/bin/io_in.cc ('k') | runtime/vm/corelib_impl_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698