#!/usr/bin/perl

#     compose_translator -- read XKB Compose files
#     Copyright © 2005 Anton Zinoviev <anton@lml.bas.bg>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.

#     If you have not received a copy of the GNU General Public License
#     along with this program, write to the Free Software Foundation, Inc.,
#     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

use warnings 'all';
use strict;
use encoding 'utf8';
binmode STDOUT, ':bytes';

sub debug {
    if (1) {
	print STDERR "@_";
    }
}

sub warning {
    print STDERR  "WARNING: @_";
}

if ($ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
    print STDERR <<EOT;
Usage: compose_translator [--acm ACM] COMPOSE_FILE
EOT
    exit 0
}

my $acm;
if ($ARGV[0] eq '--acm') {
    shift @ARGV;
    $ARGV[0] ne "" or die "$0: --acm requires a non-empty argument\n";
    $acm = $ARGV[0];
    shift @ARGV;
}

if (! $acm) {
    die "$0: compose keys can not be used in UTF-8 mode " 
	."due to kernel limitations\n";
}

my %acmtable;
if ($acm) {
    for my $acmfile ("${acm}", "${acm}.gz", "${acm}.acm", "${acm}.acm.gz",
		     "/usr/share/consoletrans/${acm}",
		     "/usr/share/consoletrans/${acm}.gz",
		     "/usr/share/consoletrans/${acm}.acm",
		     "/usr/share/consoletrans/${acm}.acm.gz",) {
	if (-f $acmfile) {
	    $acm = $acmfile;
	    last;
	}
    }
    (-f $acm) or die "$0: $acm does not exist\n";
    if ($acm =~ /gz$/) {
	open (ACM, "zcat $acm|") or die "$0: $acm: $!\n";
    } else {
	open (ACM, $acm) or die "$0: $acm: $!\n";
    }
    while (<ACM>) {
	s/\#.*//;
	chomp;
	next unless (/[^\s]/);
	if (/^\s*0x([0-9a-fA-F]{1,2})\s+\'([^\']+)\'\s*$/) {
	    my $uni = ord ($2);
	    my $c = hex ($1);
	    $acmtable{$uni} = $c;
	} else {
	    warning "Syntax error in ACM file: $_\n";
	}
    }
    close ACM;
}

for my $i (0 .. 127) {
    $acmtable{$i} = $i;
}

