aboutsummaryrefslogtreecommitdiff
path: root/scripts/maint/locatemissingdoxygen.py
blob: 797bf8176f303bd5214376d4af348645f64113bb (plain)
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
68
69
70
71
72
73
74
#!/usr/bin/python

"""
  This script parses the stderr output of doxygen and looks for undocumented
  stuff.  By default, it just counts the undocumented things per file.  But with
  the -A option, it rewrites the files to stick in /*DOCDOC*/ comments
  to highlight the undocumented stuff.
"""

import os
import re
import shutil
import sys

warning_pattern = re.compile(r'^([^:]+):(\d+): warning: (.*) is not documented')

def readDoxygenOutput(f):
    " yields (cfilename, lineno, thingname) "
    for line in f:
        m = warning_pattern.match(line)
        if m:
            yield m.groups()

warnings = {}

def buildWarnings():
    for fn, lineno, what in list(readDoxygenOutput(sys.stdin)):
        warnings.setdefault(fn, []).append( (int(lineno), what) )

def count(fn):
    if os.path.abspath(fn) not in warnings:
        print "0\t%s"%fn
    else:
        n = len(warnings[os.path.abspath(fn)])
        print "%d\t%s"%(n,fn)

def getIndentation(line):
    s = line.lstrip()
    return line[:len(line)-len(s)]

def annotate(filename):
    if os.path.abspath(filename) not in warnings:
        return
    with open(filename) as f:
        lines = f.readlines()
    w = warnings[os.path.abspath(filename)][:]
    w.sort()
    w.reverse()

    for lineno, what in w:
        lineno -= 1 # list is 0-indexed.
        if 'DOCDOC' in lines[lineno]:
            continue
        ind = getIndentation(lines[lineno])
        lines.insert(lineno, "%s/* DOCDOC %s */\n"%(ind,what))

    shutil.copy(filename, filename+".orig")
    with open(filename, 'w') as f:
        for l in lines:
            f.write(l)


if __name__ == '__main__':
    if len(sys.argv) == 1:
        print "Usage: locatemissingdoxygen.py [-A] filename... <doxygen_log"
        sys.exit(1)
    buildWarnings()
    if sys.argv[1] == '-A':
        del sys.argv[1]
        func = annotate
    else:
        func = count
    for fname in sys.argv[1:]:
        func(fname)