00013 :
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