shithub: choc

Download patch

ref: bf3747bfdda2d403344d7e007acfdad12afd5d7a
parent: eaf851e095ca15c11b26d2aa7c2589617939d2db
author: Mike Swanson <mikeonthecomputer@gmail.com>
date: Thu Jan 19 07:48:35 EST 2017

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.

--- a/man/docgen
+++ b/man/docgen
@@ -300,7 +300,7 @@
 # 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 @@
 
     current_config_file = None
 
-    f = open(file)
+    f = open(file, encoding='UTF-8')
 
     try:
         param = None
@@ -422,7 +422,7 @@
         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 @@
                 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 @@
     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):
 
--- a/man/simplecpp
+++ b/man/simplecpp
@@ -76,7 +76,7 @@
 		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)