reduce.py: several improvements (#3701)
This commit is contained in:
parent
4f508c93c4
commit
34317f86ab
|
@ -147,7 +147,7 @@ def removecomments(filedata):
|
||||||
for i in range(len(filedata)):
|
for i in range(len(filedata)):
|
||||||
line = filedata[i]
|
line = filedata[i]
|
||||||
if '//' in line:
|
if '//' in line:
|
||||||
replaceandrun('remove comment', filedata, i, line[:line.find('//')].rstrip())
|
replaceandrun('remove comment', filedata, i, line[:line.find('//')].rstrip() + '\n')
|
||||||
|
|
||||||
|
|
||||||
def checkpar(line):
|
def checkpar(line):
|
||||||
|
@ -205,7 +205,11 @@ def combinelines(filedata):
|
||||||
|
|
||||||
def removedirectives(filedata):
|
def removedirectives(filedata):
|
||||||
for i in range(len(filedata)):
|
for i in range(len(filedata)):
|
||||||
if filedata[i].lstrip().startswith('#'):
|
line = filedata[i].lstrip()
|
||||||
|
if line.startswith('#'):
|
||||||
|
# these cannot be removed on their own so skip them
|
||||||
|
if line.startswith('#if') or line.startswith('#endif') or line.startswith('#el'):
|
||||||
|
continue
|
||||||
replaceandrun('remove preprocessor directive', filedata, i, '')
|
replaceandrun('remove preprocessor directive', filedata, i, '')
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,15 +294,15 @@ writefile(ORGFILE, filedata)
|
||||||
while True:
|
while True:
|
||||||
filedata1 = list(filedata)
|
filedata1 = list(filedata)
|
||||||
|
|
||||||
print('remove comments...')
|
|
||||||
removecomments(filedata)
|
|
||||||
|
|
||||||
print('remove preprocessor directives...')
|
print('remove preprocessor directives...')
|
||||||
removedirectives(filedata)
|
removedirectives(filedata)
|
||||||
|
|
||||||
print('remove blocks...')
|
print('remove blocks...')
|
||||||
filedata = removeblocks(filedata)
|
filedata = removeblocks(filedata)
|
||||||
|
|
||||||
|
print('remove comments...')
|
||||||
|
removecomments(filedata)
|
||||||
|
|
||||||
print('combine lines..')
|
print('combine lines..')
|
||||||
combinelines(filedata)
|
combinelines(filedata)
|
||||||
|
|
||||||
|
@ -306,13 +310,8 @@ while True:
|
||||||
removeline(filedata)
|
removeline(filedata)
|
||||||
|
|
||||||
# if filedata and filedata2 are identical then stop
|
# if filedata and filedata2 are identical then stop
|
||||||
if len(filedata1) == len(filedata):
|
if filedata1 == filedata:
|
||||||
i = 0
|
|
||||||
while i < len(filedata1):
|
|
||||||
if filedata[i] != filedata1[i]:
|
|
||||||
break
|
|
||||||
i = i + 1
|
|
||||||
if i == len(filedata1):
|
|
||||||
break
|
break
|
||||||
|
|
||||||
writefile(FILE, filedata)
|
writefile(FILE, filedata)
|
||||||
|
print('DONE')
|
||||||
|
|
Loading…
Reference in New Issue