Skip to content

Commit 630e921

Browse files
committed
Add python script for removing trailing CR LF from debug logging strings (#1232)
1 parent 353e74a commit 630e921

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Created with python 3.11.4
2+
3+
# This script helps removing trailing CR LF characters from game debug log messages in the various CPP files.
4+
# Just run it.
5+
6+
import glob
7+
import os
8+
9+
10+
def modifyLine(line: str) -> str:
11+
searchWords = [
12+
"DEBUG_LOG",
13+
"DEBUG_LOG_LEVEL",
14+
"DEBUG_CRASH",
15+
"DEBUG_ASSERTLOG",
16+
"DEBUG_ASSERTCRASH",
17+
"RELEASE_CRASH",
18+
"RELEASE_CRASHLOCALIZED",
19+
"WWDEBUG_SAY",
20+
"WWDEBUG_WARNING",
21+
"WWRELEASE_SAY",
22+
"WWRELEASE_WARNING",
23+
"WWRELEASE_ERROR",
24+
"WWASSERT_PRINT",
25+
"WWDEBUG_ERROR",
26+
"SNAPSHOT_SAY",
27+
"SHATTER_DEBUG_SAY",
28+
"DBGMSG",
29+
### "REALLY_VERBOSE_LOG",
30+
"DOUBLE_DEBUG",
31+
"PERF_LOG",
32+
"CRCGEN_LOG",
33+
"STATECHANGED_LOG",
34+
"PING_LOG",
35+
"BONEPOS_LOG",
36+
]
37+
38+
SEARCH_PATTERNS = [
39+
r'\r\n"',
40+
r'\n"',
41+
]
42+
43+
for searchWord in searchWords:
44+
wordBegin = line.find(searchWord)
45+
wordEnd = wordBegin + len(searchWord)
46+
47+
if wordBegin >= 0:
48+
for searchPattern in SEARCH_PATTERNS:
49+
searchPatternLen = len(searchPattern)
50+
i = wordEnd
51+
lookEnd = len(line) - searchPatternLen
52+
53+
while i < lookEnd:
54+
pattern = line[i:i+searchPatternLen]
55+
if pattern == searchPattern:
56+
lineCopy = line[:i] + '"' + line[i+searchPatternLen:]
57+
return lineCopy
58+
i += 1
59+
60+
break
61+
62+
return line
63+
64+
65+
def main():
66+
current_dir = os.path.dirname(os.path.abspath(__file__))
67+
root_dir = os.path.join(current_dir, "..", "..")
68+
root_dir = os.path.normpath(root_dir)
69+
core_dir = os.path.join(root_dir, "Core")
70+
generals_dir = os.path.join(root_dir, "Generals")
71+
generalsmd_dir = os.path.join(root_dir, "GeneralsMD")
72+
fileNames = []
73+
fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.h'), recursive=True))
74+
fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.cpp'), recursive=True))
75+
fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.inl'), recursive=True))
76+
fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.h'), recursive=True))
77+
fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.cpp'), recursive=True))
78+
fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.inl'), recursive=True))
79+
fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.h'), recursive=True))
80+
fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.cpp'), recursive=True))
81+
fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.inl'), recursive=True))
82+
83+
for fileName in fileNames:
84+
with open(fileName, 'r', encoding="cp1252") as file:
85+
try:
86+
lines = file.readlines()
87+
except UnicodeDecodeError:
88+
continue # Not good.
89+
with open(fileName, 'w', encoding="cp1252") as file:
90+
for line in lines:
91+
line = modifyLine(line)
92+
file.write(line)
93+
94+
return
95+
96+
97+
if __name__ == "__main__":
98+
main()

0 commit comments

Comments
 (0)