Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import binascii | |
| 4 import sys | |
| 5 | |
| 6 if len(sys.argv)<2: | |
| 7 print "Provide input file name as argument to use the script!" | |
|
jungshik at Google
2016/05/17 00:32:01
Instead of a series of nested 'if - else', please
| |
| 8 else: | |
| 9 input_file = sys.argv[1] | |
| 10 n = input_file.find(".dat") | |
| 11 if n==-1: | |
| 12 print "Not a .dat file!" | |
| 13 else: | |
| 14 output_file = input_file[0:n] + "_dat.S" | |
| 15 | |
| 16 input = open(input_file, 'rb').read() | |
| 17 n = input.find("icudt") | |
| 18 if n==-1: | |
| 19 print "Cannot find version number in the input file!" | |
| 20 else: | |
| 21 version_number = input[n+5:n+7] | |
| 22 output = open(output_file, 'w') | |
| 23 | |
| 24 output.write(".globl icudt" + version_number + "_dat\n") | |
| 25 output.write("\t.section .note.GNU-stack,\"\",%progbits\ n") | |
| 26 output.write("\t.section .rodata\n") | |
| 27 output.write("\t.balign 16\n") | |
| 28 output.write("#ifdef U_HIDE_DATA_SYMBOL\n") | |
| 29 output.write("\t.hidden icudt" + version_number + "_dat\ n") | |
| 30 output.write("#endif\n") | |
| 31 output.write("\t.type icudt" + version_number + "_dat,%o bject\n") | |
| 32 output.write("icudt" + version_number + "_dat:\n") | |
|
jungshik at Google
2016/05/17 00:32:01
How about just using a multiline string with a sin
| |
| 33 | |
| 34 split = [binascii.hexlify(input[i:i+4]).upper().lstrip(' 0') for i in range(0, len(input), 4)] | |
| 35 | |
| 36 for i in range(len(split)): | |
| 37 if (len(split[i])==0): | |
| 38 value='0' | |
| 39 elif (len(split[i])==1): | |
| 40 if not any((c in '123456789') for c in s plit[i]): | |
| 41 value='0x0'+split[i] | |
| 42 else: | |
| 43 value=split[i] | |
| 44 elif (len(split[i])%2==1): | |
| 45 value='0x0'+split[i] | |
| 46 else: | |
| 47 value='0x'+split[i] | |
| 48 | |
| 49 if (i%32==0): | |
| 50 output.write("\n.long ") | |
| 51 else: | |
| 52 output.write(",") | |
| 53 output.write(value) | |
| 54 | |
| 55 output.write("\n") | |
| 56 output.close() | |
| 57 print "Generated " + output_file | |
| OLD | NEW |