Go to the documentation of this file.00001 __author__="Aurelija"
00002 __date__ ="$2010-07-13 12.17.20$"
00003
00004 import string
00005
00006 def filterFiles(fileList):
00007 files = []
00008
00009 for file in fileList:
00010 files.append((file, filterFile(file)))
00011 return files
00012
00013 def filterFile(file):
00014
00015 lines = open(file).readlines()
00016 commentStage = False
00017
00018 for i in range(len(lines)):
00019
00020 j = 0
00021
00022 while lines[i][j] != '\n':
00023
00024 char = lines[i][j]
00025
00026 if char == '/':
00027
00028 if lines[i][j+1] == '*' and not commentStage:
00029 commentStage = True
00030 commentStartLine, commentStartColumn = i, j
00031 j += 1
00032
00033 elif not commentStage and (lines[i][j+1] == '/'):
00034 lines[i] = string.replace(lines[i], lines[i][j:],'\n', 1)
00035 break
00036
00037 elif char == '"':
00038 if not commentStage:
00039 next = string.find(lines[i][j+1:], '"')
00040 lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1)
00041
00042 elif char == '\'':
00043 if not commentStage:
00044 next = string.find(lines[i][j+1:], '\'')
00045 lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1)
00046
00047 elif char == '*':
00048 if (commentStage and (lines[i][j+1] == '/')):
00049 commentStage = False;
00050 if commentStartLine != i:
00051 lines[i] = string.replace(lines[i], lines[i][:j+2],'', 1)
00052 j = -1
00053 else:
00054 lines[i] = string.replace(lines[i], lines[i][commentStartColumn:j+2], '', 1)
00055 j = commentStartColumn - 1
00056 if j != len(lines[i]) - 1:
00057 j += 1
00058 else:
00059 j = 0
00060 break
00061 if commentStage:
00062 if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
00063 else: lines[i] = lines[i].replace(lines[i][:], '\n')
00064 return lines