]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - doxygen/thtml2doxy.py
doxy: support multiple ClassImp()/ClassDef()
[u/mrichter/AliRoot.git] / doxygen / thtml2doxy.py
index 1347c549ee09338ba8aa4fd557a7c1d94ea850ec..8c0e321330055fb230ce42c8f74a993c41fe4a90 100755 (executable)
@@ -480,14 +480,15 @@ def comment_classimp(filename, comments):
 
   with open(filename, 'r') as fp:
 
-    line_classimp = -1
-    line_startcond = -1
-    line_endcond = -1
-    classimp_class = None
-    classimp_indent = None
-
     for line in fp:
 
+      # Reset to nothing found
+      line_classimp = -1
+      line_startcond = -1
+      line_endcond = -1
+      classimp_class = None
+      classimp_indent = None
+
       line_num = line_num + 1
 
       mclassimp = re.search(reclassimp, line)
@@ -521,36 +522,36 @@ def comment_classimp(filename, comments):
             in_classimp_cond = False
             line_endcond = line_num
 
-  # Did we find something?
-  if line_classimp != -1:
+      # Did we find something?
+      if line_classimp != -1:
 
-    if line_startcond != -1:
-      comments.append(Comment(
-        ['\cond CLASSIMP'],
-        line_startcond, 1, line_startcond, 1,
-        classimp_indent, 'ClassImp/Def(%s)' % classimp_class,
-        append_empty=False
-      ))
-    else:
-      comments.append(PrependComment(
-        ['\cond CLASSIMP'],
-        line_classimp, 1, line_classimp, 1,
-        classimp_indent, 'ClassImp/Def(%s)' % classimp_class
-      ))
-
-    if line_endcond != -1:
-      comments.append(Comment(
-        ['\endcond'],
-        line_endcond, 1, line_endcond, 1,
-        classimp_indent, 'ClassImp/Def(%s)' % classimp_class,
-        append_empty=False
-      ))
-    else:
-      comments.append(PrependComment(
-        ['\endcond'],
-        line_classimp+1, 1, line_classimp+1, 1,
-        classimp_indent, 'ClassImp/Def(%s)' % classimp_class
-      ))
+        if line_startcond != -1:
+          comments.append(Comment(
+            ['\cond CLASSIMP'],
+            line_startcond, 1, line_startcond, 1,
+            classimp_indent, 'ClassImp/Def(%s)' % classimp_class,
+            append_empty=False
+          ))
+        else:
+          comments.append(PrependComment(
+            ['\cond CLASSIMP'],
+            line_classimp, 1, line_classimp, 1,
+            classimp_indent, 'ClassImp/Def(%s)' % classimp_class
+          ))
+
+        if line_endcond != -1:
+          comments.append(Comment(
+            ['\endcond'],
+            line_endcond, 1, line_endcond, 1,
+            classimp_indent, 'ClassImp/Def(%s)' % classimp_class,
+            append_empty=False
+          ))
+        else:
+          comments.append(PrependComment(
+            ['\endcond'],
+            line_classimp+1, 1, line_classimp+1, 1,
+            classimp_indent, 'ClassImp/Def(%s)' % classimp_class
+          ))
 
 
 ## Traverse the AST recursively starting from the current cursor.
@@ -627,8 +628,8 @@ def strip_html(s):
 #  @param comment An array containing the lines of the original comment
 def refactor_comment(comment, do_strip_html=True, infilename=None):
 
-  recomm = r'^(/{2,}|/\*)? ?(\s*.*?)\s*((/{2,})?\s*|\*/)$'
-  regarbage = r'^(?i)\s*([\s*=-_#]+|(Begin|End)_Html)\s*$'
+  recomm = r'^(/{2,}|/\*)? ?(\s*)(.*?)\s*((/{2,})?\s*|\*/)$'
+  regarbage = r'^(?i)\s*([\s*=_#-]+|(Begin|End)_Html)\s*$'
 
   # Support for LaTeX blocks spanning on multiple lines
   relatex = r'(?i)^((.*?)\s+)?(BEGIN|END)_LATEX([.,;:\s]+.*)?$'
@@ -646,6 +647,12 @@ def refactor_comment(comment, do_strip_html=True, infilename=None):
   current_macro = []
   remacro = r'(?i)^\s*(BEGIN|END)_MACRO(\((.*?)\))?\s*$'
 
+  # Minimum indent level: scale back everything
+  lowest_indent_level = None
+
+  # Indentation threshold: if too much indented, don't indent at all
+  indent_level_threshold = 15
+
   new_comment = []
   insert_blank = False
   wait_first_non_blank = True