my %xkbsym_table = (
    'space' => '0020',
    'exclam' => '0021',
    'quotedbl' => '0022',
    'numbersign' => '0023',
    'dollar' => '0024',
    'percent' => '0025',
    'ampersand' => '0026',
    'apostrophe' => '0027',
    'quoteright' => '0027',
    'parenleft' => '0028',
    'parenlef' => '0028', # Is this recognised by X ? (speling error)
    'parenright' => '0029',
    'asterisk' => '002a',
    'asterix' => '002a', # Is this recognised by X ? (speling error)
    'plus' => '002b',
    'comma' => '002c',
    'minus' => '002d',
    'period' => '002e',
    'slash' => '002f',
    '0' => '0030',
    '1' => '0031',
    '2' => '0032',
    '3' => '0033',
    '4' => '0034',
    '5' => '0035',
    '6' => '0036',
    '7' => '0037',
    '8' => '0038',
    '9' => '0039',
    'colon' => '003a',
    'semicolon' => '003b',
    'less' => '003c',
    'equal' => '003d',
    'greater' => '003e',
    'question' => '003f',
    'at' => '0040',
    'A' => '0041',
    'B' => '0042',
    'C' => '0043',
    'D' => '0044',
    'E' => '0045',
    'F' => '0046',
    'G' => '0047',
    'H' => '0048',
    'I' => '0049',
    'J' => '004a',
    'K' => '004b',
    'L' => '004c',
    'M' => '004d',
    'N' => '004e',
    'O' => '004f',
    'P' => '0050',
    'Q' => '0051',
    'R' => '0052',
    'S' => '0053',
    'T' => '0054',
    'U' => '0055',
    'V' => '0056',
    'W' => '0057',
    'X' => '0058',
    'Y' => '0059',
    'Z' => '005a',
    'bracketleft' => '005b',
    'backslash' => '005c',
    'backlash' => '005c',   # Is this recognised by X ? (speling error)
    'bracketright' => '005d',
    'circumflex' => '005e',
    'asciicircum' => '005e',
    'underscore' => '005f',
    'grave' => '0060',
    'quoteleft' => '0060',
    'a' => '0061',
    'b' => '0062',
    'c' => '0063',
    'd' => '0064',
    'e' => '0065',
    'f' => '0066',
    'g' => '0067',
    'h' => '0068',
    'i' => '0069',
    'j' => '006a',
    'k' => '006b',
    'l' => '006c',
    'm' => '006d',
    'n' => '006e',
    'o' => '006f',
    'p' => '0070',
    'q' => '0071',
    'r' => '0072',
    's' => '0073',
    't' => '0074',
    'u' => '0075',
    'v' => '0076',
    'w' => '0077',
    'x' => '0078',
    'y' => '0079',
    'z' => '007a',
    'braceleft' => '007b',
    'pipe' => '007c', # Is this recognised by X ?
    'bar' => '007c',
    'braceright' => '007d',
    'asciitilde' => '007e',
    'nobreakspace' => '00a0',
    'exclamdown' => '00a1',
    'cent' => '00a2',
    'sterling' => '00a3',
    'currency' => '00a4',
    'yen' => '00a5',
    'brokenbar' => '00a6',
    'section' => '00a7',
    'diaeresis' => '00a8',
    'copyright' => '00a9',
    'ordfeminine' => '00aa',
    'guillemotleft' => '00ab',
    'notsign' => '00ac',
    'hyphen' => '00ad',
    'registered' => '00ae',
    'macron' => '00af',
    'overbar' => '00af',
    'degree' => '00b0',
    'plusminus' => '00b1',
    'twosuperior' => '00b2',
    'threesuperior' => '00b3',
    'acute' => '0027', # APOSTROPHE instead of ACUTE ACCENT
    'mu' => '00b5',
    'paragraph' => '00b6',
    'periodcentered' => '00b7',
    'cedilla' => '00b8',
    'onesuperior' => '00b9',
    'masculine' => '00ba',
    'guillemotright' => '00bb',
    'onequarter' => '00bc',
    'onehalf' => '00bd',
    'threequarters' => '00be',
    'questiondown' => '00bf',
    'Agrave' => '00c0',
    'Aacute' => '00c1',
    'Acircumflex' => '00c2',
    'Atilde' => '00c3',
    'Adiaeresis' => '00c4',
    'Aring' => '00c5',
    'AE' => '00c6',
    'Ccedilla' => '00c7',
    'Egrave' => '00c8',
    'Eacute' => '00c9',
    'Ecircumflex' => '00ca',
    'Ediaeresis' => '00cb',
    'Igrave' => '00cc',
    'Iacute' => '00cd',
    'Icircumflex' => '00ce',
    'Idiaeresis' => '00cf',
    'ETH' => '00d0',
    'Eth' => '00d0',
    'Ntilde' => '00d1',
    'Ograve' => '00d2',
    'Oacute' => '00d3',
    'Ocircumflex' => '00d4',
    'Otilde' => '00d5',
    'Odiaeresis' => '00d6',
    'multiply' => '00d7',
    'Ooblique' => '00d8',
    'Oslash' => '00d8',
    'Ugrave' => '00d9',
    'Uacute' => '00da',
    'Ucircumflex' => '00db',
    'Udiaeresis' => '00dc',
    'Yacute' => '00dd',
    'THORN' => '00de',
    'Thorn' => '00de',
    'ssharp' => '00df',
    'agrave' => '00e0',
    'aacute' => '00e1',
    'acircumflex' => '00e2',
    'atilde' => '00e3',
    'adiaeresis' => '00e4',
    'aring' => '00e5',
    'ae' => '00e6',
    'ccedilla' => '00e7',
    'egrave' => '00e8',
    'eacute' => '00e9',
    'ecircumflex' => '00ea',
    'ediaeresis' => '00eb',
    'igrave' => '00ec',
    'iacute' => '00ed',
    'icircumflex' => '00ee',
    'idiaeresis' => '00ef',
    'eth' => '00f0',
    'ntilde' => '00f1',
    'ograve' => '00f2',
    'oacute' => '00f3',
    'ocircumflex' => '00f4',
    'otilde' => '00f5',
    'odiaeresis' => '00f6',
    'division' => '00f7',
    'oslash' => '00f8',
    'ooblique' => '00f8',
    'ugrave' => '00f9',
    'uacute' => '00fa',
    'ucircumflex' => '00fb',
    'udiaeresis' => '00fc',
    'yacute' => '00fd',
    'thorn' => '00fe',
    'ydiaeresis' => '00ff',
    'Amacron' => '0100',
    'amacron' => '0101',
    'Abreve' => '0102',
    'abreve' => '0103',
    'Aogonek' => '0104',
    'aogonek' => '0105',
    'Cacute' => '0106',
    'cacute' => '0107',
    'Ccircumflex' => '0108',
    'ccircumflex' => '0109',
    'Cabovedot' => '010a',
    'cabovedot' => '010b',
    'Ccaron' => '010c',
    'ccaron' => '010d',
    'Dcaron' => '010e',
    'dcaron' => '010f',
    'Dstroke' => '0110',
    'dstroke' => '0111',
    'Emacron' => '0112',
    'emacron' => '0113',
    'Eabovedot' => '0116',
    'eabovedot' => '0117',
    'Eogonek' => '0118',
    'eogonek' => '0119',
    'Ecaron' => '011a',
    'ecaron' => '011b',
    'Gcircumflex' => '011c',
    'gcircumflex' => '011d',
    'Gbreve' => '011e',
    'gbreve' => '011f',
    'Gabovedot' => '0120',
    'gabovedot' => '0121',
    'Gcedilla' => '0122',
    'gcedilla' => '0123',
    'Hcircumflex' => '0124',
    'hcircumflex' => '0125',
    'Hstroke' => '0126',
    'hstroke' => '0127',
    'Itilde' => '0128',
    'itilde' => '0129',
    'Imacron' => '012a',
    'imacron' => '012b',
    'Ibreve' => '012c',
    'ibreve' => '012d',
    'Iogonek' => '012e',
    'iogonek' => '012f',
    'Iabovedot' => '0130',
    'idotless' => '0131',
    'Jcircumflex' => '0134',
    'jcircumflex' => '0135',
    'Kcedilla' => '0136',
    'kcedilla' => '0137',
    'kra' => '0138',
    'Lacute' => '0139',
    'lacute' => '013a',
    'Lcedilla' => '013b',
    'lcedilla' => '013c',
    'Lcaron' => '013d',
    'lcaron' => '013e',
    'Lstroke' => '0141',
    'lstroke' => '0142',
    'Nacute' => '0143',
    'nacute' => '0144',
    'Ncedilla' => '0145',
    'ncedilla' => '0146',
    'Ncaron' => '0147',
    'ncaron' => '0148',
    'ENG' => '014a',
    'eng' => '014b',
    'Omacron' => '014c',
    'omacron' => '014d',
    'Odoubleacute' => '0150',
    'odoubleacute' => '0151',
    'OE' => '0152',
    'oe' => '0153',
    'Racute' => '0154',
    'racute' => '0155',
    'Rcedilla' => '0156',
    'rcedilla' => '0157',
    'Rcaron' => '0158',
    'rcaron' => '0159',
    'Sacute' => '015a',
    'sacute' => '015b',
    'Scircumflex' => '015c',
    'scircumflex' => '015d',
    'Scedilla' => '015e',
    'scedilla' => '015f',
    'Scaron' => '0160',
    'scaron' => '0161',
    'Tcedilla' => '0162',
    'tcedilla' => '0163',
    'Tcaron' => '0164',
    'tcaron' => '0165',
    'Tslash' => '0166',
    'tslash' => '0167',
    'Utilde' => '0168',
    'utilde' => '0169',
    'Umacron' => '016a',
    'umacron' => '016b',
    'Ubreve' => '016c',
    'ubreve' => '016d',
    'Uring' => '016e',
    'uring' => '016f',
    'Udoubleacute' => '0170',
    'udoubleacute' => '0171',
    'Uogonek' => '0172',
    'uogonek' => '0173',
    'Wcircumflex' => '0174',
    'wcircumflex' => '0175',
    'Ycircumflex' => '0176',
    'ycircumflex' => '0177',
    'Ydiaeresis' => '0178',
    'Zacute' => '0179',
    'zacute' => '017a',
    'Zabovedot' => '017b',
    'zabovedot' => '017c',
    'Zcaron' => '017d',
    'zcaron' => '017e',
    'SCHWA' => '018f',
    'Schwa' => '018f', # Is this recognised by X ?
    'function' => '0192',
    'Obarred' => '019f',
    'Ohorn' => '01a0', # Is this recognised by X ?
    'ohorn' => '01a1', # Is this recognised by X ?
    'Uhorn' => '01af',
    'uhorn' => '01b0',
    'Zstroke' => '01b5',
    'zstroke' => '01b6',
    'Ocaron' => '01d1',
    'ocaron' => '01d2',
    'Gcaron' => '01e6', # Is this recognised by X ?
    'gcaron' => '01e7', # Is this recognised by X ?
    'schwa' => '0259', # Is this recognised by X ?
    'obarred' => '0275',
    'caron' => '02c7',
    'breve' => '02d8',
    'abovedot' => '02d9',
    'ogonek' => '02db',
    'doubleacute' => '02dd',
    'Greek_accentdieresis' => '0385',
    'Greek_ALPHAaccent' => '0386',
    'Greek_EPSILONaccent' => '0388',
    'Greek_ETAaccent' => '0389',
    'Greek_IOTAaccent' => '038a',
    'Greek_OMICRONaccent' => '038c',
    'Greek_UPSILONaccent' => '038e',
    'Greek_OMEGAaccent' => '038f',
    'Greek_iotaaccentdieresis' => '0390',
    'Greek_ALPHA' => '0391',
    'Greek_BETA' => '0392',
    'Greek_GAMMA' => '0393',
    'Greek_DELTA' => '0394',
    'Greek_EPSILON' => '0395',
    'Greek_ZETA' => '0396',
    'Greek_ETA' => '0397',
    'Greek_THETA' => '0398',
    'Greek_IOTA' => '0399',
    'Greek_KAPPA' => '039a',
    'Greek_LAMBDA' => '039b',
    'Greek_LAMDA' => '039b',   # Is this recognised by X ? (speling error)
    'Greek_MU' => '039c',
    'Greek_NU' => '039d',
    'Greek_XI' => '039e',
    'Greek_OMICRON' => '039f',
    'Greek_PI' => '03a0',
    'Greek_RHO' => '03a1',
    'Greek_SIGMA' => '03a3',
    'Greek_TAU' => '03a4',
    'Greek_UPSILON' => '03a5',
    'Greek_PHI' => '03a6',
    'Greek_CHI' => '03a7',
    'Greek_PSI' => '03a8',
    'Greek_OMEGA' => '03a9',
    'Greek_IOTAdiaeresis' => '03aa',
    'Greek_UPSILONdieresis' => '03ab',
    'Greek_alphaaccent' => '03ac',
    'Greek_epsilonaccent' => '03ad',
    'Greek_etaaccent' => '03ae',
    'Greek_iotaaccent' => '03af',
    'Greek_upsilonaccentdieresis' => '03b0',
    'Greek_alpha' => '03b1',
    'Greek_beta' => '03b2',
    'Greek_gamma' => '03b3',
    'Greek_delta' => '03b4',
    'Greek_epsilon' => '03b5',
    'Greek_zeta' => '03b6',
    'Greek_eta' => '03b7',
    'Greek_theta' => '03b8',
    'Greek_iota' => '03b9',
    'Greek_kappa' => '03ba',
    'Greek_lambda' => '03bb',
    'Greek_lamda' => '03bb', # Is this recognised by X ? (speling error)
    'Greek_mu' => '03bc',
    'Greek_nu' => '03bd',
    'Greek_xi' => '03be',
    'Greek_omicron' => '03bf',
    'Greek_pi' => '03c0',
    'Greek_rho' => '03c1',
    'Greek_finalsmallsigma' => '03c2',
    'Greek_sigma' => '03c3',
    'Greek_tau' => '03c4',
    'Greek_upsilon' => '03c5',
    'Greek_phi' => '03c6',
    'Greek_chi' => '03c7',
    'Greek_psi' => '03c8',
    'Greek_omega' => '03c9',
    'Greek_iotadieresis' => '03ca',
    'Greek_upsilondieresis' => '03cb',
    'Greek_omicronaccent' => '03cc',
    'Greek_upsilonaccent' => '03cd',
    'Greek_omegaaccent' => '03ce',
    'Cyrillic_IO' => '0401',
    'Serbian_DJE' => '0402',
    'Macedonia_GJE' => '0403',
    'Ukrainian_IE' => '0404',
    'Macedonia_DSE' => '0405',
    'Ukrainian_I' => '0406',
    'Ukrainian_YI' => '0407',
    'Cyrillic_JE' => '0408',
    'Cyrillic_LJE' => '0409',
    'Cyrillic_NJE' => '040a',
    'Serbian_TSHE' => '040b',
    'Macedonia_KJE' => '040c',
    'Byelorussian_SHORTU' => '040e',
    'Cyrillic_DZHE' => '040f',
    'Cyrillic_A' => '0410',
    'Cyrillic_BE' => '0411',
    'Cyrillic_VE' => '0412',
    'Cyrillic_GHE' => '0413',
    'Cyrillic_DE' => '0414',
    'Cyrillic_IE' => '0415',
    'Cyrillic_ZHE' => '0416',
    'Cyrillic_ZH' => '0416',
    'Cyrillic_ZE' => '0417',
    'Cyrillic_I' => '0418',
    'Cyrillic_SHORTI' => '0419',
    'Cyrillic_KA' => '041a',
    'Cyrillic_EL' => '041b',
    'Cyrillic_EM' => '041c',
    'Cyrillic_EN' => '041d',
    'Cyrillic_N' => '041d',
    'Cyrillic_O' => '041e',
    'Cyrillic_PE' => '041f',
    'Cyrillic_ER' => '0420',
    'Cyrillic_ES' => '0421',
    'Cyrillic_TE' => '0422',
    'Cyrillic_U' => '0423',
    'Cyrillic_EF' => '0424',
    'Cyrillic_F' => '0424',
    'Cyrillic_HA' => '0425',
    'Cyrillic_TSE' => '0426',
    'Cyrillic_CHE' => '0427',
    'Cyrillic_SHA' => '0428',
    'Cyrillic_SHCHA' => '0429',
    'Cyrillic_HARDSIGN' => '042a',
    'Cyrillic_YERU' => '042b',
    'Cyrillic_UI' => '042b',
    'Cyrillic_SOFTSIGN' => '042c',
    'Cyrillic_E' => '042d',
    'Cyrillic_YU' => '042e',
    'Cyrillic_YA' => '042f',
    'Cyrillic_a' => '0430',
    'Cyrillic_be' => '0431',
    'Cyrillic_ve' => '0432',
    'Cyrillic_ghe' => '0433',
    'Cyrillic_de' => '0434',
    'Cyrillic_ie' => '0435',
    'Cyrillic_zhe' => '0436',
    'Cyrillic_zh' => '0436',
    'Cyrillic_ze' => '0437',
    'Cyrillic_i' => '0438',
    'Cyrillic_shorti' => '0439',
    'Cyrillic_ka' => '043a',
    'Cyrillic_el' => '043b',
    'Cyrillic_em' => '043c',
    'Cyrillic_en' => '043d',
    'Cyrillic_n' => '043d',
    'Cyrillic_o' => '043e',
    'Cyrillic_pe' => '043f',
    'Cyrillic_er' => '0440',
    'Cyrillic_es' => '0441',
    'Cyrillic_te' => '0442',
    'Cyrillic_u' => '0443',
    'Cyrillic_ef' => '0444',
    'Cyrillic_f' => '0444',
    'Cyrillic_ha' => '0445',
    'Cyrillic_tse' => '0446',
    'Cyrillic_che' => '0447',
    'Cyrillic_sha' => '0448',
    'Cyrillic_shcha' => '0449',
    'Cyrillic_hardsign' => '044a',
    'Cyrillic_yeru' => '044b',
    'Cyrillic_ui' => '044b',
    'Cyrillic_softsign' => '044c',
    'Cyrillic_e' => '044d',
    'Cyrillic_yu' => '044e',
    'Cyrillic_ya' => '044f',
    'Cyrillic_io' => '0451',
    'Serbian_dje' => '0452',
    'Macedonia_gje' => '0453',
    'Ukrainian_ie' => '0454',
    'Macedonia_dse' => '0455',
    'Ukrainian_i' => '0456',
    'Ukrainian_yi' => '0457',
    'Cyrillic_je' => '0458',
    'Cyrillic_lje' => '0459',
    'Cyrillic_nje' => '045a',
    'Serbian_tshe' => '045b',
    'Macedonia_kje' => '045c',
    'Byelorussian_shortu' => '045e',
    'Cyrillic_dzhe' => '045f',
    'Ukrainian_GHE_WITH_UPTURN' => '0490', # Is this recognised by X ?
    'Ukrainian_ghe_with_upturn' => '0491', # Is this recognised by X ?
    'Cyrillic_GHE_bar' => '0492', # Is this recognised by X ?
    'Cyrillic_ghe_bar' => '0493', # Is this recognised by X ?
    'Cyrillic_ZHE_descender' => '0496',
    'Cyrillic_zhe_descender' => '0497',
    'Cyrillic_KA_descender' => '049a', # Is this recognised by X ?
    'Cyrillic_ka_descender' => '049b', # Is this recognised by X ?
    'Cyrillic_KA_vertstroke' => '049c', # Is this recognised by X ?
    'Cyrillic_ka_vertstroke' => '049d', # Is this recognised by X ?
    'Cyrillic_EN_descender' => '04a2', # Is this recognised by X ?
    'Cyrillic_en_descender' => '04a3', # Is this recognised by X ?
    'Cyrillic_U_straight' => '04ae', # Is this recognised by X ?
    'Cyrillic_u_straight' => '04af', # Is this recognised by X ?
    'Cyrillic_U_straight_bar' => '04b0', # Is this recognised by X ?
    'Cyrillic_u_straight_bar' => '04b1', # Is this recognised by X ?
    'Cyrillic_HA_descender' => '04b2', # Is this recognised by X ?
    'Cyrillic_ha_descender' => '04b3', # Is this recognised by X ?
    'Cyrillic_CHE_descender' => '04b6',
    'Cyrillic_che_descender' => '04b7',
    'Cyrillic_CHE_vertstroke' => '04b8', # Is this recognised by X ?
    'Cyrillic_che_vertstroke' => '04b9', # Is this recognised by X ?
    'Cyrillic_SHHA' => '04ba', # Is this recognised by X ?
    'Cyrillic_shha' => '04bb', # Is this recognised by X ?
    'Cyrillic_SCHWA' => '04d8', # Is this recognised by X ?
    'Cyrillic_schwa' => '04d9', # Is this recognised by X ?
    'Cyrillic_I_macron' => '04e2',
    'Cyrillic_i_macron' => '04e3',
    'Cyrillic_O_bar' => '04e8', # Is this recognised by X ?
    'Cyrillic_o_bar' => '04e9', # Is this recognised by X ?
    'Cyrillic_U_macron' => '04ee',
    'Cyrillic_u_macron' => '04ef',
    'Armenian_AYB' => '0531',
    'Armenian_BEN' => '0532',
    'Armenian_GIM' => '0533',
    'Armenian_DA' => '0534',
    'Armenian_YECH' => '0535',
    'Armenian_ZA' => '0536',
    'Armenian_E' => '0537',
    'Armenian_AT' => '0538',
    'Armenian_TO' => '0539',
    'Armenian_ZHE' => '053a',
    'Armenian_INI' => '053b',
    'Armenian_LYUN' => '053c',
    'Armenian_KHE' => '053d',
    'Armenian_TSA' => '053e',
    'Armenian_KEN' => '053f',
    'Armenian_HO' => '0540',
    'Armenian_DZA' => '0541',
    'Armenian_GHAT' => '0542',
    'Armenian_TCHE' => '0543',
    'Armenian_MEN' => '0544',
    'Armenian_HI' => '0545',
    'Armenian_NU' => '0546',
    'Armenian_SHA' => '0547',
    'Armenian_VO' => '0548',
    'Armenian_CHA' => '0549',
    'Armenian_PE' => '054a',
    'Armenian_JE' => '054b',
    'Armenian_RA' => '054c',
    'Armenian_SE' => '054d',
    'Armenian_VEV' => '054e',
    'Armenian_TYUN' => '054f',
    'Armenian_RE' => '0550',
    'Armenian_TSO' => '0551',
    'Armenian_VYUN' => '0552',
    'Armenian_PYUR' => '0553',
    'Armenian_KE' => '0554',
    'Armenian_O' => '0555',
    'Armenian_FE' => '0556',
    'Armenian_apostrophe' => '055a',
    'Armenian_accent' => '055b',
    'Armenian_shesht' => '055b',
    'Armenian_amanak' => '055c',
    'Armenian_exclam' => '055c',
    'Armenian_but' => '055d',
    'Armenian_separation_mark' => '055d',
    'Armenian_paruyk' => '055e',
    'Armenian_question' => '055e',
    'Armenian_ayb' => '0561',
    'Armenian_ben' => '0562',
    'Armenian_gim' => '0563',
    'Armenian_da' => '0564',
    'Armenian_yech' => '0565',
    'Armenian_za' => '0566',
    'Armenian_e' => '0567',
    'Armenian_at' => '0568',
    'Armenian_to' => '0569',
    'Armenian_zhe' => '056a',
    'Armenian_ini' => '056b',
    'Armenian_lyun' => '056c',
    'Armenian_khe' => '056d',
    'Armenian_tsa' => '056e',
    'Armenian_ken' => '056f',
    'Armenian_ho' => '0570',
    'Armenian_dza' => '0571',
    'Armenian_ghat' => '0572',
    'Armenian_tche' => '0573',
    'Armenian_men' => '0574',
    'Armenian_hi' => '0575',
    'Armenian_nu' => '0576',
    'Armenian_sha' => '0577',
    'Armenian_vo' => '0578',
    'Armenian_cha' => '0579',
    'Armenian_pe' => '057a',
    'Armenian_je' => '057b',
    'Armenian_ra' => '057c',
    'Armenian_se' => '057d',
    'Armenian_vev' => '057e',
    'Armenian_tyun' => '057f',
    'Armenian_re' => '0580',
    'Armenian_tso' => '0581',
    'Armenian_vyun' => '0582',
    'Armenian_pyur' => '0583',
    'Armenian_ke' => '0584',
    'Armenian_o' => '0585',
    'Armenian_fe' => '0586',
    'Armenian_ligature_ew' => '0587',
    'Armenian_full_stop' => '0589',
    'Armenian_verjaket' => '0589',
    'Armenian_hyphen' => '058a',
    'Armenian_yentamna' => '058a',
    'hebrew_aleph' => '05d0',
    'hebrew_bet' => '05d1',
    'hebrew_gimel' => '05d2',
    'hebrew_dalet' => '05d3',
    'hebrew_he' => '05d4',
    'hebrew_waw' => '05d5',
    'hebrew_zain' => '05d6',
    'hebrew_chet' => '05d7',
    'hebrew_tet' => '05d8',
    'hebrew_yod' => '05d9',
    'hebrew_finalkaph' => '05da',
    'hebrew_kaph' => '05db',
    'hebrew_lamed' => '05dc',
    'hebrew_finalmem' => '05dd',
    'hebrew_mem' => '05de',
    'hebrew_finalnun' => '05df',
    'hebrew_nun' => '05e0',
    'hebrew_samech' => '05e1',
    'hebrew_ayin' => '05e2',
    'hebrew_finalpe' => '05e3',
    'hebrew_pe' => '05e4',
    'hebrew_finalzade' => '05e5',
    'hebrew_zade' => '05e6',
    'hebrew_qoph' => '05e7',
    'hebrew_resh' => '05e8',
    'hebrew_shin' => '05e9',
    'hebrew_taw' => '05ea',
    'Arabic_comma' => '060c',
    'Arabic_semicolon' => '061b',
    'Arabic_question_mark' => '061f',
    'Arabic_hamza' => '0621',
    'Arabic_maddaonalef' => '0622',
    'Arabic_hamzaonalef' => '0623',
    'Arabic_hamzaonwaw' => '0624',
    'Arabic_hamzaunderalef' => '0625',
    'Arabic_hamzaonyeh' => '0626',
    'Arabic_alef' => '0627',
    'Arabic_beh' => '0628',
    'Arabic_tehmarbuta' => '0629',
    'Arabic_teh' => '062a',
    'Arabic_theh' => '062b',
    'Arabic_jeem' => '062c',
    'Arabic_hah' => '062d',
    'Arabic_khah' => '062e',
    'Arabic_dal' => '062f',
    'Arabic_thal' => '0630',
    'Arabic_ra' => '0631',
    'Arabic_zain' => '0632',
    'Arabic_seen' => '0633',
    'Arabic_sheen' => '0634',
    'Arabic_sad' => '0635',
    'Arabic_dad' => '0636',
    'Arabic_tah' => '0637',
    'Arabic_zah' => '0638',
    'Arabic_ain' => '0639',
    'Arabic_ghain' => '063a',
    'Arabic_tatweel' => '0640',
    'Arabic_feh' => '0641',
    'Arabic_qaf' => '0642',
    'Arabic_kaf' => '0643',
    'Arabic_lam' => '0644',
    'Arabic_meem' => '0645',
    'Arabic_noon' => '0646',
    'Arabic_ha' => '0647',
    'Arabic_heh' => '0647', # Is this recognised by X ?
    'Arabic_waw' => '0648',
    'Arabic_alefmaksura' => '0649',
    'Arabic_yeh' => '064a',
    'Arabic_fathatan' => '064b',
    'Arabic_dammatan' => '064c',
    'Arabic_kasratan' => '064d',
    'Arabic_fatha' => '064e',
    'Arabic_damma' => '064f',
    'Arabic_kasra' => '0650',
    'Arabic_shadda' => '0651',
    'Arabic_sukun' => '0652',
    'Arabic_madda_above' => '0653', # Is this recognised by X ?
    'Arabic_hamza_above' => '0654', # Is this recognised by X ?
    'Arabic_hamza_below' => '0655', # Is this recognised by X ?
    'Arabic_0' => '0660',
    'Arabic_1' => '0661',
    'Arabic_2' => '0662',
    'Arabic_3' => '0663',
    'Arabic_4' => '0664',
    'Arabic_5' => '0665',
    'Arabic_6' => '0666',
    'Arabic_7' => '0667',
    'Arabic_8' => '0668',
    'Arabic_9' => '0669',
    'Arabic_percent' => '066a',
    'Arabic_superscript_alef' => '0670', # Is this recognised by X ?
    'Arabic_tteh' => '0679',
    'Arabic_peh' => '067e',
    'Arabic_tcheh' => '0686',
    'Arabic_ddal' => '0688',
    'Arabic_rreh' => '0691',
    'Arabic_jeh' => '0698',
    'Arabic_veh' => '06a4',
    'Arabic_keheh' => '06a9',
    'Arabic_gaf' => '06af',
    'Arabic_noon_ghunna' => '06ba',
    'Arabic_heh_doachashmee' => '06be',
    'Arabic_heh_goal' => '06c1',
    'Arabic_farsi_yeh' => '06cc',
    'Farsi_yeh' => '06cc',
    'Arabic_yeh_baree' => '06d2',
    'Arabic_fullstop' => '06d4',
    'Farsi_0' => '06f0',
    'Farsi_1' => '06f1',
    'Farsi_2' => '06f2',
    'Farsi_3' => '06f3',
    'Farsi_4' => '06f4',
    'Farsi_5' => '06f5',
    'Farsi_6' => '06f6',
    'Farsi_7' => '06f7',
    'Farsi_8' => '06f8',
    'Farsi_9' => '06f9',
    'Thai_kokai' => '0e01',
    'Thai_khokhai' => '0e02',
    'Thai_khokhuat' => '0e03',
    'Thai_khokhwai' => '0e04',
    'Thai_khokhon' => '0e05',
    'Thai_khorakhang' => '0e06',
    'Thai_ngongu' => '0e07',
    'Thai_chochan' => '0e08',
    'Thai_choching' => '0e09',
    'Thai_chochang' => '0e0a',
    'Thai_soso' => '0e0b',
    'Thai_chochoe' => '0e0c',
    'Thai_yoying' => '0e0d',
    'Thai_dochada' => '0e0e',
    'Thai_topatak' => '0e0f',
    'Thai_thothan' => '0e10',
    'Thai_thonangmontho' => '0e11',
    'Thai_thophuthao' => '0e12',
    'Thai_nonen' => '0e13',
    'Thai_dodek' => '0e14',
    'Thai_totao' => '0e15',
    'Thai_thothung' => '0e16',
    'Thai_thothahan' => '0e17',
    'Thai_thothong' => '0e18',
    'Thai_nonu' => '0e19',
    'Thai_bobaimai' => '0e1a',
    'Thai_popla' => '0e1b',
    'Thai_phophung' => '0e1c',
    'Thai_fofa' => '0e1d',
    'Thai_phophan' => '0e1e',
    'Thai_fofan' => '0e1f',
    'Thai_phosamphao' => '0e20',
    'Thai_moma' => '0e21',
    'Thai_yoyak' => '0e22',
    'Thai_rorua' => '0e23',
    'Thai_ru' => '0e24',
    'Thai_loling' => '0e25',
    'Thai_lu' => '0e26',
    'Thai_wowaen' => '0e27',
    'Thai_sosala' => '0e28',
    'Thai_sorusi' => '0e29',
    'Thai_sosua' => '0e2a',
    'Thai_hohip' => '0e2b',
    'Thai_lochula' => '0e2c',
    'Thai_oang' => '0e2d',
    'Thai_honokhuk' => '0e2e',
    'Thai_paiyannoi' => '0e2f',
    'Thai_saraa' => '0e30',
    'Thai_maihanakat' => '0e31',
    'Thai_saraaa' => '0e32',
    'Thai_saraam' => '0e33',
    'Thai_sarai' => '0e34',
    'Thai_saraii' => '0e35',
    'Thai_saraue' => '0e36',
    'Thai_sarauee' => '0e37',
    'Thai_sarau' => '0e38',
    'Thai_sarauu' => '0e39',
    'Thai_phinthu' => '0e3a',
    'Thai_baht' => '0e3f',
    'Thai_sarae' => '0e40',
    'Thai_saraae' => '0e41',
    'Thai_sarao' => '0e42',
    'Thai_saraaimaimuan' => '0e43',
    'Thai_saraaimaimalai' => '0e44',
    'Thai_lakkhangyao' => '0e45',
    'Thai_maiyamok' => '0e46',
    'Thai_maitaikhu' => '0e47',
    'Thai_maiek' => '0e48',
    'Thai_maitho' => '0e49',
    'Thai_maitri' => '0e4a',
    'Thai_maichattawa' => '0e4b',
    'Thai_thanthakhat' => '0e4c',
    'Thai_nikhahit' => '0e4d',
    'Thai_leksun' => '0e50',
    'Thai_leknung' => '0e51',
    'Thai_leksong' => '0e52',
    'Thai_leksam' => '0e53',
    'Thai_leksi' => '0e54',
    'Thai_lekha' => '0e55',
    'Thai_lekhok' => '0e56',
    'Thai_lekchet' => '0e57',
    'Thai_lekpaet' => '0e58',
    'Thai_lekkao' => '0e59',
    'Georgian_an' => '10d0',
    'Georgian_ban' => '10d1',
    'Georgian_gan' => '10d2',
    'Georgian_don' => '10d3',
    'Georgian_en' => '10d4',
    'Georgian_vin' => '10d5',
    'Georgian_zen' => '10d6',
    'Georgian_tan' => '10d7',
    'Georgian_in' => '10d8',
    'Georgian_kan' => '10d9',
    'Georgian_las' => '10da',
    'Georgian_man' => '10db',
    'Georgian_nar' => '10dc',
    'Georgian_on' => '10dd',
    'Georgian_par' => '10de',
    'Georgian_zhar' => '10df',
    'Georgian_rae' => '10e0',
    'Georgian_san' => '10e1',
    'Georgian_tar' => '10e2',
    'Georgian_un' => '10e3',
    'Georgian_phar' => '10e4',
    'Georgian_khar' => '10e5',
    'Georgian_ghan' => '10e6',
    'Georgian_qar' => '10e7',
    'Georgian_shin' => '10e8',
    'Georgian_chin' => '10e9',
    'Georgian_can' => '10ea',
    'Georgian_jil' => '10eb',
    'Georgian_cil' => '10ec',
    'Georgian_char' => '10ed',
    'Georgian_xan' => '10ee',
    'Georgian_jhan' => '10ef',
    'Georgian_hae' => '10f0',
    'Georgian_he' => '10f1',
    'Georgian_hie' => '10f2',
    'Georgian_we' => '10f3',
    'Georgian_har' => '10f4',
    'Georgian_hoe' => '10f5',
    'Georgian_fi' => '10f6',
    'Hangul_J_Kiyeog' => '11a8',
    'Hangul_J_SsangKiyeog' => '11a9',
    'Hangul_J_KiyeogSios' => '11aa',
    'Hangul_J_Nieun' => '11ab',
    'Hangul_J_NieunJieuj' => '11ac',
    'Hangul_J_NieunHieuh' => '11ad',
    'Hangul_J_Dikeud' => '11ae',
    'Hangul_J_Rieul' => '11af',
    'Hangul_J_RieulKiyeog' => '11b0',
    'Hangul_J_RieulMieum' => '11b1',
    'Hangul_J_RieulPieub' => '11b2',
    'Hangul_J_RieulSios' => '11b3',
    'Hangul_J_RieulTieut' => '11b4',
    'Hangul_J_RieulPhieuf' => '11b5',
    'Hangul_J_RieulHieuh' => '11b6',
    'Hangul_J_Mieum' => '11b7',
    'Hangul_J_Pieub' => '11b8',
    'Hangul_J_PieubSios' => '11b9',
    'Hangul_J_Sios' => '11ba',
    'Hangul_J_SsangSios' => '11bb',
    'Hangul_J_Ieung' => '11bc',
    'Hangul_J_Jieuj' => '11bd',
    'Hangul_J_Cieuc' => '11be',
    'Hangul_J_Khieuq' => '11bf',
    'Hangul_J_Tieut' => '11c0',
    'Hangul_J_Phieuf' => '11c1',
    'Hangul_J_Hieuh' => '11c2',
    'Hangul_J_PanSios' => '11eb',
    'Hangul_J_KkogjiDalrinIeung' => '11f0',
    'Hangul_J_YeorinHieuh' => '11f9',
    'Babovedot' => '1e02', # Is this recognised by X ?
    'babovedot' => '1e03', # Is this recognised by X ?
    'Dabovedot' => '1e0a', # Is this recognised by X ?
    'dabovedot' => '1e0b', # Is this recognised by X ?
    'Fabovedot' => '1e1e', # Is this recognised by X ?
    'fabovedot' => '1e1f', # Is this recognised by X ?
    'Lbelowdot' => '1e36',
    'lbelowdot' => '1e37',
    'Mabovedot' => '1e40', # Is this recognised by X ?
    'mabovedot' => '1e41', # Is this recognised by X ?
    'Pabovedot' => '1e56', # Is this recognised by X ?
    'pabovedot' => '1e57', # Is this recognised by X ?
    'Sabovedot' => '1e60', # Is this recognised by X ?
    'sabovedot' => '1e61', # Is this recognised by X ?
    'Tabovedot' => '1e6a', # Is this recognised by X ?
    'tabovedot' => '1e6b', # Is this recognised by X ?
    'Wgrave' => '1e80',
    'wgrave' => '1e81',
    'Wacute' => '1e82',
    'wacute' => '1e83',
    'Wdiaeresis' => '1e84',
    'wdiaeresis' => '1e85',
    'Xabovedot' => '1e8a',
    'xabovedot' => '1e8b',
    'Abelowdot' => '1ea0',
    'abelowdot' => '1ea1',
    'Ahook' => '1ea2',
    'ahook' => '1ea3',
    'Acircumflexacute' => '1ea4',
    'acircumflexacute' => '1ea5',
    'Acircumflexgrave' => '1ea6',
    'acircumflexgrave' => '1ea7',
    'Acircumflexhook' => '1ea8',
    'acircumflexhook' => '1ea9',
    'Acircumflextilde' => '1eaa',
    'acircumflextilde' => '1eab',
    'Acircumflexbelowdot' => '1eac',
    'acircumflexbelowdot' => '1ead',
    'Abreveacute' => '1eae',
    'abreveacute' => '1eaf',
    'Abrevegrave' => '1eb0',
    'abrevegrave' => '1eb1',
    'Abrevehook' => '1eb2',
    'abrevehook' => '1eb3',
    'Abrevetilde' => '1eb4',
    'abrevetilde' => '1eb5',
    'Abrevebelowdot' => '1eb6',
    'abrevebelowdot' => '1eb7',
    'Ebelowdot' => '1eb8',
    'ebelowdot' => '1eb9',
    'Ehook' => '1eba',
    'ehook' => '1ebb',
    'Etilde' => '1ebc',
    'etilde' => '1ebd',
    'Ecircumflexacute' => '1ebe',
    'ecircumflexacute' => '1ebf',
    'Ecircumflexgrave' => '1ec0',
    'ecircumflexgrave' => '1ec1',
    'Ecircumflexhook' => '1ec2',
    'ecircumflexhook' => '1ec3',
    'Ecircumflextilde' => '1ec4',
    'ecircumflextilde' => '1ec5',
    'Ecircumflexbelowdot' => '1ec6',
    'ecircumflexbelowdot' => '1ec7',
    'Ihook' => '1ec8',
    'ihook' => '1ec9',
    'Ibelowdot' => '1eca',
    'ibelowdot' => '1ecb',
    'Obelowdot' => '1ecc',
    'obelowdot' => '1ecd',
    'Ohook' => '1ece',
    'ohook' => '1ecf',
    'Ocircumflexacute' => '1ed0',
    'ocircumflexacute' => '1ed1',
    'Ocircumflexgrave' => '1ed2',
    'ocircumflexgrave' => '1ed3',
    'Ocircumflexhook' => '1ed4',
    'ocircumflexhook' => '1ed5',
    'Ocircumflextilde' => '1ed6',
    'ocircumflextilde' => '1ed7',
    'Ocircumflexbelowdot' => '1ed8',
    'ocircumflexbelowdot' => '1ed9',
    'Ohornacute' => '1eda',
    'ohornacute' => '1edb',
    'Ohorngrave' => '1edc',
    'ohorngrave' => '1edd',
    'Ohornhook' => '1ede',
    'ohornhook' => '1edf',
    'Ohorntilde' => '1ee0',
    'ohorntilde' => '1ee1',
    'Ohornbelowdot' => '1ee2',
    'ohornbelowdot' => '1ee3',
    'Ubelowdot' => '1ee4',
    'ubelowdot' => '1ee5',
    'Uhook' => '1ee6',
    'uhook' => '1ee7',
    'Uhornacute' => '1ee8',
    'uhornacute' => '1ee9',
    'Uhorngrave' => '1eea',
    'uhorngrave' => '1eeb',
    'Uhornhook' => '1eec',
    'uhornhook' => '1eed',
    'Uhorntilde' => '1eee',
    'uhorntilde' => '1eef',
    'Uhornbelowdot' => '1ef0',
    'uhornbelowdot' => '1ef1',
    'Ygrave' => '1ef2',
    'ygrave' => '1ef3',
    'Ybelowdot' => '1ef4',
    'ybelowdot' => '1ef5',
    'Yhook' => '1ef6',
    'yhook' => '1ef7',
    'Ytilde' => '1ef8',
    'ytilde' => '1ef9',
    'enspace' => '2002',
    'emspace' => '2003',
    'em3space' => '2004',
    'em4space' => '2005',
    'digitspace' => '2007',
    'punctspace' => '2008',
    'thinspace' => '2009',
    'hairspace' => '200a',
    'figdash' => '2012',
    'endash' => '2013',
    'emdash' => '2014',
    'Greek_horizbar' => '2015',
    'hebrew_doublelowline' => '2017',
    'leftsinglequotemark' => '2018',
    'rightsinglequotemark' => '2019',
    'singlelowquotemark' => '201a',
    'leftdoublequotemark' => '201c',
    'rightdoublequotemark' => '201d',
    'doublelowquotemark' => '201e',
    'dagger' => '2020',
    'doubledagger' => '2021',
    'enfilledcircbullet' => '2022',
    'doubbaselinedot' => '2025',
    'ellipsis' => '2026',
    'minutes' => '2032',
    'seconds' => '2033',
    'caret' => '2038',
    'guilsinglleft' => '2039',
    'guilsinglright' => '203a',
    'overline' => '203e',
    'zerosuperior' => '2070',
    'foursuperior' => '2074',
    'fivesuperior' => '2075',
    'sixsuperior' => '2076',
    'sevensuperior' => '2077',
    'eightsuperior' => '2078',
    'ninesuperior' => '2079',
    'zerosubscript' => '2080',
    'onesubscript' => '2081',
    'twosubscript' => '2082',
    'threesubscript' => '2083',
    'foursubscript' => '2084',
    'fivesubscript' => '2085',
    'sixsubscript' => '2086',
    'sevensubscript' => '2087',
    'eightsubscript' => '2088',
    'ninesubscript' => '2089',
    'EcuSign' => '20a0',
    'ColonSign' => '20a1',
    'CruzeiroSign' => '20a2',
    'FFrancSign' => '20a3',
    'LiraSign' => '20a4',
    'MillSign' => '20a5',
    'NairaSign' => '20a6',
    'PesetaSign' => '20a7',
    'RupeeSign' => '20a8',
    'WonSign' => '20a9',
    'Korean_Won' => '20a9',
    'NewSheqelSign' => '20aa',
    'DongSign' => '20ab', # Is this recognised by X ?
    'EuroSign' => '20ac',
    'Euro' => '20ac',
    'careof' => '2105',
    'numerosign' => '2116',
    'phonographcopyright' => '2117',
    'prescription' => '211e',
    'trademark' => '2122',
    'onethird' => '2153',
    'twothirds' => '2154',
    'onefifth' => '2155',
    'twofifths' => '2156',
    'threefifths' => '2157',
    'fourfifths' => '2158',
    'onesixth' => '2159',
    'fivesixths' => '215a',
    'oneeighth' => '215b',
    'threeeighths' => '215c',
    'fiveeighths' => '215d',
    'seveneighths' => '215e',
    'leftarrow' => '2190',
    'uparrow' => '2191',
    'rightarrow' => '2192',
    'downarrow' => '2193',
    'implies' => '21d2',
    'ifonlyif' => '21d4',
    'partialderivative' => '2202',
    'partdifferential' => '2202',
    'emptyset' => '2205',
    'nabla' => '2207',
    'elementof' => '2208',
    'notelementof' => '2209',
    'containsas' => '220B',
    'jot' => '2218',
    'radical' => '221a',
    'squareroot' => '221a',
    'cuberoot' => '221b',
    'fourthroot' => '221c',
    'variation' => '221d',
    'infinity' => '221e',
    'logicaland' => '2227',
    'upcaret' => '2227',
    'downcaret' => '2228',
    'logicalor' => '2228',
    'intersection' => '2229',
    'upshoe' => '2229',
    'downshoe' => '222a',
    'union' => '222a',
    'integral' => '222b',
    'dintegral' => '222c',
    'tintegral' => '222d',
    'therefore' => '2234',
    'because' => '2235',
    'approximate' => '223c',
    'similarequal' => '2243',
    'notapproxeq' => '2247',
    'approxeq' => '2248',
    'notidentical' => '2262',
    'notequal' => '2260',
    'identical' => '2261',
    'stricteq' => '2263',
    'lessthanequal' => '2264',
    'greaterthanequal' => '2265',
    'includedin' => '2282',
    'leftshoe' => '2282',
    'includes' => '2283',
    'rightshoe' => '2283',
    'lefttack' => '22a2',
    'righttack' => '22a3',
    'uptack' => '22a4',
    'downtack' => '22a5',
    'upstile' => '2308',
    'downstile' => '230a',
    'telephonerecorder' => '2315',
    'topintegral' => '2320',
    'botintegral' => '2321',
    'leftanglebracket' => '2329',
    'rightanglebracket' => '232a',
    'quad' => '2395',
    'topleftparens' => '239b',
    'botleftparens' => '239d',
    'toprightparens' => '239e',
    'botrightparens' => '23a0',
    'topleftsqbracket' => '23a1',
    'botleftsqbracket' => '23a3',
    'toprightsqbracket' => '23a4',
    'botrightsqbracket' => '23a6',
    'leftmiddlecurlybrace' => '23a8',
    'rightmiddlecurlybrace' => '23ac',
    'leftradical' => '23b7',
    'horizlinescan1' => '23ba',
    'horizlinescan3' => '23bb',
    'horizlinescan7' => '23bc',
    'horizlinescan9' => '23bd',
    'ht' => '2409',
    'lf' => '240a',
    'vt' => '240b',
    'ff' => '240c',
    'cr' => '240d',
    'nl' => '2424',
    'horizconnector' => '2500',
    'horizlinescan5' => '2500',
    'vertbar' => '2502',
    'vertconnector' => '2502',
    'topleftradical' => '250c',
    'upleftcorner' => '250c',
    'uprightcorner' => '2510',
    'lowleftcorner' => '2514',
    'lowrightcorner' => '2518',
    'leftt' => '251c',
    'rightt' => '2524',
    'topt' => '252c',
    'bott' => '2534',
    'crossinglines' => '253c',
    'checkerboard' => '2592',
    'enfilledsqbullet' => '25aa',
    'enopensquarebullet' => '25ab',
    'filledrectbullet' => '25ac',
    'openrectbullet' => '25ad',
    'emfilledrect' => '25ae',
    'emopenrectangle' => '25af',
    'filledtribulletup' => '25b2',
    'opentribulletup' => '25b3',
    'filledrighttribullet' => '25b6',
    'rightopentriangle' => '25b7',
    'filledtribulletdown' => '25bc',
    'opentribulletdown' => '25bd',
    'filledlefttribullet' => '25c0',
    'leftopentriangle' => '25c1',
    'soliddiamond' => '25c6',
    'circle' => '25cb',
    'emopencircle' => '25cb',
    'emfilledcircle' => '25cf',
    'enopencircbullet' => '25e6',
    'openstar' => '2606',
    'telephone' => '260e',
    'signaturemark' => '2613',
    'leftpointer' => '261c',
    'rightpointer' => '261e',
    'femalesymbol' => '2640',
    'malesymbol' => '2642',
    'club' => '2663',
    'heart' => '2665',
    'diamond' => '2666',
    'musicalflat' => '266d',
    'musicalsharp' => '266f',
    'checkmark' => '2713',
    'ballotcross' => '2717',
    'latincross' => '271d',
    'maltesecross' => '2720',
    'braille_dots_1' => '2801',
    'braille_dots_2' => '2802',
    'braille_dots_12' => '2803',
    'braille_dots_3' => '2804',
    'braille_dots_13' => '2805',
    'braille_dots_23' => '2806',
    'braille_dots_123' => '2807',
    'braille_dots_4' => '2808',
    'braille_dots_14' => '2809',
    'braille_dots_24' => '280a',
    'braille_dots_124' => '280b',
    'braille_dots_34' => '280c',
    'braille_dots_134' => '280d',
    'braille_dots_234' => '280e',
    'braille_dots_1234' => '280f',
    'braille_dots_5' => '2810',
    'braille_dots_15' => '2811',
    'braille_dots_25' => '2812',
    'braille_dots_125' => '2813',
    'braille_dots_35' => '2814',
    'braille_dots_135' => '2815',
    'braille_dots_235' => '2816',
    'braille_dots_1235' => '2817',
    'braille_dots_45' => '2818',
    'braille_dots_145' => '2819',
    'braille_dots_245' => '281a',
    'braille_dots_1245' => '281b',
    'braille_dots_345' => '281c',
    'braille_dots_1345' => '281d',
    'braille_dots_2345' => '281e',
    'braille_dots_12345' => '281f',
    'braille_dots_6' => '2820',
    'braille_dots_16' => '2821',
    'braille_dots_26' => '2822',
    'braille_dots_126' => '2823',
    'braille_dots_36' => '2824',
    'braille_dots_136' => '2825',
    'braille_dots_236' => '2826',
    'braille_dots_1236' => '2827',
    'braille_dots_46' => '2828',
    'braille_dots_146' => '2829',
    'braille_dots_246' => '282a',
    'braille_dots_1246' => '282b',
    'braille_dots_346' => '282c',
    'braille_dots_1346' => '282d',
    'braille_dots_2346' => '282e',
    'braille_dots_12346' => '282f',
    'braille_dots_56' => '2830',
    'braille_dots_156' => '2831',
    'braille_dots_256' => '2832',
    'braille_dots_1256' => '2833',
    'braille_dots_356' => '2834',
    'braille_dots_1356' => '2835',
    'braille_dots_2356' => '2836',
    'braille_dots_12356' => '2837',
    'braille_dots_456' => '2838',
    'braille_dots_1456' => '2839',
    'braille_dots_2456' => '283a',
    'braille_dots_12456' => '283b',
    'braille_dots_3456' => '283c',
    'braille_dots_13456' => '283d',
    'braille_dots_23456' => '283e',
    'braille_dots_123456' => '283f',
    'braille_dots_7' => '2840',
    'braille_dots_17' => '2841',
    'braille_dots_27' => '2842',
    'braille_dots_127' => '2843',
    'braille_dots_37' => '2844',
    'braille_dots_137' => '2845',
    'braille_dots_237' => '2846',
    'braille_dots_1237' => '2847',
    'braille_dots_47' => '2848',
    'braille_dots_147' => '2849',
    'braille_dots_247' => '284a',
    'braille_dots_1247' => '284b',
    'braille_dots_347' => '284c',
    'braille_dots_1347' => '284d',
    'braille_dots_2347' => '284e',
    'braille_dots_12347' => '284f',
    'braille_dots_57' => '2850',
    'braille_dots_157' => '2851',
    'braille_dots_257' => '2852',
    'braille_dots_1257' => '2853',
    'braille_dots_357' => '2854',
    'braille_dots_1357' => '2855',
    'braille_dots_2357' => '2856',
    'braille_dots_12357' => '2857',
    'braille_dots_457' => '2858',
    'braille_dots_1457' => '2859',
    'braille_dots_2457' => '285a',
    'braille_dots_12457' => '285b',
    'braille_dots_3457' => '285c',
    'braille_dots_13457' => '285d',
    'braille_dots_23457' => '285e',
    'braille_dots_123457' => '285f',
    'braille_dots_67' => '2860',
    'braille_dots_167' => '2861',
    'braille_dots_267' => '2862',
    'braille_dots_1267' => '2863',
    'braille_dots_367' => '2864',
    'braille_dots_1367' => '2865',
    'braille_dots_2367' => '2866',
    'braille_dots_12367' => '2867',
    'braille_dots_467' => '2868',
    'braille_dots_1467' => '2869',
    'braille_dots_2467' => '286a',
    'braille_dots_12467' => '286b',
    'braille_dots_3467' => '286c',
    'braille_dots_13467' => '286d',
    'braille_dots_23467' => '286e',
    'braille_dots_123467' => '286f',
    'braille_dots_567' => '2870',
    'braille_dots_1567' => '2871',
    'braille_dots_2567' => '2872',
    'braille_dots_12567' => '2873',
    'braille_dots_3567' => '2874',
    'braille_dots_13567' => '2875',
    'braille_dots_23567' => '2876',
    'braille_dots_123567' => '2877',
    'braille_dots_4567' => '2878',
    'braille_dots_14567' => '2879',
    'braille_dots_24567' => '287a',
    'braille_dots_124567' => '287b',
    'braille_dots_34567' => '287c',
    'braille_dots_134567' => '287d',
    'braille_dots_234567' => '287e',
    'braille_dots_1234567' => '287f',
    'braille_dots_8' => '2880',
    'braille_dots_18' => '2881',
    'braille_dots_28' => '2882',
    'braille_dots_128' => '2883',
    'braille_dots_38' => '2884',
    'braille_dots_138' => '2885',
    'braille_dots_238' => '2886',
    'braille_dots_1238' => '2887',
    'braille_dots_48' => '2888',
    'braille_dots_148' => '2889',
    'braille_dots_248' => '288a',
    'braille_dots_1248' => '288b',
    'braille_dots_348' => '288c',
    'braille_dots_1348' => '288d',
    'braille_dots_2348' => '288e',
    'braille_dots_12348' => '288f',
    'braille_dots_58' => '2890',
    'braille_dots_158' => '2891',
    'braille_dots_258' => '2892',
    'braille_dots_1258' => '2893',
    'braille_dots_358' => '2894',
    'braille_dots_1358' => '2895',
    'braille_dots_2358' => '2896',
    'braille_dots_12358' => '2897',
    'braille_dots_458' => '2898',
    'braille_dots_1458' => '2899',
    'braille_dots_2458' => '289a',
    'braille_dots_12458' => '289b',
    'braille_dots_3458' => '289c',
    'braille_dots_13458' => '289d',
    'braille_dots_23458' => '289e',
    'braille_dots_123458' => '289f',
    'braille_dots_68' => '28a0',
    'braille_dots_168' => '28a1',
    'braille_dots_268' => '28a2',
    'braille_dots_1268' => '28a3',
    'braille_dots_368' => '28a4',
    'braille_dots_1368' => '28a5',
    'braille_dots_2368' => '28a6',
    'braille_dots_12368' => '28a7',
    'braille_dots_468' => '28a8',
    'braille_dots_1468' => '28a9',
    'braille_dots_2468' => '28aa',
    'braille_dots_12468' => '28ab',
    'braille_dots_3468' => '28ac',
    'braille_dots_13468' => '28ad',
    'braille_dots_23468' => '28ae',
    'braille_dots_123468' => '28af',
    'braille_dots_568' => '28b0',
    'braille_dots_1568' => '28b1',
    'braille_dots_2568' => '28b2',
    'braille_dots_12568' => '28b3',
    'braille_dots_3568' => '28b4',
    'braille_dots_13568' => '28b5',
    'braille_dots_23568' => '28b6',
    'braille_dots_123568' => '28b7',
    'braille_dots_4568' => '28b8',
    'braille_dots_14568' => '28b9',
    'braille_dots_24568' => '28ba',
    'braille_dots_124568' => '28bb',
    'braille_dots_34568' => '28bc',
    'braille_dots_134568' => '28bd',
    'braille_dots_234568' => '28be',
    'braille_dots_1234568' => '28bf',
    'braille_dots_78' => '28c0',
    'braille_dots_178' => '28c1',
    'braille_dots_278' => '28c2',
    'braille_dots_1278' => '28c3',
    'braille_dots_378' => '28c4',
    'braille_dots_1378' => '28c5',
    'braille_dots_2378' => '28c6',
    'braille_dots_12378' => '28c7',
    'braille_dots_478' => '28c8',
    'braille_dots_1478' => '28c9',
    'braille_dots_2478' => '28ca',
    'braille_dots_12478' => '28cb',
    'braille_dots_3478' => '28cc',
    'braille_dots_13478' => '28cd',
    'braille_dots_23478' => '28ce',
    'braille_dots_123478' => '28cf',
    'braille_dots_578' => '28d0',
    'braille_dots_1578' => '28d1',
    'braille_dots_2578' => '28d2',
    'braille_dots_12578' => '28d3',
    'braille_dots_3578' => '28d4',
    'braille_dots_13578' => '28d5',
    'braille_dots_23578' => '28d6',
    'braille_dots_123578' => '28d7',
    'braille_dots_4578' => '28d8',
    'braille_dots_14578' => '28d9',
    'braille_dots_24578' => '28da',
    'braille_dots_124578' => '28db',
    'braille_dots_34578' => '28dc',
    'braille_dots_134578' => '28dd',
    'braille_dots_234578' => '28de',
    'braille_dots_1234578' => '28df',
    'braille_dots_678' => '28e0',
    'braille_dots_1678' => '28e1',
    'braille_dots_2678' => '28e2',
    'braille_dots_12678' => '28e3',
    'braille_dots_3678' => '28e4',
    'braille_dots_13678' => '28e5',
    'braille_dots_23678' => '28e6',
    'braille_dots_123678' => '28e7',
    'braille_dots_4678' => '28e8',
    'braille_dots_14678' => '28e9',
    'braille_dots_24678' => '28ea',
    'braille_dots_124678' => '28eb',
    'braille_dots_34678' => '28ec',
    'braille_dots_134678' => '28ed',
    'braille_dots_234678' => '28ee',
    'braille_dots_1234678' => '28ef',
    'braille_dots_5678' => '28f0',
    'braille_dots_15678' => '28f1',
    'braille_dots_25678' => '28f2',
    'braille_dots_125678' => '28f3',
    'braille_dots_35678' => '28f4',
    'braille_dots_135678' => '28f5',
    'braille_dots_235678' => '28f6',
    'braille_dots_1235678' => '28f7',
    'braille_dots_45678' => '28f8',
    'braille_dots_145678' => '28f9',
    'braille_dots_245678' => '28fa',
    'braille_dots_1245678' => '28fb',
    'braille_dots_345678' => '28fc',
    'braille_dots_1345678' => '28fd',
    'braille_dots_2345678' => '28fe',
    'braille_dots_12345678' => '28ff',
    'kana_comma' => '3001',
    'kana_fullstop' => '3002',
    'kana_openingbracket' => '300c',
    'kana_closingbracket' => '300d',
    'voicedsound' => '309b',
    'semivoicedsound' => '309c',
    'kana_a' => '30a1',
    'kana_A' => '30a2',
    'kana_i' => '30a3',
    'kana_I' => '30a4',
    'kana_u' => '30a5',
    'kana_U' => '30a6',
    'kana_e' => '30a7',
    'kana_E' => '30a8',
    'kana_o' => '30a9',
    'kana_O' => '30aa',
    'kana_KA' => '30ab',
    'kana_KI' => '30ad',
    'kana_KU' => '30af',
    'kana_KE' => '30b1',
    'kana_KO' => '30b3',
    'kana_SA' => '30b5',
    'kana_SHI' => '30b7',
    'kana_SU' => '30b9',
    'kana_SE' => '30bb',
    'kana_SO' => '30bd',
    'kana_TA' => '30bf',
    'kana_CHI' => '30c1',
    'kana_tsu' => '30c3',
    'kana_TSU' => '30c4',
    'kana_TE' => '30c6',
    'kana_TO' => '30c8',
    'kana_NA' => '30ca',
    'kana_NI' => '30cb',
    'kana_NU' => '30cc',
    'kana_NE' => '30cd',
    'kana_NO' => '30ce',
    'kana_HA' => '30cf',
    'kana_HI' => '30d2',
    'kana_FU' => '30d5',
    'kana_HE' => '30d8',
    'kana_HO' => '30db',
    'kana_MA' => '30de',
    'kana_MI' => '30df',
    'kana_MU' => '30e0',
    'kana_ME' => '30e1',
    'kana_MO' => '30e2',
    'kana_ya' => '30e3',
    'kana_YA' => '30e4',
    'kana_yu' => '30e5',
    'kana_YU' => '30e6',
    'kana_yo' => '30e7',
    'kana_YO' => '30e8',
    'kana_RA' => '30e9',
    'kana_RI' => '30ea',
    'kana_RU' => '30eb',
    'kana_RE' => '30ec',
    'kana_RO' => '30ed',
    'kana_WA' => '30ef',
    'kana_WO' => '30f2',
    'kana_N' => '30f3',
    'kana_conjunctive' => '30fb',
    'kana_middledot' => '30fb', # Is this recognised by X ?
    'prolongedsound' => '30fc',
    'Hangul_Kiyeog' => '3131',
    'Hangul_SsangKiyeog' => '3132',
    'Hangul_KiyeogSios' => '3133',
    'Hangul_Nieun' => '3134',
    'Hangul_NieunJieuj' => '3135',
    'Hangul_NieunHieuh' => '3136',
    'Hangul_Dikeud' => '3137',
    'Hangul_SsangDikeud' => '3138',
    'Hangul_Rieul' => '3139',
    'Hangul_RieulKiyeog' => '313a',
    'Hangul_RieulMieum' => '313b',
    'Hangul_RieulPieub' => '313c',
    'Hangul_RieulSios' => '313d',
    'Hangul_RieulTieut' => '313e',
    'Hangul_RieulPhieuf' => '313f',
    'Hangul_RieulHieuh' => '3140',
    'Hangul_Mieum' => '3141',
    'Hangul_Pieub' => '3142',
    'Hangul_SsangPieub' => '3143',
    'Hangul_PieubSios' => '3144',
    'Hangul_Sios' => '3145',
    'Hangul_SsangSios' => '3146',
    'Hangul_Ieung' => '3147',
    'Hangul_Jieuj' => '3148',
    'Hangul_SsangJieuj' => '3149',
    'Hangul_Cieuc' => '314a',
    'Hangul_Khieuq' => '314b',
    'Hangul_Tieut' => '314c',
    'Hangul_Phieuf' => '314d',
    'Hangul_Hieuh' => '314e',
    'Hangul_A' => '314f',
    'Hangul_AE' => '3150',
    'Hangul_YA' => '3151',
    'Hangul_YAE' => '3152',
    'Hangul_EO' => '3153',
    'Hangul_E' => '3154',
    'Hangul_YEO' => '3155',
    'Hangul_YE' => '3156',
    'Hangul_O' => '3157',
    'Hangul_WA' => '3158',
    'Hangul_WAE' => '3159',
    'Hangul_OE' => '315a',
    'Hangul_YO' => '315b',
    'Hangul_U' => '315c',
    'Hangul_WEO' => '315d',
    'Hangul_WE' => '315e',
    'Hangul_WI' => '315f',
    'Hangul_YU' => '3160',
    'Hangul_EU' => '3161',
    'Hangul_YI' => '3162',
    'Hangul_I' => '3163',
    'Hangul_RieulYeorinHieuh' => '316d',
    'Hangul_SunkyeongeumMieum' => '3171',
    'Hangul_SunkyeongeumPieub' => '3178',
    'Hangul_PanSios' => '317f',
    'Hangul_KkogjiDalrinIeung' => '3181',
    'Hangul_SunkyeongeumPhieuf' => '3184',
    'Hangul_YeorinHieuh' => '3186',
    'Hangul_AraeA' => '318d',
    'Hangul_AraeAE' => '318e',
);

