-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfilter_func_calls.py
58 lines (48 loc) · 1.44 KB
/
filter_func_calls.py
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
#!/bin/env python
import os
import sys
#
# Searches function calls like "ptratio()" with just () ending in a source file
# Also can cross reference to CMS3.h or other class header files to eliminate ROOT or custom function calls with '()' ending
#
def help():
print "python {} SOURCECODE [CLASSHEADERCODE]".format(sys.argv[0])
print "e.g. python {} ScanChain.C CMS3.h".format(sys.argv[0])
sys.exit()
fname = sys.argv[1]
f = open(fname)
lines = f.readlines()
rmchar = ".!,;=<>&\"?|*+/-:"
paran = "(){}[]"
# gather all the function calls ending with '()'
funcs = []
for line in lines:
line = line.strip()
for c in rmchar:
line = line.replace(c, " ")
if line.find("()") != -1:
ls = line.split("()")
for item in ls[:-1]:
for p in paran:
item = item.replace(p, " ")
funcs.append(item.split()[-1])
funcs = list(set(funcs))
funcs.sort()
# if header file path provided gather all the available () and cross reference and print
if len(sys.argv) > 2:
cname = sys.argv[2]
c = open(cname)
lines = c.readlines()
funcnames = []
for line in lines:
line = line.strip()
if line.find("&") != -1 and line.find("const") != -1:
funcnames.append(line.split("&")[1].split("()")[0])
funcnames = list(set(funcnames))
funcnames.sort()
for f in funcnames:
if f in funcs:
print f
else:
for f in funcs:
print f