File: search-xref

package info (click to toggle)
synopsis 0.8.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,112 kB
  • ctags: 12,996
  • sloc: cpp: 34,254; ansic: 33,620; python: 10,975; sh: 7,261; xml: 6,369; makefile: 773; asm: 445
file content (67 lines) | stat: -rwxr-xr-x 1,847 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
# Command line search interface for Synopsis XREF file
# Copyright (c) 2002 by Stephen Davies

import string, sys, cPickle

if len(sys.argv) != 4:
    print "Usage: search-xref <data file> <mode> <string>"
    print "mode is one of:"
    print " full    - search for fully scoped name,"
    print "   eg: 'Ptree::Ptree()' will only match that declaration"
    print " name    - search for name of declaration,"
    print "   eg: 'Ptree' will only match class Ptree or a constructor"
    sys.exit(0)

mode = sys.argv[2]

search = sys.argv[3]

f = open(sys.argv[1], 'rb')
data, index = cPickle.load(f)
f.close()

def dump(name):
    if not data.has_key(name): return
    print string.join(name, '::')
    target_data = data[name]
    if target_data[0]:
	print "  Defined at:"
	for file, line, scope in target_data[0]:
	    print "    %s:%s: %s"%(file,line,string.join(scope,'::'))
    if target_data[1]:
	print "  Called from:"
	for file, line, scope in target_data[1]:
	    print "    %s:%s: %s"%(file,line,string.join(scope,'::'))
    if target_data[2]:
	print "  Referenced from:"
	for file, line, scope in target_data[2]:
	    print "    %s:%s: %s"%(file,line,string.join(scope,'::'))


if mode == 'full':
    name = tuple(string.split(search,'::'))
    found = 0
    # Check for exact match
    if data.has_key(name):
	print "Found exact match:"
	dump(name)
	found = 1
    # Search for last part of name in index
    if index.has_key(name[-1]):
	matches = index[name[-1]]
	print "Found (%d) possible matches:"%(len(matches))
	for name in matches:
	    dump(name)
	found = 1
    if not found:
	print "No matches found"

elif mode == 'name':
    if index.has_key(search):
	matches = index[search]
	print "Found (%d) possible matches:"%(len(matches))
	for name in matches:
	    dump(name)
    else:
	print "No matches found"