blob: 6b3fb8474ed616771a86fd7189549e410cc9d15d (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/env python
__author__ = "Jan Pokorny <jpokorny at redhat dot com>"
__license__ = "GPLv2"
from sys import stdin, stderr
import re
import textwrap
DEF_IDENT = '[A-Za-z_][A-Za-z0-9_]*'
DEF_HEX = '0x[0-9A-Za-z]+'
DEF_MSG = '[<][ A-Za-z0-9_]+[>]'
DEF_PATH = '[A-Za-z0-9._/]+'
RE_BT = re.compile(\
'(?P<init>^\#[0-9]+\s+)'\
'(?:(?P<hex>%(DEF_HEX)s) in )?'\
'(?P<where>%(DEF_IDENT)s(?:(?: |::)%(DEF_IDENT)s)*)'\
' (?P<args>[(](?:(?<=[( ])%(DEF_IDENT)s=(?:%(DEF_IDENT)s|%(DEF_MSG)s|%(DEF_HEX)s)(?:, )?)*[)])'\
' at (?P<path>%(DEF_PATH)s):(?P<line>[1-9][0-9]*)'
% locals())
def main():
space = None
line = '__init__'
while line:
line = stdin.readline()
found = RE_BT.search(line)
if found:
found = found.groupdict()
if not space:
space = '\n' + ' ' * len(found['init'])
args = textwrap.wrap(found['args'], subsequent_indent=space[1:])
res = found['init'] + found['where']
res += (args[0] == '()' and '()' or space + '\n'.join(args))
res += space + 'at ' + found['path'] + ':' + found['line'] + '\n'
print res
else:
space = None
print >>stderr, "bad line:", line
if __name__ == '__main__':
main()
|