示例#1
0
def parse_ctags(tagFile):
	tf = CTags(tagFile)
	e = TagEntry()
	results = []
	s = tf.first(e)
	while s:
		eP = {'name': e['name'], 'file': e['file'], 'pattern': e['pattern'], 'lineNumber': e['lineNumber'], 'kind': e['kind'], 'fileScope': e['fileScope']}
		results.append(eP)
		s = tf.next(e)
	return sorted(results, cmp = lambda x, y: cmp(x['file'].lower(), y['file'].lower()) if x['file'] != y['file'] else cmp(x['lineNumber'], y['lineNumber']))
示例#2
0
def parse_ctags():
    '''Returns a list of all the functions and their arguments found by ctags'''
    try:
        tf = CTags('tags')
    except:
        print "Unable to find tags file!"
        sys.exit(-1)
    entry = TagEntry()
    l = []
    if 0 == tf.first(entry):
        return []
    while True:
        l.append(parse_pattern(entry['pattern']))
        if 0 == tf.next(entry):
            break
    return l
示例#3
0
from __future__ import print_function
import ctags
from ctags import CTags, TagEntry
import sys

try:
    tagFile = CTags(b'tags')
except:
    sys.exit(1)
    
   
entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile['name'])
print(tagFile['author'])
print(tagFile['format'])
if status:
    print(entry['name'])
    print(entry['kind'])
    
if tagFile.find(entry, b'find', ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print('found')
    print(entry['lineNumber'])
    print(entry['pattern'])
    print(entry['kind'])

status = tagFile.findNext(entry)
if status:
    print(entry['lineNumber'])
示例#4
0
def update_type_map(type_map, ctags_fname):
    logger.debug("processing %s ...", ctags_fname)
    tag = CTags(ctags_fname.encode())
    tag.setSortType(ctags.TAG_SORTED)
    entry = TagEntry()

    # First traverse all entries
    status = tag.first(entry)
    while status:
        name = entry["name"].decode()
        kind = entry["kind"].decode()
        typeref = (entry[b"typeref"] or b"").decode()
        pattern = entry["pattern"].decode()

        # TODO: Check multiple declaration
        if name in type_map:
            status = tag.next(entry)
            continue

        # TODO: handle macro properly. currently, assume macros are integers.
        # Also, skip allocation.
        if kind == "macro" or "=" in pattern:
            status = tag.next(entry)
            continue

        if kind in ["func", "proc", "function", "procedure", "method"]:
            ret_type = "func"
        elif kind.startswith("enum"):
            ret_type = "enum"
        elif kind == "union":
            ret_type = "union"
        elif kind.startswith("struct"):
            ret_type = "struct"
        elif kind.startswith("class"):
            ret_type = "struct"
        elif kind == "label":
            ret_type = ret_type
        elif kind in ["label", "typedef", "member", "variable"]:
            if typeref:
                ret_type = typeref.split(":")[0]
            else:
                ret_type = pattern[:pattern.rindex(name)].rstrip()
        else:
            status = tag.next(entry)
            continue

        ret_type = sanitize(ret_type)

        if "(" in ret_type:
            ret_type = "func"

        if "*" in ret_type:
            ret_type + " *"

        type_map[name] = ret_type
        status = tag.next(entry)

    # Now check until no update exists
    while True:
        is_updated = False
        status = tag.first(entry)
        while status:
            name = entry["name"].decode()
            kind = entry["kind"].decode()
            typeref = (entry[b"typeref"] or b"").decode()
            pattern = entry["pattern"].decode()

            # No need to handle a macro as it is already replaced by a constant.
            # Also, skip allocation.
            if kind == "macro" or "=" in pattern:
                status = tag.next(entry)
                continue

            if name not in type_map:
                ret_type = "int"
            else:
                ret_type = type_map[name]
                ret_type = ret_type.split()[0]  # remove pointer for here
                while ret_type in type_map and ret_type != type_map[ret_type]:
                    ret_type = ret_type.split()[0]  # remove pointer for here
                    ret_type = type_map[ret_type]

                if ret_type not in type_map:
                    ret_type = "int"

                # use a single '*' for denoting a pointer
                if "*" not in ret_type and "*" in type_map[name]:
                    ret_type = ret_type + " *"

                if ret_type != type_map[name]:
                    type_map[name] = ret_type
                    is_updated = True

            status = tag.next(entry)

        if is_updated == False:
            break

    return None
stat, output = c.getstatusoutput("%s -f /tmp/ctags-blub -R %s" % (ctags, projectdir))
if stat != 0:
    print "Error when running ctags: %s" % output
    sys.exit(1)

try:
    tagfile = CTags("/tmp/ctags-blub")
except:
    print "Error when reading ctags file"
    sys.exit(1)

# collect all tags for a sorted tag

fileCollection = dict()
entry = TagEntry()
status = tagfile.first(entry)
fileCollection[entry['file']] = [(entry['name'], entry['kind'], entry['lineNumber'], entry['pattern'])]
while tagfile.next(entry):
    addEntry = [(entry['name'], entry['kind'], entry['lineNumber'], entry['pattern'])]
    try: 
        fileCollection[entry['file']] += addEntry
    except KeyError:
        fileCollection[entry['file']] = addEntry

es = Elasticsearch()
for file in fileCollection:
    f = open(file, "r")
    tags = [] 
    for tag in fileCollection[file]: 
        print tag
        tags += [{
示例#6
0
from __future__ import print_function

import sys

import ctags
from ctags import CTags, TagEntry

try:
    tagFile = CTags(b"tags")
except:
    sys.exit(1)

entry = TagEntry()
status = tagFile.setSortType(ctags.TAG_SORTED)
status = tagFile.first(entry)

print(tagFile["name"])
print(tagFile["author"])
print(tagFile["format"])
if status:
    print(entry["name"])
    print(entry["kind"])

if tagFile.find(entry, b"find", ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print("found")
    print(entry["lineNumber"])
    print(entry["pattern"])
    print(entry["kind"])

status = tagFile.findNext(entry)
if status:
示例#7
0
文件: ping.py 项目: rosedu/pylxr
#!/usr/bin/env python

import ctags 
from ctags import CTags, TagEntry
import sys

try:
	tagFile = CTags('tags')
except:
	print 'Error on open tags'
	sys.exit(1)
	
entry = TagEntry()

if len(sys.argv) == 2:
	if tagFile.find(entry, sys.argv[1], ctags.TAG_FULLMATCH):
		print entry['file'], entry['lineNumber']
	else:
		print 'Symbol', sys.argv[1], 'not found'
else:
	stat = tagFile.first(entry)
	while stat:
		print entry['name'], entry['file'], entry['lineNumber'], entry['kind']
		stat = tagFile.next(entry)