%xkbsym_table = 
    (%xkbsym_table,
# Control symbols
     'BackSpace' => 'Delete',  # 0008
     'Tab' => 'Tab',           # 0009
     'Linefeed' => 'Linefeed', # 000a
     'Return' => 'Return',     # 000d
     'Escape' => 'Escape',     # 001b
# Keypad keys
     'KP_Multiply' => 'KP_Multiply',
     'KP_Add' => 'KP_Add',
     'KP_Seprator' => 'KP_Comma', # Is this recognised by X ?
     'KP_Separator' => 'KP_Comma',
     'KP_Subtract' => 'KP_Subtract',
     'KP_Decimal' => 'KP_Period',
     'KP_Divide' => 'KP_Divide',
     'KP_0' => 'KP_0',
     'KP_1' => 'KP_1',
     'KP_2' => 'KP_2',
     'KP_3' => 'KP_3',
     'KP_4' => 'KP_4',
     'KP_5' => 'KP_5',
     'KP_6' => 'KP_6',
     'KP_7' => 'KP_7',
     'KP_8' => 'KP_8',
     'KP_9' => 'KP_9',
     'KP_Enter' => 'KP_Enter',
# Keypad keys (alternate level)
     'KP_Home' => 'KP_7',
     'KP_Left' => 'KP_4',
     'KP_Up' => 'KP_8',
     'KP_Right' => 'KP_6',
     'KP_Down' => 'KP_2',
     'KP_Prior' => 'KP_9',
     'KP_Page_Up' => 'KP_9',
     'KP_Next' => 'KP_3',
     'KP_Page_Down' => 'KP_3',
     'KP_End' => 'KP_1',
     'KP_Begin' => 'VoidSymbol', # What does correspond to this?
     'KP_Insert' => 'KP_0',
     'KP_Delete' => 'VoidSymbol', # has to be 'KP_Period' or 'KP_Decimal'
# Keypad keys with missing support in the kernel
     'KP_Space' => 'space',
     'KP_Equal' => 'equal',
     'KP_Tab' => 'Tab',
     'KP_F1' => 'F1',
     'KP_F2' => 'F2',
     'KP_F3' => 'F3',
     'KP_F4' => 'F4',
# Dead symbols
     'dead_grave' => 'dead_grave',
     'SunFA_Grave' => 'dead_grave', # Is this recognised by X ?
     'dead_acute' => 'dead_acute',
     'SunFA_Acute' => 'dead_acute', # Is this recognised by X ?
     'dead_circumflex' => 'dead_circumflex',
     'SunFA_Circum' => 'dead_circumflex', # Is this recognised by X ?
     'dead_tilde' => 'dead_tilde',
     'SunFA_Tilde' => 'dead_tilde',
     'dead_breve' => 'dead_breve',
     'dead_diaeresis' => 'dead_diaeresis',
     'SunFA_Diaeresis' => 'dead_diaeresis', # Is this recognised by X ?
     'dead_doubleacute' => 'dead_doubleacute',
     'dead_caron' => 'dead_caron',
     'dead_V' => 'dead_caron', # Is this correct?
     'dead_cedilla' => 'dead_cedilla',
     'SunFA_Cedilla' => 'dead_cedilla', # Is this recognised by X ?
     'dead_ogonek' => 'dead_ogonek',
# Dead symbols with no support in the kernel
     'dead_macron' => '005f',         # underscore
     'dead_abovedot' => '002e',       # period
     'dead_abovering' => '00b0',      # degree
     'dead_stroke' => '002d',         # hyphen
     'dead_belowdot' => '0323',       # ???? Vietnamese or Romanian cedilla
     'dead_hook' => '0309',           # ???? Vietnamese
     'dead_belowcomma' => 'VoidSymbol',
     'dead_currency' => 'VoidSymbol',
     'dead_doublegrave' => 'VoidSymbol',
     'dead_invertedbreve' => 'VoidSymbol',
     'dead_iota' => '03b9',           # ???? Greek
     'dead_horn' => '031b',           # ???? Greek
     'dead_psili' => 'VoidSymbol',    # ???? Greek
     'dead_dasia' => 'VoidSymbol',    # ???? Greek
# Modifiers
     'Multi_key' => 'Compose',
     'Mode_switch' => 'ShiftL',
     'script_switch' => 'VoidSymbol',
     'Shift_L' => 'Shift',
     'Shift_R' => 'Shift',
     'Control_L' => 'Control',
     'Control_R' => 'Control',
     'Caps_Lock' => 'Caps_Lock',
     'Shift_Lock' => 'Shift_Lock',
     'Meta_L' => 'Alt',
     'Meta_R' => 'Alt',
     'Alt_L' => 'Alt',
     'Alt_R' => 'Alt',
     'Super_L' => 'Alt',
     'Super_R' => 'Alt',
     'Hyper_L' => 'Alt',
     'Hyper_R' => 'Alt',
     'ISO_Lock' => 'Caps_Lock',
     'ISO_Level2_Latch' => 'Shift',
     'ISO_Level3_Shift' => 'AltGr',
     'ISO_Level3_Latch' => 'AltGr',
     'ISO_Level3_Lock' => 'AltGr_Lock',
     'ISO_Level5_Shift' => 'AltGr',
     'ISO_Level5_Latch' => 'AltGr',
     'ISO_Level5_Lock' => 'AltGr_Lock',
     'ISO_Group_Shift' => 'ShiftL',
     'ISO_Group_Latch' => 'ShiftL',
     'ISO_Group_Lock' => 'ShiftL_Lock',
     'ISO_Next_Group' => 'ShiftL_Lock',
     'ISO_Next_Group_Lock' => 'ShiftL_Lock',
     'ISO_Prev_Group' => 'ShiftL_Lock',
     'ISO_Prev_Group_Lock' => 'ShiftL_Lock',
     'ISO_First_Group' => 'ShiftL_Lock',
     'ISO_First_Group_Lock' => 'ShiftL_Lock',
     'ISO_Last_Group' => 'ShiftL_Lock',
     'ISO_Last_Group_Lock' => 'ShiftL_Lock',
# Other symbols
     'NoAction' => 'NoSymbol', # Is this recognised by X ?
     'nosymbol' => 'NoSymbol', # Is this recognised by X ?
     'Nosymbol' => 'NoSymbol', # Is this recognised by X ?
     'noSymbol' => 'NoSymbol', # Is this recognised by X ?
     'NoSymbol' => 'NoSymbol',
     'any' => 'NoSymbol', # Is this recognised by X ?
     'VoidSymbol' => 'VoidSymbol',
     'voidsymbol' => 'VoidSymbol', # Is this recognised by X ?
     'ISO_Left_Tab' => 'Tab',
     'Clear' => 'VoidSymbol',
     'Pause' => 'Pause',
     'Scroll_Lock' => 'Scroll_Lock',
     'Sys_Req' => 'Last_Console',
     'Delete' => 'Remove',
     'Codeinput' => 'VoidSymbol',
     'SingleCandidate' => 'VoidSymbol',
     'MultipleCandidate' => 'VoidSymbol',
     'PreviousCandidate' => 'VoidSymbol',
     'Home' => 'Home',
     'Left' => 'Left',
     'Up' => 'Up',
     'Right' => 'Right',
     'Down' => 'Down',
     'Prior' => 'Prior',
     'Page_Up' => 'PageUp',
     'Next' => 'Next',
     'Page_Down' => 'PageDown',
     'End' => 'End',
     'Begin' => 'VoidSymbol',
     'Select' => 'Select',
     'Print' => 'Control_backslash',
     'Execute' => 'VoidSymbol',
     'Insert' => 'Insert',
     'Undo' => 'VoidSymbol',
     'Redo' => 'VoidSymbol',
     'Menu' => 'VoidSymbol',
     'Find' => 'Find',
     'Cancel' => 'VoidSymbol',
     'Help' => 'Help',
     'Break' => 'Break',
     'Num_Lock' => 'Num_Lock',
     'F1' => 'F1',
     'F2' => 'F2',
     'F3' => 'F3',
     'F4' => 'F4',
     'F5' => 'F5',
     'F6' => 'F6',
     'F7' => 'F7',
     'F8' => 'F8',
     'F9' => 'F9',
     'F10' => 'F10',
     'F11' => 'F11',
     'L1' => 'F11',
     'F12' => 'F12',
     'L2' => 'F12',
     'F13' => 'F13',
     'L3' => 'F13',
     'F14' => 'F14',
     'L4' => 'F14',
     'F15' => 'F15',
     'L5' => 'F15',
     'F16' => 'F16',
     'L6' => 'F16',
     'F17' => 'F17',
     'L7' => 'F17',
     'F18' => 'F18',
     'L8' => 'F18',
     'F19' => 'F19',
     'L9' => 'F19',
     'F20' => 'F20',
     'L10' => 'F20',
     'F21' => 'F21',
     'R1' => 'F21',
     'F22' => 'F22',
     'R2' => 'F22',
     'F23' => 'F23',
     'R3' => 'F23',
     'F24' => 'F24',
     'R4' => 'F24',
     'F25' => 'F25',
     'R5' => 'F25',
     'F26' => 'F26',
     'R6' => 'F26',
     'F27' => 'F27',
     'R7' => 'F27',
     'F28' => 'F28',
     'R8' => 'F28',
     'F29' => 'F29',
     'R9' => 'F29',
     'F30' => 'F30',
     'R10' => 'F30',
     'F31' => 'F31',
     'R11' => 'F31',
     'F32' => 'F32',
     'R12' => 'F32',
     'F33' => 'F33',
     'R13' => 'F33',
     'F34' => 'F34',
     'R14' => 'F34',
     'F35' => 'F35',
     'R15' => 'F35',
     'Terminate_Server' => 'VoidSymbol',
     'Pointer_EnableKeys' => 'VoidSymbol',
     'XF86_Switch_VT_1' => 'Console_1',
     'XF86_Switch_VT_2' => 'Console_2',
     'XF86_Switch_VT_3' => 'Console_3',
     'XF86_Switch_VT_4' => 'Console_4',
     'XF86_Switch_VT_5' => 'Console_5',
     'XF86_Switch_VT_6' => 'Console_6',
     'XF86_Switch_VT_7' => 'Console_7',
     'XF86_Switch_VT_8' => 'Console_8',
     'XF86_Switch_VT_9' => 'Console_9',
     'XF86_Switch_VT_10' => 'Console_10',
     'XF86_Switch_VT_11' => 'Console_11',
     'XF86_Switch_VT_12' => 'Console_12',
     'XF86_ClearGrab' => 'VoidSymbol',
     'XF86_Ungrab' => 'VoidSymbol',
     'XF86_Next_VMode' => 'VoidSymbol',
     'XF86_Prev_VMode' => 'VoidSymbol',
     'XF86Copy' => 'VoidSymbol',
     'XF86Cut' => 'VoidSymbol',
     'XF86Paste' => 'VoidSymbol',
     'XF86AudioLowerVolume' => 'VoidSymbol',
     'XF86AudioRaiseVolume' => 'VoidSymbol',
     'XF86AudioMute' => 'VoidSymbol',
     'XF86PowerOff' => 'VoidSymbol',
     'XF86AudioForward' => 'VoidSymbol',
     'XF86AudioMedia' => 'VoidSymbol',
     'XF86AudioNext' => 'VoidSymbol',
     'XF86AudioPause' => 'VoidSymbol',
     'XF86AudioPlay' => 'VoidSymbol',
     'XF86AudioPrev' => 'VoidSymbol',
     'XF86AudioRecord' => 'VoidSymbol',
     'XF86AudioRewind' => 'VoidSymbol',
     'XF86AudioStop' => 'VoidSymbol',
     'XF86Back' => 'VoidSymbol',
     'XF86Battery' => 'VoidSymbol',
     'XF86Bluetooth' => 'VoidSymbol',
     'XF86Calculator' => 'VoidSymbol',
     'XF86Close' => 'VoidSymbol',
     'XF86Display' => 'VoidSymbol',
     'XF86Documents' => 'VoidSymbol',
     'XF86DOS' => 'VoidSymbol',
     'XF86Eject' => 'VoidSymbol',
     'XF86Explorer' => 'VoidSymbol',
     'XF86Favorites' => 'VoidSymbol',
     'XF86Finance' => 'VoidSymbol',
     'XF86Forward' => 'VoidSymbol',
     'XF86HomePage' => 'VoidSymbol',
     'XF86KbdBrightnessDown' => 'VoidSymbol',
     'XF86KbdBrightnessUp' => 'VoidSymbol',
     'XF86KbdLightOnOff' => 'VoidSymbol',
     'XF86Launch1' => 'VoidSymbol',
     'XF86Launch2' => 'VoidSymbol',
     'XF86Launch3' => 'VoidSymbol',
     'XF86Launch4' => 'VoidSymbol',
     'XF86Mail' => 'VoidSymbol',
     'XF86MailForward' => 'VoidSymbol',
     'XF86MenuKB' => 'VoidSymbol',
     'XF86MonBrightnessDown' => 'VoidSymbol',
     'XF86MonBrightnessUp' => 'VoidSymbol',
     'XF86MyComputer' => 'VoidSymbol',
     'XF86New' => 'VoidSymbol',
     'XF86Phone' => 'VoidSymbol',
     'XF86Reload' => 'VoidSymbol',
     'XF86Reply' => 'VoidSymbol',
     'XF86RotateWindows' => 'VoidSymbol',
     'XF86Save' => 'VoidSymbol',
     'XF86ScreenSaver' => 'VoidSymbol',
     'XF86ScrollDown' => 'VoidSymbol',
     'XF86ScrollUp' => 'VoidSymbol',
     'XF86Search' => 'VoidSymbol',
     'XF86Send' => 'VoidSymbol',
     'XF86Shop' => 'VoidSymbol',
     'XF86Sleep' => 'VoidSymbol',
     'XF86Suspend' => 'VoidSymbol',
     'XF86Tools' => 'VoidSymbol',
     'XF86TouchpadToggle' => 'VoidSymbol',
     'XF86WakeUp' => 'VoidSymbol',
     'XF86WebCam' => 'VoidSymbol',
     'XF86WLAN' => 'VoidSymbol',
     'XF86WWW' => 'VoidSymbol',
     'XF86Xfer' => 'VoidSymbol',
     'braille_blank' => 'Brl_blank',
     'braille_dot_1' => 'Brl_dot1',
     'braille_dot_2' => 'Brl_dot2',
     'braille_dot_3' => 'Brl_dot3',
     'braille_dot_4' => 'Brl_dot4',
     'braille_dot_5' => 'Brl_dot5',
     'braille_dot_6' => 'Brl_dot6',
     'braille_dot_7' => 'Brl_dot7',
     'braille_dot_8' => 'Brl_dot8',
     'braille_dot_9' => 'Brl_dot9',
     'braille_dot_10' => 'Brl_dot10',
# I do not know the Unicodes of these
     '0x1000' => 'VoidSymbol', # Special symbol for X or syntax error?
     '0x13a4' => 'VoidSymbol', # Special symbol for X or syntax error?
     '0xfe11' => 'VoidSymbol', # Special symbol for X or syntax error?
     'leftcaret' => 'VoidSymbol', # Is this recognised by X ?
     'guj_rra' => 'VoidSymbol', # Is this recognised by X ?
     'guj_nnna' => 'VoidSymbol', # Is this recognised by X ?
     'guj_llla' => 'VoidSymbol', # Is this recognised by X ?
     'gur_visarga' => 'VoidSymbol', # Is this recognised by X ?
     'gur_v_r' => 'VoidSymbol', # Is this recognised by X ?
     'gur_v_r_s' => 'VoidSymbol', # Is this recognised by X ?
     'Eisu_toggle' => 'VoidSymbol', # Is this recognised by X ?
     'Zenkaku_Hankaku' => 'VoidSymbol', # Is this recognised by X ?
     'Kanji' => 'VoidSymbol', # Is this recognised by X ?
     'Hangul' => 'VoidSymbol', # Is this recognised by X ?
     'Hangul_Hanja' => 'VoidSymbol', # Is this recognised by X ?
     'Henkan' => 'VoidSymbol',
     'Hiragana' => 'VoidSymbol',
     'Hiragana_Katakana' => 'VoidSymbol',
     'Katakana' => 'VoidSymbol',
     'Muhenkan' => 'VoidSymbol',
# XFree86 does not recognise these
     'SunAudioLowerVolume' => 'VoidSymbol',
     'SunAudioRaiseVolume' => 'VoidSymbol',
     'SunAudioMute' => 'VoidSymbol',
     'SunCopy' => 'VoidSymbol',
     'SunCut' => 'VoidSymbol',
     'SunPaste' => 'VoidSymbol',
     'SunAgain' => 'VoidSymbol',
     'SunUndo' => 'VoidSymbol',
     'SunFind' => 'VoidSymbol',
     'SunStop' => 'VoidSymbol',
     'SunF36' => 'VoidSymbol',
     'SunF37' => 'VoidSymbol',
     'SunFront' => 'VoidSymbol',
     'SunOpen' => 'VoidSymbol',
     'SunPowerSwitch' => 'VoidSymbol',
     'SunPowerSwitchShift' => 'VoidSymbol',
     'SunProps' => 'VoidSymbol',
     'SunSys_Req' => 'VoidSymbol',
     'SunVideoDegauss' => 'VoidSymbol',
     'SunVideoLowerBrightness' => 'VoidSymbol',
     'SunVideoRaiseBrightness' => 'VoidSymbol',
    );

