Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:44

0001 from builtins import range
0002 __author__="Aurelija"
0003 __date__ ="$2010-09-23 15.00.20$"
0004 
0005 import re
0006 
0007 declarator = '(\\*|&)?(\\w|<|,|>|$|::)+'
0008 cv_decl = '\\s*(const|volatile|noexcept)\\s*'
0009 exception = 'throw\\(((::)|\\w|\\s|,|<|>)*\\)'
0010 decl_param = '\\s((\\(%s\\))|(%s))\\s*\\((\\w|\\s|\\*|&|\\.|=|\'|\"|-|<|>|,|(::))*\\)'%(declarator, declarator)
0011 operator = '(%s|)operator\\s*(\\(\\)|\\[\\]|\\s+(new|delete)(\\s*\\[\\]|)|\\-\\>[*]{0,1}|[+\\-*/%%^&|~!=<>,]{1,2}(=|))'%(declarator)
0012 dm_init = '(:[^{]*)'
0013 functStart_re = re.compile('(\\s|~|^)((\\(%s\\))|(%s)|(%s))\\s*\\((%s|\\w|\\s|\\*|&|\\.|=|\'|\"|-|<|>|,|::)*\\)(%s)?(%s)?\\s*(%s)?\\s*{'%(declarator, declarator, operator, decl_param, cv_decl, exception,dm_init), re.MULTILINE)
0014 
0015 def filterFiles(fileList):
0016     files = []
0017 
0018     for i in range(len(fileList)):
0019         if type(fileList[0]).__name__ != 'tuple':
0020             file = fileList[i]
0021             fileLines = filterFile(fileList[i])
0022         else:
0023             file = fileList[i][0]
0024             fileLines = filterFile(fileList[i][1])
0025 
0026         files.append((file, fileLines))
0027     return files
0028 
0029 def filterFile(file):
0030 
0031     lines = ""
0032 
0033     if type(file).__name__ != 'list':
0034         lines = open(file, errors='replace').read()
0035     else:
0036         for line in file:
0037             lines += line
0038     fileLines = lines[:]
0039     prevEndPosition = 0
0040     endPosition = 0
0041     while(True):
0042         m = functStart_re.search(lines)
0043         if m != None:
0044             openBracket = 1
0045             closeBracket = 0
0046             startPosition = m.start()
0047             #print "MATCH: " + lines[m.start():m.end()]
0048             for i, character in enumerate(lines[m.end():]):
0049                 if character == "{":
0050                     openBracket += 1
0051                 elif character == "}":
0052                     closeBracket += 1
0053                     if openBracket == closeBracket :
0054                         prevEndPosition += endPosition
0055                         endPosition = m.end() + i + 1
0056                         break
0057             if openBracket != closeBracket:#if there is error in file
0058                 print("Error in file. To much open brackets. Run commentSkipper before you run functionSkipper.")
0059                 break
0060             else:
0061                 #print "LINES: \n" + lines[startPosition:endPosition] 
0062                 #print "#############################################";
0063                 lines = delLines(lines, startPosition, endPosition)
0064                 fileLines = fileLines[:prevEndPosition] + lines
0065                 lines = lines[endPosition:]
0066         else:
0067             break
0068 
0069     listOfLines = []
0070     startLine = 0
0071     for index, character in enumerate(fileLines):
0072         if character == "\n":
0073             listOfLines.append(fileLines[startLine:index+1])
0074             startLine = index + 1
0075     listOfLines.append(fileLines[startLine:])
0076     return listOfLines
0077 
0078 def delLines(string, startPosition, endPosition):
0079     i = startPosition - 1
0080     end = startPosition
0081     while(True):
0082         if i != -1 and string[i] != '\n':
0083             i -= 1
0084         else:
0085             string = string[:i+1] + (end - i - 1)*' ' + string[end:]
0086             break
0087 
0088     i = startPosition
0089     start = startPosition
0090     while(i != endPosition):
0091         if string[i] != '\n':
0092             i += 1
0093         else:
0094             string = string[:start] + (i-start)*str(" ") + string[i:]
0095             i = i+1
0096             start = i
0097     string = string[:start] + (endPosition-start)*str(" ") + string[endPosition:]
0098 
0099     return string