[or-cvs] Make mdd.py marginally less kludgey
Nick Mathewson
nickm at seul.org
Thu May 13 00:09:53 UTC 2004
Update of /home/or/cvsroot/contrib
In directory moria.mit.edu:/tmp/cvs-serv11318/contrib
Modified Files:
mdd.py
Log Message:
Make mdd.py marginally less kludgey
Index: mdd.py
===================================================================
RCS file: /home/or/cvsroot/contrib/mdd.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mdd.py 12 May 2004 20:24:56 -0000 1.1
+++ mdd.py 13 May 2004 00:09:50 -0000 1.2
@@ -1,4 +1,4 @@
-#!/home/nickm/bin/python2.3
+#!/usr/bin/env python2.3
import re, sys
import textwrap
@@ -10,17 +10,25 @@
funcCalledByFile = {}
funcCalledByFunc = {}
+cpp_re = re.compile(r'//.*$')
+c_re = re.compile(r'/[*]+(?:[^*]+|[*]+[^/*])*[*]+/', re.M|re.S)
+
for fname in files:
f = open(fname, 'r')
curFunc = "???"
functionCalls.setdefault(curFunc,{})
lineno = 0
- for line in f.xreadlines():
+ body = f.read()
+ body = cpp_re.sub(" ",body)
+ body = c_re.sub(" ",body)
+ #if fname == 'dns.c': print body
+ for line in body.split("\n"):
lineno += 1
m = re.match(r'^[^\s/].*\s(\w+)\([^;]*$', line)
if m:
#print line, "->", m.group(1)
curFunc = m.group(1)
+ if curFunc[0] == '_': curFunc = curFunc[1:]
functionCalls.setdefault(curFunc,{})
funcDeclaredIn[m.group(1)] = fname
fileDeclares.setdefault(fname, {})[m.group(1)] = 1
@@ -29,6 +37,7 @@
if m:
#print line, "->", m.group(1)
curFunc = m.group(1)
+ if curFunc[0] == '_': curFunc = curFunc[1:]
functionCalls.setdefault(curFunc,{})
funcDeclaredIn[m.group(1)] = fname
fileDeclares.setdefault(fname, {})[m.group(1)] = 1
@@ -36,7 +45,10 @@
while line:
m = re.search(r'(\w+)\(', line)
if not m: break
- #print line, "->", m.group(1)
+ #print fname, line, curFunc, "->", m.group(1)
+ fn = m.group(1)
+ if fn[0] == '_':
+ fn = fn[1:]
functionCalls[curFunc][m.group(1)] = 1
#if curFunc == "???":
# print ">>!!!!! at %s:%s"%(fname,lineno)
@@ -92,7 +104,8 @@
callers = [c for c in funcCalledByFunc.get(func,{}).keys()
if c != "???"]
callers.sort()
- called = [c for c in functionCalls[func].keys() if c != "???"]
+ called = [c for c in functionCalls[func].keys() if c != "???" and
+ c in funcnames]
called.sort()
print wrap(" ".join(callers),
" Called by:")
More information about the tor-commits
mailing list