#!/usr/bin/env python

import sys

singlebyte = [0] * 256
doublebyte_1st = [0] * 256
doublebyte_2nd = [0] * 256

def is_singlebyte(c):
  return singlebyte[c] == 1

def is_doublebyte(c1,c2):
  return doublebyte_1st[c1] == 1 and doublebyte_2nd[c2] == 1

def print_mb2ucs_one_char(mb, ucs):
    mblen = len(mb)
    ucslen = len(ucs)

    if mblen == 0:
        mblen = 1
        ucslen = 1
    for i in range(0, mblen):
        sys.stdout.write("\\x%02X" % ord(mb[i]))
    sys.stdout.write(" ")
    for i in range(0, ucslen):
        sys.stdout.write("<U%04X>" % ord(ucs[i]))
    sys.stdout.write("\n")

def mb2ucs_1(codeset):
  for c1 in range(0x00,0x100):
    mb = chr(c1)
    try:
      ucs = mb.decode(codeset)
    except:
      continue
    if ucs[0] != u'\ufffd':
      print_mb2ucs_one_char(mb, ucs)
      singlebyte[c1] = 1    

def mb2ucs_2(codeset):
  for c1 in range(0x80,0x100):
    if is_singlebyte(c1):
      continue
    for c2 in range(0x21,0x100):
      mb = chr(c1) + chr(c2)
      try:
        ucs = mb.decode(codeset)
      except:
        continue
      if ucs[0] != u'\ufffd':
        print_mb2ucs_one_char(mb, ucs)
        doublebyte_1st[c1] = 1
        doublebyte_2nd[c2] = 1

def mb2ucs_3(codeset):
  for c1 in range(0x80,0x100):
    if is_singlebyte(c1):
      continue
    for c2 in range(0x21,0x100):
      if is_doublebyte(c1,c2):
        continue
      for c3 in range(0x21,0x100):
        mb = chr(c1) + chr(c2) + chr(c3)
        try:
          ucs = mb.decode(codeset)
        except:
          continue
        if ucs[0] != u'\ufffd':
          print_mb2ucs_one_char(mb, ucs)

def mb2ucs(codeset):
  mb2ucs_1(codeset)
  mb2ucs_2(codeset)
  mb2ucs_3(codeset)

if len(sys.argv) != 2:
  print >> sys.stderr, "Usage: mb2ucs codeset"
  sys.exit(1)

mb2ucs(sys.argv[1])
