8 # Roughly translates THtml C++ comments to Doxygen.
12 # `thtml2doxy file1 [file2 [file3...]]`
14 # @author Dario Berzano <dario.berzano@cern.ch>
19 # **Note:** this program only has this function.
22 #reblock = r'^(\s*)//\s+(.*)\s*$'
23 reblock = r'^//\s+(.*)\s*$'
24 reignore = r'((Begin|End)_Html|^_+$)'
25 restrip = r'(?i)</?P>|</?H[0-9]>|<BR/?>'
26 refield = r'(?i)^(date|authors?):\s*(.*)$'
27 reclass = r'/?([^./]+)\.[^.]+$'
34 mclass = re.search( reclass, fn )
35 classname = mclass.group(1)
37 fnout = fn + '.doxyout'
39 with open(fn, 'r') as fp, open(fnout, 'w') as fout:
43 mblock = re.match(reblock, rawline)
45 if mblock and not endblock and not inblock:
46 # beginning of a block
47 fout.write('/// \class %s\n' % classname)
49 elif not mblock and inblock:
56 #indent = mblock.group(1)
57 #text = mblock.group(2)
59 text = mblock.group(1)
61 if re.match(reignore, text):
65 stripped = re.sub( restrip, '', text ).strip()
67 mfield = re.match(refield, stripped)
69 field = mfield.group(1).lower()
70 value = mfield.group(2)
71 fout.write( '%s/// \%s: %s\n' % (indent, field, value) )
74 # print by restoring indent and with correct comment
76 stripped = ' ' + stripped
77 fout.write( '%s///%s\n' % (indent, stripped) )
84 print '[ERROR] cannot open %s: %s' % (fn, e)
88 os.rename( fnout, fn )
90 print '[ERROR] renaming/removing: %s (aborting)' % e
95 if __name__ == '__main__':
96 sys.exit( main( sys.argv ) )