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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/env python
"""
# b43 firmware assembly code beautifier
#
# Copyright (C) 2008-2010 Michael Buesch <m@bues.ch>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import getopt
import sys
from libb43 import *
def usage():
print "b43 firmware assembly code beautifier"
print ""
print "Copyright (C) 2008 Michael Buesch <m@bues.ch>"
print "Licensed under the GNU/GPL version 3"
print ""
print "Usage: b43-beautifier [OPTIONS]"
print ""
print "-h|--help Print this help text"
print "-a|--asmfile [FILE] Assembly code source file"
print "-d|--defs [DIR] Directory containing the defs files"
print ""
print "The options -d and -a are essential."
print "The \"include\" directory can be used for --defs"
def parseArgs():
global opt_asmfile
global opt_defsfiles
opt_asmfile = None
opt_defsfiles = None
try:
(opts, args) = getopt.getopt(sys.argv[1:],
"ha:d:",
[ "help", "asmfile=", "defs=" ])
except getopt.GetoptError:
usage()
sys.exit(1)
for (o, v) in opts:
if o in ("-h", "--help"):
usage()
sys.exit(0)
if o in ("-a", "--asmfile"):
opt_asmfile = v
if o in ("-d", "--defs"):
opt_defsfiles = v
if not opt_asmfile:
print "Must provide --asmfile"
sys.exit(1)
if not opt_defsfiles:
print "Must provide --defs"
sys.exit(1)
def main():
parseArgs()
try:
asm = file(opt_asmfile).read()
except IOError, e:
print "Could not read asmfile %s: %s" % (e.filename, e.strerror)
return 1
try:
b = B43Beautifier(asm, opt_defsfiles)
sys.stdout.write(b.getAsm())
except B43Exception:
return 1
return 0
if __name__ == "__main__":
sys.exit(main())
|