aboutsummaryrefslogtreecommitdiff
path: root/tools/bin2h.py
blob: 52d4baee3e9bc5bf7861852dbb42f78640ac8070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# vim: set expandtab ts=4 sw=4 tw=100:

import sys
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-b", "--before", dest="before", action="append",
                  help="text to put before, may be specified more than once")
parser.add_option("-a", "--after", dest="after", action="append",
                  help="text to put after, may be specified more than once")
(options, args) = parser.parse_args()

if options.before and len(options.before) > 0:
    for b in options.before:
        print b

offset = 0
f = bytearray(sys.stdin.read())
for c in f:
    if offset != 0 and offset % 16 == 0:
        print ""
    print "%#04x," % c,
    offset = offset + 1
print ""

if options.after and len(options.after) > 0:
    for a in options.after:
        print a