def main():
    if len(sys.argv) != 3:
        print 'usage: %s generate_context.py tbl_file tags_file' % sys.argv[0]
        sys.exit(2)
    tbl_path = sys.argv[1]
    tags_path = sys.argv[2]

    tags = ctags.CTags(tags_path)
    entry = ctags.TagEntry()

    tbl_file = open(tbl_path, 'r')
    syscalls = []
    for line in tbl_file:
        syscall = {'num': -1, 'entry': '', 'name': '', 'context':'', 'args': []}

        match = re.search(r'^(\w+)\t+\w+\t+(\w+)\t+(\w+)', line)
        if not match:
            continue

        num = match.group(1)
        name = match.group(2)
        entrypoint = match.group(3)

        # Rename stub_* entrypoints to sys_*
        entrypoint = re.sub(r'^stub_', r'sys_', entrypoint)

        if not tags.find(entry, entrypoint, ctags.TAG_FULLMATCH | ctags.TAG_OBSERVECASE):
            continue

        syscall['num'] = int(num)
        syscall['name'] = name
        syscall['entry'] = entrypoint

        found_prototype = False
        while not found_prototype:
            if(entry['kind'] == 'prototype'):
                found_prototype = True
            elif not tags.findNext(entry):
                break

        if not found_prototype:
            continue

        args = [];
        if(entry['signature'] != '(void)'):
            strargs = entry['signature'].strip('()').split(',')
            for strarg in strargs:
                strarg = strarg.strip()
                arg = {'sig': '', 'refcount': 0, 'context': ''}
                arg['sig'] = strarg
                arg['refcount'] = strarg.count('*')
                args.append(arg)

        syscall['args'] = args

        syscalls.append(syscall)

    tbl_file.close()

    print simplejson.dumps(syscalls, indent='\t')
Beispiel #2
0
def main(tags_file, search_expression):
    # read tags file
    tags = ctags.CTags(tags_file)
    status = tags.setSortType(ctags.TAG_SORTED)

    # search
    entry = ctags.TagEntry()
    found = tags.find(entry, search_expression, ctags.TAG_PARTIALMATCH)
    if not found:
        return

    # save entries
    entries = []
    while True:
        file = entry['file']
        pattern = entry['pattern']
        entries.append({'file': file, 'pattern': pattern})
        #print entry['pattern']
        #print entry['file']
        found = tags.findNext(entry)
        if not found:
            break

    for i, entry in enumerate(entries):
        file = entry['file']
        pattern = entry['pattern']
        print("{}:{}".format(file, pattern))
Beispiel #3
0
    def query(self, query):
        entry = ctags.TagEntry()
        flags = self.build_flags()

        if self.tag_file.find(entry, query, flags):
            yield self.entry_to_Entry(entry)
            while self.tag_file.findNext(entry):
                yield self.entry_to_Entry(entry)
Beispiel #4
0
 def test_tag_entry(self):
     entry = ctags.TagEntry()
     self.ctags.setSortType(ctags.TAG_SORTED)
     self.ctags.first(entry)
     entry_info = [
         entry[_] for _ in ("file", "name", "pattern", "kind", b"language")
     ]
     self.assertEqual(
         entry_info,
         [b"../_readtags.c", b"DL_EXPORT", b"10", b"macro", b"C"])
Beispiel #5
0
    def readFromFile(self, filename, groupByFile, ignorePaths):
        self.__entries = []

        e = ctags.TagEntry()
        tf = ctags.CTags(filename)
        while tf.next(e):
            self.__addFromTagEntry(e, ignorePaths)

        if groupByFile:
            self.__entries = self.__sortByFile(self.__entries)
        else:
            self.__entries = self.__sortByScope(self.__entries, None)
        self.reset()
Beispiel #6
0
 def test_tag_find(self):
     entry = ctags.TagEntry()
     self.ctags.setSortType(ctags.TAG_SORTED)
     self.ctags.find(entry, b"find",
                     ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE)
     entry_info = [
         entry[_] for _ in ("file", "name", "pattern", "kind", b"language")
     ]
     self.assertEqual(
         entry_info,
         [
             b"../readtags.c",
             b"find",
             b"/^static tagResult find (tagFile "
             b"*const file, tagEntry *const entry,$/",
             b"function",
             b"C",
         ],
     )
Beispiel #7
0
 def _lookup_ctag(token):
     entry = ctags.TagEntry()
     if _ctags.find(entry, token, 0):
         return entry['file'], entry['kind']
     else:
         return None, None
Beispiel #8
0
 def _lookup_ctag(self, token):
     entry = ctags.TagEntry()
     if self._ctags.find(entry, token, 0):
         return entry['file'], entry['lineNumber']
     else:
         return None, None
Beispiel #9
0
 def query(self, query):
     entry = ctags.TagEntry()
     if self.tag_file.first(entry):
         yield self.entry_to_Entry(entry)
         while self.tag_file.next(entry):
             yield self.entry_to_Entry(entry)