for my $i (keys %xkbsym_table) {
    if ($xkbsym_table{$i} !~ /^[a-zA-Z0-9]{4}$/) {
        delete $xkbsym_table{$i};
    }
}

sub lower_case {
    my $sequence = $_[0];
    my @k = split ' ', $sequence;
    for my $i (0 .. $#k) {
	(my $lc = $k[$i]) =~ tr/A-Z/a-z/;
	if (defined $xkbsym_table{$lc}) {
	    $k[$i] = $lc;
	}
    }
    return "@k";
}

use bytes;

my %compose;
my $line = 0;
while (<>) {
    $line++;
    s/\#[^\"].*//;
    s/\s+/ /g;
    next unless (/[^ ]/);
    /^(.*?) ?: ?\"(.*) ([a-zA-Z0-9_]+) ?$/
	or die "$0: syntax error on line $line\n$_\n";
    my $sequence = $1;
    my $result = $2;
    $sequence =~ s/\<//g;
    $sequence =~ s/\>//g;
    if ($result =~ /^([^\\])\"$/) {
	$result = $1;
    } elsif ($result =~ /^\\([0-7]+)\"$/) {
	$result = chr (oct ($1));
    } elsif ($result =~ /^\\([\"\\])\"$/) {
	$result = $1;
    } else {
	die "$0: syntax error on line $line\n$_\n";
    }
    if ($result eq '\\' || $result eq '\'') {
	$result = '\\'. $result;
    }
    if ($sequence =~ /^Multi_key [a-zA-Z0-9_]+ space/) {
	next;
    }
    if ((' '. $sequence .' ') =~ / space /) {
	next;
    }
    if ($sequence =~ /(dead_[a-z]+) \1/) {
 	next;
    }
    if ($sequence =~ / .* .* /) {
	warning "Skipping too long sequence: $_\n";
	next;
    }
    if ($sequence =~ /^dead_.* .* /) {
	warning "Skipping too long sequence: $_\n";
	next;
    }
    $sequence =~ s/^Multi_key //;
    $compose{$sequence} = $result;
}

my @sequences = keys %compose;

my %lc_compose;
my %lc_sequences;

foreach my $sequence (@sequences) {
    my @k = split ' ', $sequence;
    if ($k[0] =~ /^.$/) {
	if (defined $compose{"$k[1] $k[0]"}
	    && $compose{$sequence} eq $compose{"$k[1] $k[0]"}) {
	    delete $compose{$sequence};
	    next;
	}
    }
    my $lcase = lower_case ($sequence);
    if (! defined $lc_compose{$lcase}) {
	$lc_compose{$lcase} = $compose{$sequence};
	push @{$lc_sequences{$lcase}}, $sequence;
    } elsif ($lc_compose{$lcase} eq $compose{$sequence}) {
	push @{$lc_sequences{$lcase}}, $sequence;
    } else {
	$lc_compose{$lcase} = 'DISAGREEMENT';
    }
}

foreach my $lcase (keys %lc_compose) {
    next if ($lc_compose{$lcase} eq 'DISAGREEMENT');
    foreach my $sequence (@{$lc_sequences{$lcase}}) {
	delete $compose{$sequence};
    }
    $compose{$lcase} = $lc_compose{$lcase};
}

my %output;
my %original_sequences;
foreach my $sequence (keys %compose) {
    my @k = split ' ', $sequence;
    for my $i (0 .. $#k) {
	if (defined $xkbsym_table{$k[$i]}) {
	    my $l = $acmtable{hex($xkbsym_table{$k[$i]})};
	    if (! defined $l) {
#		debug "Undefined in ACM $k[$i]\n";
		@k = ();
		last;
	    }
	    $k[$i] = chr($l);
	    if ($k[$i] eq '\\' || $k[$i] eq '\'') {
		$k[$i] = '\\'. $k[$i];
	    }
	} else {
#	    debug "Undefined keysym $k[$i]\n";
	    @k = ();
	    last;
	}
    }
    next if ($#k < 0);
    if ($#k != 1) {
	warning "Skipping too short sequence: $sequence\n";
	next;
    }
    if (! defined $output{"\'$k[0]\' \'$k[1]\'"}) {
	$output{"\'$k[0]\' \'$k[1]\'"} = "\'$compose{$sequence}\'";
	$original_sequences{"\'$k[0]\' \'$k[1]\'"} = $sequence;
    } else {
	my $newsequence = $sequence;
	my $newresult = "\'$compose{$sequence}\'";
	my $oldsequence = $original_sequences{"\'$k[0]\' \'$k[1]\'"};
	my $oldresult = $output{"\'$k[0]\' \'$k[1]\'"};
	my $scsequence = "\'$k[0]\' \'$k[1]\'";
	if ($oldresult ne $newresult) {
	    # The keyboards for languages that need circumflex and tilde can
	    # generate them natively so prefer caron and doubleacute.
	    if ($newsequence =~ /dead_caron/
		|| $newsequence =~ /dead_doubleacute/) {
		my ($x, $y) = ($oldsequence, $oldresult);
		($oldsequence, $oldresult) = ($newsequence, $newresult);
		($newsequence, $newresult) = ($x, $y);
	    }
	    warning "Skipping sequience due to collision:\n";
	    warning "  Skip: $newsequence\n";
	    warning "  Preserve: $oldsequence\n";
	}
    } 
}

@sequences = sort (keys %output);

for my $sequence (@sequences) {
    print "compose $sequence to $output{$sequence}\n";
}
