diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2019-08-07 09:32:54 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2019-08-07 09:32:54 +0200 |
commit | 1fb4b2b100d76cfa362cd021760b7cc0038cf55d (patch) | |
tree | 2443bfdda69965757d8ce335cda1a28bb7327834 /harnesses/dict_conv.py | |
parent | b134093d75235a90f09ff591137aed9dbdad6e89 (diff) | |
parent | 40f3d0030e6e98bcb02d6523e5ee48497dec49a6 (diff) |
Update upstream source from tag 'upstream/6.9.3'
Update to upstream version '6.9.3'
with Debian dir 0b54db06b48ebf22a6090f21e4dcc045a1085e11
Diffstat (limited to 'harnesses/dict_conv.py')
-rw-r--r-- | harnesses/dict_conv.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/harnesses/dict_conv.py b/harnesses/dict_conv.py new file mode 100644 index 0000000..f721293 --- /dev/null +++ b/harnesses/dict_conv.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# dict_conv.py (Python3 script) + +import sys + +ENC_UTF16_BE = 1 +ENC_UTF16_LE = 2 + +def add_char(enc, s, c): + if enc == ENC_UTF16_BE: + s += "\\x00" + + s += c + if enc == ENC_UTF16_LE: + s += "\\x00" + + return s + +def conv(enc, s): + n = len(s) + r = "" + i = 0 + while i < n: + c = s[i] + if c == '\\': + c = s[i+1] + if c == '\\' or c == '"': + r = add_char(enc, r, "\\" + c) + i += 2 + continue + else: + raise("Unknown escape {0}".format(s)) + + r = add_char(enc, r, c) + i += 1 + + return r + +def main(enc): + print("# This file was generated by dict_conv.py.") + for line in sys.stdin: + s = line.strip() + if s[0] == '#': + print(s) + continue + + if s[0] == '"' and s[-1] == '"': + s = conv(enc, s[1:-1]) + print("\"{0}\"".format(s)) + else: + raise("Invalid format {0}".format(s)) + +def usage(argv): + raise RuntimeError("Usage: python {0} utf16_be/utf16_le".format(argv[0])) + + +if __name__ == "__main__": + argv = sys.argv + argc = len(argv) + + if argc >= 2: + s = argv[1] + if s == 'utf16_be': + enc = ENC_UTF16_BE + elif s == 'utf16_le': + enc = ENC_UTF16_LE + else: + usage(argv) + else: + usage(argv) + + main(enc) |