@@ -662,7 +669,7 @@ def refactor_comment(comment, do_strip_html=True, infilename=None):
         current_macro = []
 
         # Insert image
-        new_comment.append( '![Picture from ROOT macro](%s)' % (outimg) )
+        new_comment.append( '![Picture from ROOT macro](%s)' % (os.path.basename(outimg)) )
 
         logging.debug( 'Found macro for generating image %s' % Colt(outimg).magenta() )
 
@@ -680,9 +687,20 @@ def refactor_comment(comment, do_strip_html=True, infilename=None):
 
     mcomm = re.search( recomm, line_comment )
     if mcomm:
-      new_line_comment = mcomm.group(2)
+      new_line_comment = mcomm.group(2) + mcomm.group(3)  # indent + comm
+
       mgarbage = re.search( regarbage, new_line_comment )
 
+      if mgarbage is None and not mcomm.group(3).startswith('\\') and mcomm.group(3) != '':
+        # not a special command line: count indent
+        indent_level = len( mcomm.group(2) )
+        if lowest_indent_level is None or indent_level < lowest_indent_level:
+          lowest_indent_level = indent_level
+
+        # if indentation level is too much, consider it zero
+        if indent_level > indent_level_threshold:
+          new_line_comment = mcomm.group(3)  # remove ALL indentation
+
       if new_line_comment == '' or mgarbage is not None:
         insert_blank = True
       else:
@@ -778,6 +796,23 @@ def refactor_comment(comment, do_strip_html=True, infilename=None):
     else:
       assert False, 'Comment regexp does not match'
 
+  # Fixing indentation level
+  if lowest_indent_level is not None:
+    logging.debug('Lowest indentation level found: %d' % lowest_indent_level)
+
+    new_comment_indent = []
+    reblankstart = r'^\s+'
+    for line in new_comment:
+      if re.search(reblankstart, line):
+        new_comment_indent.append( line[lowest_indent_level:] )
+      else:
+        new_comment_indent.append( line )
+
+    new_comment = new_comment_indent
+
+  else:
+    logging.debug('No indentation scaling applied')
+
   return new_comment
 
 
@@ -872,15 +907,42 @@ def rewrite_comments(fhin, fhout, comments):
     # Find current comment
     prev_comm = comm
     comm = None
+    comm_list = []
     for c in comments:
       if c.has_comment(line_num):
         comm = c
+        comm_list.append(c)
+
+    if len(comm_list) > 1:
+
+      merged = True
+
+      if len(comm_list) == 2:
+        c1,c2 = comm_list
+        if isinstance(c1, Comment) and isinstance(c2, Comment):
+          c1.lines = c1.lines + c2.lines  # list merge
+          comm = c1
+          logging.debug('Two adjacent comments merged. Result: {%s}' % Colt(comm).cyan())
+        else:
+          merged = False
+      else:
+        merged = False
+
+      if merged == False:
+        logging.warning('Too many unmergeable comments on the same line (%d), picking the last one' % len(comm_list))
+        for c in comm_list:
+          logging.warning('>> %s' % c)
+          comm = c  # considering the last one
 
     if comm:
 
       # First thing to check: are we in the same comment as before?
-      if comm is not prev_comm and isinstance(comm, Comment) and isinstance(prev_comm, Comment) \
-        and not isinstance(prev_comm, RemoveComment):
+      if comm is not prev_comm and \
+         isinstance(comm, Comment) and \
+         isinstance(prev_comm, Comment) and \
+         not isinstance(prev_comm, RemoveComment):
+
+        # We are NOT in the same comment as before, and this comment is dumpable
 
         skip_empty = dump_comment_block(prev_comm, restore_lines)
         in_comment = False
@@ -954,7 +1016,7 @@ def rewrite_comments(fhin, fhout, comments):
           in_comment = False
           restore_lines = None
 
-      elif prev_comm is None:
+      elif restore_lines is None:
 
         # Beginning of a new comment block of type Comment or PrependComment
         in_comment = True
@@ -975,7 +1037,7 @@ def rewrite_comments(fhin, fhout, comments):
           restore_lines.append( line.rstrip('\n') )
 
       else:
-        assert False, 'Unhandled parser state. line=%d comm=%s prev_comm=%s' % \
+        assert False, 'Unhandled parser state: line=%d comm={%s} prev_comm={%s}' % \
           (line_num, comm, prev_comm)
 
     else: