3 # A script to convert blob from the MS spec to array of byte to use in unitary tests
5 # 00000000 c7 01 00 01 20 54 e2
6 # 00000008 c7 01 00 01 20 54 e2
7 # taken from the spec, will give:
8 # 0xc7, 0x01, 0x00, 0x01, 0x20, 0x54, 0xe2,
9 # 0xc7, 0x01, 0x00, 0x01, 0x20, 0x54, 0xe2,
12 # * the script reads the two first lines to detect the number of items per lines, so you need a blob with at least 2 lines
13 # * the script detects if items are hex values by searching for + or -
16 # $ python scripts/specBytesToCode.py < image.txt > image.c
17 # then go edit image.c and paste that in your code
22 token = l.split(' ')[0]
26 return l.find('+') == -1 and l.find('-') == -1
28 if __name__ == '__main__':
34 # parse the offset to know how many items per line we have
35 l1 = sys.stdin.readline().strip()
36 l2 = sys.stdin.readline().strip()
37 itemsPerLine = getOffset(l2) - getOffset(l1)
42 for l in [l1, l2] + sys.stdin.readlines():
43 # 00000000 c7 01 00 01 20 54 e2 cc 00 jh.kjkjhkhk
44 l = l.strip() # in case we have spaces before the offset
49 tokens = l.strip().split(' ')
52 if not t: # empty token
55 if ntokens == itemPerLine:
67 lines.append(', '.join(items))
69 print(",\n".join(lines))