From bce616eaf0b6ca508876ec8a87c87c4b6a93db55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andy=20Teijelo=20P=C3=A9rez?= Date: Thu, 15 Sep 2016 14:35:32 -0400 Subject: [PATCH] Check for dupes in msx2utf8, to avoid last commit's bug --- msx2utf8.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/msx2utf8.py b/msx2utf8.py index 8fee05e..90eeabd 100755 --- a/msx2utf8.py +++ b/msx2utf8.py @@ -27,10 +27,17 @@ def msxchars(): for i in range(65,96): yield (256 + i, chars[160 + i]) -charmap = {} +msx2uni = {} +uni2msx = {} for m,c in msxchars(): - charmap[m] = c + if m in msx2uni: + raise ValueError("MSX code {} is duplicated".format(m)) + msx2uni[m] = c + if c in uni2msx: + raise ValueError("Codepoint {} ({}) is duplicated" + .format(ord(c), c)) + uni2msx[c] = m if len(sys.argv) < 2: while True: @@ -44,7 +51,7 @@ if len(sys.argv) < 2: sys.stdout.write('\x01') break code = 256 + c[0] - char = charmap[code] + char = msx2uni[code] sys.stdout.write(char) if sys.argv[1] == '-l':