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

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

Issue 9407017: Revert my last change. Windows dislikes long strings... (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 !#$%&'()*+,-./:;<=>?@[]^_`{|}~ "
18 result = ' ' 16 result = ' '
19 lineNumber = 1
20 for string_file in input_files: 17 for string_file in input_files:
21 if string_file.endswith('dart'): 18 if string_file.endswith('dart'):
22 fileHandle = open(string_file, 'rb') 19 fileHandle = open(string_file, 'rb')
23 quoted = False 20 lineCounter = 0
24 result += '\n // ----- ' + string_file + ' -----\n\n' 21 result += ' // ' + string_file + '\n '
25 for byte in fileHandle.read(): 22 for byte in fileHandle.read():
26 if not quoted: 23 result += ' %d,' % ord(byte)
27 result += ' "' 24 lineCounter += 1
28 quoted = True 25 if lineCounter == 10:
29 if byte in printable: 26 result += '\n '
30 result += byte 27 lineCounter = 0
31 elif byte == '\n': 28 if lineCounter != 0:
32 if lineNumber % 10 == 0: 29 result += '\n '
33 result += '\\n" /* L%d */\n' % lineNumber 30 result += ' // Terminating null character.\n 0'
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)
42 return result 31 return result
43 32
44 33
45 def makeFile(output_file, input_cc_file, input_files): 34 def makeFile(output_file, input_cc_file, input_files):
46 bootstrap_cc_text = open(input_cc_file).read() 35 bootstrap_cc_text = open(input_cc_file).read()
47 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}", 36 bootstrap_cc_text = bootstrap_cc_text.replace("{{DART_SOURCE}}",
48 makeString(input_files)) 37 makeString(input_files))
49 open(output_file, 'w').write(bootstrap_cc_text) 38 open(output_file, 'w').write(bootstrap_cc_text)
50 return True 39 return True
51 40
(...skipping 29 matching lines...) Expand all
81 70
82 return 0 71 return 0
83 except Exception, inst: 72 except Exception, inst:
84 sys.stderr.write('create_string_literal.py exception\n') 73 sys.stderr.write('create_string_literal.py exception\n')
85 sys.stderr.write(str(inst)) 74 sys.stderr.write(str(inst))
86 sys.stderr.write('\n') 75 sys.stderr.write('\n')
87 return -1 76 return -1
88 77
89 if __name__ == '__main__': 78 if __name__ == '__main__':
90 sys.exit(main(sys.argv)) 79 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