OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 the V8 project authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Represent a file as a C++ constant string. |
| 6 |
| 7 Usage: |
| 8 python xxd.py VAR SOURCE DEST |
| 9 """ |
| 10 |
| 11 |
| 12 import sys |
| 13 import rjsmin |
| 14 |
| 15 |
| 16 def main(): |
| 17 variable_name, input_filename, output_filename = sys.argv[1:] |
| 18 with open(input_filename) as input_file: |
| 19 input_text = input_file.read() |
| 20 input_text = rjsmin.jsmin(input_text) |
| 21 hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] |
| 22 const_declaration = 'const char %s[] = {\n%s\n};\n' % ( |
| 23 variable_name, ', '.join(hex_values)) |
| 24 with open(output_filename, 'w') as output_file: |
| 25 output_file.write(const_declaration) |
| 26 |
| 27 if __name__ == '__main__': |
| 28 sys.exit(main()) |
OLD | NEW |