From 172a7636a6a18cca356fca8c591f783ee38e46da Mon Sep 17 00:00:00 2001 From: heister Date: Thu, 13 Feb 2014 02:10:35 +0000 Subject: [PATCH] add python script to reformat and rewrap doxygen comments git-svn-id: https://svn.dealii.org/trunk@32474 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/contrib/utilities/wrapcomments.py | 293 ++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100755 deal.II/contrib/utilities/wrapcomments.py diff --git a/deal.II/contrib/utilities/wrapcomments.py b/deal.II/contrib/utilities/wrapcomments.py new file mode 100755 index 0000000000..97dc9dc3a2 --- /dev/null +++ b/deal.II/contrib/utilities/wrapcomments.py @@ -0,0 +1,293 @@ +#!/usr/bin/python + +# run this script on all headers of deal.II to fix comment line wrapping for +# doxygen comments. +# Example: +# cd include +# find . -name "*h" -print | while read file;do ../contrib/utilities/wrapcomments.py $file >temp;mv temp $file;done + +from __future__ import print_function +import textwrap +import sys +import string +wrapper = textwrap.TextWrapper() + +# take an array of lines and wrap them to 78 columns and let each lines start +# with @p startwith +def wrap_block(lines, startwith): + longline = " ".join(lines) + wrapper.initial_indent = startwith + wrapper.subsequent_indent = startwith + wrapper.width = 78 + return wrapper.wrap(longline) + +# strips whitespace and leading "*" from each lines +def remove_junk(lines): + out = [] + for line in lines: + line = line.strip() + if line.startswith("*"): + line = line[1:].strip() + out.append(line) + return out + +# returns True if at least one entry in @p list is contained in @p str +def one_in(list, str): + for li in list: + if li in str: + return True + return False + +# returns True if @p str starts with one of the entries in @p list +def starts_with_one(list, str): + for li in list: + if str.startswith(li): + return True + return False + +# take a doxygen comment block "/** bla ... */" given as a list of lines and +# format it in a pretty way rewrapping lines while taking care to keep certain +# structure. +def format_block(lines, infostr=""): + if len(lines)==1 and "/*" in lines[0] and "*/" in lines[0]: + return lines + + if (not "/**" in lines[0] + or not "*/" in lines[-1]): + print("%s not a code block"%infostr, file=sys.stderr) + return lines + + for line in lines[1:-1]: + assert(not "/*" in line) + assert(not "*/" in line) + + lines[-1]=lines[-1].replace("**/","*/") + + if not lines[0].strip().startswith("/**"): + print ("%s error, ignoring code block with junk in same line before"%infostr, file=sys.stderr) + return lines + if not lines[-1].strip().endswith("*/"): + print ("%s error, ignoring code block not ending at end of line"%infostr, file=sys.stderr) + return lines + + if lines[0].strip()!="/**": + #print ("%s warning code block not starting in separate line"%infostr, file=sys.stderr) + idx = string.find(lines[0],"/**") + temp = [lines[0][0:idx+3], lines[0][idx+3:]] + temp.extend(lines[1:]) + lines = temp + if lines[-1].strip()!="*/": + #print ("%s warning code block not ending in separate line"%infostr, file=sys.stderr) + idx = string.find(lines[-1],"*/") + temp = lines[0:-1] + temp.append(lines[-1][0:idx]) + temp.append(lines[-1][idx:]) + lines = temp + + idx = string.find(lines[0],"/**") + start = lines[0][:idx]+" * " + + out = [lines[0]] + idx = 1 + endidx = len(lines)-1 + curlines = [] + + ops_startline = ["
  • ", "@param", "@returns", "@warning", "@ingroup", "@author", "@date", "@related", "@deprecated"] + + ops_separate_line = ["", "@{", "@}"] + + while idx", \ + " *
  • bla", \ + " *
  • blub", \ + " * ", \ + " */"] +assert(format_block(lineI)==lineI) + +lineI = [" /** @addtogroup Exceptions", \ + " * @{ */"] +lineO = [" /**", \ + " * @addtogroup Exceptions", \ + " * @{", \ + " */"] +assert(format_block(lineI)==lineO) + + +# now open the file and do the work + + +args=sys.argv +args.pop(0) + +if len(args)!=1: + print("Usage: wrapcomments.py infile >outfile") + exit(0) + +f = open(args[0]) +lines = f.readlines() +f.close() + +out = [] +cur = [] +inblock = False +lineidx = 0 +for line in lines: + lineidx += 1 + line = line.replace("\n","") + if not inblock and "/**" in line: + inblock = True + cur = [] + if inblock: + cur.append(line) + else: + out.append(line) + if inblock and "*/" in line: + out.extend(format_block(cur, args[0]+":%d"%lineidx)) + cur = [] + inblock = False + +assert(cur==[]) + +for line in out: + print (line) + + + + + -- 2.39.5