commit bf3747bfdda2d403344d7e007acfdad12afd5d7a
Author: Mike Swanson <mikeonthecomputer@gmail.com>
AuthorDate: Thu Jan 19 12:48:35 2017 -0800
Commit: Mike Swanson <mikeonthecomputer@gmail.com>
CommitDate: Thu Jan 19 12:48:35 2017 -0800
man/{docgen,simplecpp}: Force UTF-8 reading and writing regardless of locale
When encountering non-ASCII UTF-8 characters in source files (as
exists in Crispy Doom), the Python scripts would fail to work with
a UnicodeDecodeError if the locale was not a UTF-8 one (eg, the C
locale as encountered in chroot build environments).
Let's just use UTF-8 on both open() and replace print() statements with
sys.stdout.buffer.write(). This guarantees that all input and output is
UTF-8 regardless.
---
man/docgen | 10 +++++-----
man/simplecpp | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/man/docgen b/man/docgen
index 510c2ba2..d40e5c7b 100755
--- a/man/docgen
+++ b/man/docgen
@@ -300,7 +300,7 @@ class Parameter:
# Read list of wiki pages
def read_wikipages():
- f = open("wikipages")
+ f = open("wikipages", encoding='UTF-8')
try:
for line in f:
@@ -356,7 +356,7 @@ def process_file(file):
current_config_file = None
- f = open(file)
+ f = open(file, encoding='UTF-8')
try:
param = None
@@ -422,7 +422,7 @@ def process_files(path):
process_file(path)
def print_template(template_file, content):
- f = open(template_file)
+ f = open(template_file, encoding='UTF-8')
try:
for line in f:
@@ -432,7 +432,7 @@ def print_template(template_file, content):
print_template(filename, content)
else:
line = line.replace("@content", content)
- print(line.rstrip())
+ sys.stdout.buffer.write(line.rstrip().encode('UTF-8'))
finally:
f.close()
@@ -452,7 +452,7 @@ def wiki_output(targets, template):
read_wikipages()
for t in targets:
- print(t.wiki_output())
+ sys.stdout.buffer.write(t.wiki_output().encode('UTF-8'))
def plaintext_output(targets, template_file):
diff --git a/man/simplecpp b/man/simplecpp
index 4cb58a4c..d3590d6d 100755
--- a/man/simplecpp
+++ b/man/simplecpp
@@ -76,7 +76,7 @@ def parse_stream(stream):
raise Exception("Mismatched #if in '%s'" % stream.name)
def parse_file(filename):
- f = open(filename)
+ f = open(filename, encoding='UTF-8')
try:
parse_stream(f)