mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-03 14:34:32 +00:00
tools: teach msgenc to avoid comments (#1151)
Currently the C preprocessor is used to remove comments from the text files before encoding them. However the option used (`-fpreprocessed`) is only supported by gcc – but not by clang, which breaks the macOS build. By using Python to remove comments, we can remove the use of this gcc-specific option, and fix the macOS build.
This commit is contained in:
parent
5b0f79ec6e
commit
267e20dd4c
2 changed files with 17 additions and 2 deletions
|
@ -14,6 +14,21 @@ def read_charmap(path):
|
|||
|
||||
return charmap
|
||||
|
||||
# From https://stackoverflow.com/questions/241327/remove-c-and-c-comments-using-python
|
||||
def remove_comments(text):
|
||||
def replacer(match):
|
||||
s = match.group(0)
|
||||
if s.startswith('/'):
|
||||
return " " # note: a space and not an empty string
|
||||
else:
|
||||
return s
|
||||
|
||||
pattern = re.compile(
|
||||
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||
re.DOTALL | re.MULTILINE
|
||||
)
|
||||
return re.sub(pattern, replacer, text)
|
||||
|
||||
def convert_text(text, charmap):
|
||||
def cvt_str(m):
|
||||
string = m.group(0)
|
||||
|
@ -46,6 +61,7 @@ def main():
|
|||
with open(args.input, "r") as infile:
|
||||
text = infile.read()
|
||||
|
||||
text = remove_comments(text)
|
||||
text = convert_text(text, charmap)
|
||||
|
||||
with open(args.output, "w", encoding="raw_unicode_escape") as outfile:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue