#!/usr/bin/perl -w

use utf8;

print "<dictionary>\n";

while (<>) {

#Start of entity replacement list as found on the page:
# <http://lexicon.ff.cuni.cz/about/aa_character_encoding.html>

# The first four entities should NOT be replaced, as they have special
# meaning in xml.
# s/&quot;/\x{0022}/g ;
# s/&amp;/\x{0026}/g ;
# s/&lt;/\x{003C}/g ;
# s/&gt;/\x{003E}/g ;
s/&tilde;/\x{007E}/g ;
s/&sect;/\x{00A7}/g ;
s/&laquo;/\x{00AB}/g ;
s/&para;/\x{00B6}/g ;
s/&raquo;/\x{00BB}/g ;
s/&Agrave;/\x{00C0}/g ;
s/&Aacute;/\x{00C1}/g ;
s/&Acirc;/\x{00C2}/g ;
s/&Atilde;/\x{00C3}/g ;
s/&Auml;/\x{00C4}/g ;
s/&Aring;/\x{00C5}/g ;
s/&AElig;/\x{00C6}/g ;
s/&Ccedil;/\x{00C7}/g ;
s/&Egrave;/\x{00C8}/g ;
s/&Eacute;/\x{00C9}/g ;
s/&Ecirc;/\x{00CA}/g ;
s/&Euml;/\x{00CB}/g ;
s/&Igrave;/\x{00CC}/g ;
s/&Iacute;/\x{00CD}/g ;
s/&Icirc;/\x{00CE}/g ;
s/&Iuml;/\x{00CF}/g ;
s/&ETH;/\x{00D0}/g ;
s/&Ntilde;/\x{00D1}/g ;
s/&Ograve;/\x{00D2}/g ;
s/&Oacute;/\x{00D3}/g ;
s/&Ocirc;/\x{00D4}/g ;
s/&Otilde;/\x{00D5}/g ;
s/&Ouml;/\x{00D6}/g ;
s/&Oslash;/\x{00D8}/g ;
s/&Ugrave;/\x{00D9}/g ;
s/&Uacute;/\x{00DA}/g ;
s/&Ucirc;/\x{00DB}/g ;
s/&Uuml;/\x{00DC}/g ;
s/&Yacute;/\x{00DD}/g ;
s/&THORN;/\x{00DE}/g ;
s/&szlig;/\x{00DF}/g ;
s/&agrave;/\x{00E0}/g ;
s/&aacute;/\x{00E1}/g ;
s/&acirc;/\x{00E2}/g ;
s/&atilde;/\x{00E3}/g ;
s/&auml;/\x{00E4}/g ;
s/&aring;/\x{00E5}/g ;
s/&aelig;/\x{00E6}/g ;
s/&ccedil;/\x{00E7}/g ;
s/&egrave;/\x{00E8}/g ;
s/&eacute;/\x{00E9}/g ;
s/&ecirc;/\x{00EA}/g ;
s/&euml;/\x{00EB}/g ;
s/&igrave;/\x{00EC}/g ;
s/&iacute;/\x{00ED}/g ;
s/&icirc;/\x{00EE}/g ;
s/&iuml;/\x{00EF}/g ;
s/&eth;/\x{00F0}/g ;
s/&ntilde;/\x{00F1}/g ;
s/&ograve;/\x{00F2}/g ;
s/&oacute;/\x{00F3}/g ;
s/&ocirc;/\x{00F4}/g ;
s/&otilde;/\x{00F5}/g ;
s/&ouml;/\x{00F6}/g ;
s/&oslash;/\x{00F8}/g ;
s/&ugrave;/\x{00F9}/g ;
s/&uacute;/\x{00FA}/g ;
s/&ucirc;/\x{00FB}/g ;
s/&uuml;/\x{00FC}/g ;
s/&yacute;/\x{00FD}/g ;
s/&thorn;/\x{00FE}/g ;
s/&yuml;/\x{00FF}/g ;
# The following 6 entities do not have a proper Unicode representation;
# what is used is an approximation with the possibilities at hand:
s/&dash-uncertain;/\x{223C}/g ;
s/&e-sub;/\x{2091}/g ;
s/&u-super;/<sup>u<\/sup>/g ;
s/&aolig;/a\x{fe20}\x{fe21}o/g ;
s/&aolig-acute;/a\x{fe20}\x{fe21}o\x{0301}/g ;
s/&thorn-bar;/\x{00fe}\x{0336}/g ;
# The rest of the entities do have proper Unicode representations as
# defined on the page referred to above.
s/&a-acute-hook;/\x{0061}\x{0301}\x{0328}/g ;
s/&a-long-acute;/\x{0061}\x{0304}\x{0301}/g ;
s/&a-long-short;/\x{0061}\x{0304}\x{0306}/g ;
s/&a-odot-acute;/\x{0061}\x{0307}\x{0301}/g ;
s/&a-uml-circ;/\x{0061}\x{0308}\x{0302}/g ;
s/&a-ohook;/\x{0061}\x{0313}/g ;
s/&c-hachek-udot;/\x{0063}\x{030C}\x{0323}/g ;
s/&c-tilde;/\x{0063}\x{0303}/g ;
s/&c-udot;/\x{0063}\x{0323}/g ;
s/&e-acute-hook;/\x{0065}\x{0301}\x{0328}/g ;
s/&e-circ-acute;/\x{0065}\x{0302}\x{0301}/g ;
s/&e-tilde-hook;/\x{0065}\x{0303}\x{0328}/g ;
s/&e-long-short;/\x{0065}\x{0304}\x{0306}/g ;
s/&e-long-hook;/\x{0065}\x{0304}\x{0328}/g ;
s/&e-odot-acute;/\x{0065}\x{0307}\x{0301}/g ;
s/&e-odot-tilde;/\x{0065}\x{0307}\x{0303}/g ;
s/&e-uml-acute;/\x{0065}\x{0308}\x{0301}/g ;
s/&e-uml-tilde;/\x{0065}\x{0308}\x{0303}/g ;
s/&e-ohook;/\x{0065}\x{0313}/g ;
s/&g-ocomma;/\x{0067}\x{0315}/g ;
s/&i-circ-acute;/\x{0069}\x{0302}\x{0301}/g ;
s/&i-tilde-hook;/\x{0069}\x{0303}\x{0328}/g ;
s/&i-long-acute;/\x{0069}\x{0304}\x{0301}/g ;
s/&i-long-short;/\x{0069}\x{0304}\x{0306}/g ;
s/&i-oring;/\x{0069}\x{030A}/g ;
s/&i-oring-acute;/\x{0069}\x{030A}\x{0301}/g ;
s/&i-oring-tilde;/\x{0069}\x{030A}\x{0303}/g ;
s/&i-nonsyllabic;/\x{0069}\x{032F}/g ;
s/&k-circ;/\x{006B}\x{0302}/g ;
s/&k-ocomma;/\x{006B}\x{0315}/g ;
s/&l-tilde;/\x{006C}\x{0303}/g ;
s/&l-ocomma;/\x{006C}\x{0315}/g ;
s/&l-uring;/\x{006C}\x{0325}/g ;
s/&m-tilde;/\x{006D}\x{0303}/g ;
s/&m-uring;/\x{006D}\x{0325}/g ;
s/&n-ocomma;/\x{006E}\x{0315}/g ;
s/&n-uring;/\x{006E}\x{0325}/g ;
s/&o-acute-hook;/\x{006F}\x{0301}\x{0328}/g ;
s/&o-circ-acute;/\x{006F}\x{0302}\x{0301}/g ;
s/&o-circ-hook;/\x{006F}\x{0302}\x{0328}/g ;
s/&o-long-acute;/\x{006F}\x{0304}\x{0301}/g ;
s/&o-long-short;/\x{006F}\x{0304}\x{0306}/g ;
s/&o-uml-circ;/\x{006F}\x{0308}\x{0302}/g ;
s/&q-bar;/\x{0071}\x{0336}/g ;
s/&r-acute-udot;/\x{0072}\x{0301}\x{0323}/g ;
s/&r-tilde;/\x{0072}\x{0303}/g ;
s/&r-long;/\x{0072}\x{0304}/g ;
s/&r-uring;/\x{0072}\x{0325}/g ;
s/&s-ocomma;/\x{0073}\x{0315}/g ;
s/&t-ocomma;/\x{0074}\x{0315}/g ;
s/&u-circ-acute;/\x{0075}\x{0302}\x{0301}/g ;
s/&u-long-acute;/\x{0075}\x{0304}\x{0301}/g ;
s/&u-long-short;/\x{0075}\x{0304}\x{0306}/g ;
s/&u-odot;/\x{0075}\x{0307}/g ;
s/&u-uml-circ;/\x{0075}\x{0308}\x{0302}/g ;
s/&u-oring-acute;/\x{0075}\x{030A}\x{0301}/g ;
s/&u-oring-tilde;/\x{0075}\x{030A}\x{0303}/g ;
s/&u-nonsyllabic;/\x{0075}\x{032F}/g ;
s/&v-long;/\x{0076}\x{0304}/g ;
s/&y-short;/\x{0079}\x{0306}/g ;
s/&z-odot;/\x{007A}\x{0307}/g ;
s/&O-slash-long;/\x{00D8}\x{0304}/g ;
s/&a-tilde;/\x{00E3}/g ;
s/&aelig-circ;/\x{00E6}\x{0302}/g ;
s/&o-slash-long;/\x{00F8}\x{0304}/g ;
s/&A-long;/\x{0100}/g ;
s/&a-long;/\x{0101}/g ;
s/&A-short;/\x{0102}/g ;
s/&a-short;/\x{0103}/g ;
s/&a-hook;/\x{0105}/g ;
s/&c-acute;/\x{0107}/g ;
s/&c-hachek;/\x{010D}/g ;
s/&d-bar;/\x{0111}/g ;
s/&E-long;/\x{0112}/g ;
s/&e-long;/\x{0113}/g ;
s/&e-short;/\x{0115}/g ;
s/&e-odot;/\x{0117}/g ;
s/&e-hook;/\x{0119}/g ;
s/&e-hachek;/\x{011B}/g ;
s/&g-circ;/\x{011D}/g ;
s/&i-tilde;/\x{0129}/g ;
s/&I-long;/\x{012A}/g ;
s/&i-long;/\x{012B}/g ;
s/&i-short;/\x{012D}/g ;
s/&i-hook;/\x{012F}/g ;
s/&k-cedil;/\x{0137}/g ;
s/&l-bar;/\x{0142}/g ;
s/&n-acute;/\x{0144}/g ;
s/&O-long;/\x{014C}/g ;
s/&o-long;/\x{014D}/g ;
s/&o-short;/\x{014F}/g ;
s/&OElig;/\x{0152}/g ;
s/&oelig;/\x{0153}/g ;
s/&oelig-acute;/\x{0153}\x{0301}/g ;
s/&r-hachek;/\x{0159}/g ;
s/&s-acute;/\x{015B}/g ;
s/&s-hachek;/\x{0161}/g ;
s/&u-tilde;/\x{0169}/g ;
s/&0x-long;/\x{016A}/g ;
s/&u-long;/\x{016B}/g ;
s/&u-short;/\x{016D}/g ;
s/&u-oring;/\x{016F}/g ;
s/&w-circ;/\x{0175}/g ;
s/&y-circ;/\x{0177}/g ;
s/&z-hachek;/\x{017E}/g ;
s/&s-tall;/\x{017F}/g ;
s/&b-bar;/\x{0180}/g ;
s/&hw;/\x{0195}/g ;
s/&wynn;/\x{01BF}/g ;
s/&a-hachek;/\x{01CE}/g ;
s/&u-hachek;/\x{01D4}/g ;
s/&aelig-long;/\x{01E3}/g ;
s/&O-hook;/\x{01EA}/g ;
s/&o-hook;/\x{01EB}/g ;
s/&j-hachek;/\x{01F0}/g ;
s/&g-acute;/\x{01F5}/g ;
s/&AElig-acute;/\x{01FC}/g ;
s/&aelig-acute;/\x{01FD}/g ;
s/&YOGH;/\x{021C}/g ;
s/&yogh;/\x{021D}/g ;
s/&z-tail;/\x{0225}/g ;
s/&a-odot;/\x{0227}/g ;
s/&Y-long;/\x{0232}/g ;
s/&y-long;/\x{0233}/g ;
s/&schwa;/\x{0259}/g ;
s/&r-runic;/\x{0280}/g ;
s/&Alpha;/\x{0391}/g ;
s/&Beta;/\x{0392}/g ;
s/&Gamma;/\x{0393}/g ;
s/&Delta;/\x{0394}/g ;
s/&Epsilon;/\x{0395}/g ;
s/&Zeta;/\x{0396}/g ;
s/&Eta;/\x{0397}/g ;
s/&Theta;/\x{0398}/g ;
s/&Iota;/\x{0399}/g ;
s/&Kappa;/\x{039A}/g ;
s/&Lambda;/\x{039B}/g ;
s/&Mu;/\x{039C}/g ;
s/&Nu;/\x{039D}/g ;
s/&Xi;/\x{039E}/g ;
s/&Omicron;/\x{039F}/g ;
s/&Pi;/\x{03A0}/g ;
s/&Rho;/\x{03A1}/g ;
s/&Sigma;/\x{03A3}/g ;
s/&Tau;/\x{03A4}/g ;
s/&0xpsilon;/\x{03A5}/g ;
s/&Phi;/\x{03A6}/g ;
s/&Chi;/\x{03A7}/g ;
s/&Psi;/\x{03A8}/g ;
s/&Omega;/\x{03A9}/g ;
s/&alpha;/\x{03B1}/g ;
s/&beta;/\x{03B2}/g ;
s/&gamma;/\x{03B3}/g ;
s/&delta;/\x{03B4}/g ;
s/&epsilon;/\x{03B5}/g ;
s/&epsilon-long;/\x{03B5}\x{0304}/g ;
s/&zeta;/\x{03B6}/g ;
s/&eta;/\x{03B7}/g ;
s/&theta;/\x{03B8}/g ;
s/&iota;/\x{03B9}/g ;
s/&kappa;/\x{03BA}/g ;
s/&lambda;/\x{03BB}/g ;
s/&mu;/\x{03BC}/g ;
s/&nu;/\x{03BD}/g ;
s/&xi;/\x{03BE}/g ;
s/&omicron;/\x{03BF}/g ;
s/&pi;/\x{03C0}/g ;
s/&rho;/\x{03C1}/g ;
s/&sigmaf;/\x{03C2}/g ;
s/&sigma;/\x{03C3}/g ;
s/&tau;/\x{03C4}/g ;
s/&upsilon;/\x{03C5}/g ;
s/&phi;/\x{03C6}/g ;
s/&chi;/\x{03C7}/g ;
s/&psi;/\x{03C8}/g ;
s/&omega;/\x{03C9}/g ;
s/&iota-diar;/\x{03CA}/g ;
s/&left-half-ring;/\x{0559}/g ;
s/&d-udot;/\x{1E0D}/g ;
s/&h-udot;/\x{1E25}/g ;
s/&l-udot;/\x{1E37}/g ;
s/&m-odot;/\x{1E41}/g ;
s/&m-udot;/\x{1E43}/g ;
s/&n-odot;/\x{1E45}/g ;
s/&n-udot;/\x{1E47}/g ;
s/&r-odot;/\x{1E59}/g ;
s/&r-udot;/\x{1E5B}/g ;
s/&s-udot;/\x{1E63}/g ;
s/&t-udot;/\x{1E6D}/g ;
s/&v-udot;/\x{1E7F}/g ;
s/&a-udot;/\x{1EA1}/g ;
s/&a-circ-acute;/\x{1EA5}/g ;
s/&e-udot;/\x{1EB9}/g ;
s/&e-tilde;/\x{1EBD}/g ;
s/&y-tilde;/\x{1EF9}/g ;
s/&alpha-psili;/\x{1F00}/g ;
s/&alpha-dasia;/\x{1F01}/g ;
s/&alpha-dasia-oxia;/\x{1F04}/g ;
s/&alpha-psili-oxia;/\x{1F04}/g ;
s/&Alpha-psili;/\x{1F08}/g ;
s/&Alpha-dasia;/\x{1F09}/g ;
s/&epsilon-psili;/\x{1F10}/g ;
s/&epsilon-dasia;/\x{1F11}/g ;
s/&epsilon-psili-oxia;/\x{1F14}/g ;
s/&epsilon-dasia-oxia;/\x{1F15}/g ;
s/&eta-psili;/\x{1F20}/g ;
s/&eta-psili-oxia;/\x{1F24}/g ;
s/&eta-dasia-oxia;/\x{1F25}/g ;
s/&eta-psili-peri;/\x{1F26}/g ;
s/&eta-dasia-peri;/\x{1F27}/g ;
s/&iota-psili;/\x{1F30}/g ;
s/&iota-dasia;/\x{1F31}/g ;
s/&iota-psili-oxia;/\x{1F34}/g ;
s/&iota-dasia-oxia;/\x{1F35}/g ;
s/&iota-psili-peri;/\x{1F36}/g ;
s/&iota-dasia-peri;/\x{1F37}/g ;
s/&omicron-psili;/\x{1F40}/g ;
s/&omicron-psili-peri;/\x{1F40}\x{0342}/g ;
s/&omicron-dasia;/\x{1F41}/g ;
s/&omicron-psili-oxia;/\x{1F44}/g ;
s/&omicron-dasia-oxia;/\x{1F45}/g ;
s/&upsilon-psili;/\x{1F50}/g ;
s/&upsilon-dasia;/\x{1F51}/g ;
s/&upsilon-psili-oxia;/\x{1F54}/g ;
s/&upsilon-dasia-oxia;/\x{1F55}/g ;
s/&upsilon-psili-peri;/\x{1F56}/g ;
s/&omega-psili;/\x{1F60}/g ;
s/&omega-psili-ypo;/\x{1F60}\x{0345}/g ;
s/&omega-psili-oxia;/\x{1F64}/g ;
s/&omega-dasia-oxia;/\x{1F65}/g ;
s/&omega-psili-peri;/\x{1F66}/g ;
s/&omega-dasia-peri;/\x{1F67}/g ;
s/&alpha-oxia;/\x{1F71}/g ;
s/&epsilon-oxia;/\x{1F73}/g ;
s/&eta-dasia;/\x{1F74}/g ;
s/&eta-oxia;/\x{1F75}/g ;
s/&iota-oxia;/\x{1F77}/g ;
s/&omicron-varia;/\x{1F78}/g ;
s/&omicron-oxia;/\x{1F79}/g ;
s/&upsilon-oxia;/\x{1F7B}/g ;
s/&omega-oxia;/\x{1F7D}/g ;
s/&alpha-long;/\x{1FB1}/g ;
s/&alpha-long-oxia;/\x{1FB1}\x{0301}/g ;
s/&alpha-long-psili-oxia;/\x{1FB1}\x{0313}\x{0301}/g ;
s/&alpha-peri;/\x{1FB6}/g ;
s/&eta-ypo;/\x{1FC3}/g ;
s/&eta-peri;/\x{1FC6}/g ;
s/&iota-long;/\x{1FD1}/g ;
s/&iota-long-oxia;/\x{1FD1}\x{0301}/g ;
s/&iota-long-psili;/\x{1FD1}\x{0313}/g ;
s/&iota-diar-oxia;/\x{1FD3}/g ;
s/&iota-peri;/\x{1FD6}/g ;
s/&iota-psili;/\x{1FD6}/g ;
s/&upsilon-long;/\x{1FE1}/g ;
s/&upsilon-long-oxia;/\x{1FE1}\x{0301}/g ;
s/&upsilon-long-dasia;/\x{1FE1}\x{0314}/g ;
s/&upsilon-diar-oxia;/\x{1FE3}/g ;
s/&rho-dasia;/\x{1FE5}/g ;
s/&upsilon-peri;/\x{1FE6}/g ;
s/&omega-ypo;/\x{1FF3}/g ;
s/&omega-peri;/\x{1FF6}/g ;
s/&omega-peri-ypo;/\x{1FF7}/g ;
s/&ndash;/\x{2013}/g ;
s/&mdash;/\x{2014}/g ;
s/&dash-acute;/\x{2014}\x{0301}/g ;
s/&highquote;/\x{2018}/g ;
s/&lowquote;/\x{201A}/g ;
s/&bull;/\x{2022}/g ;
s/&sup4;/\x{2074}/g ;

# The following entities are NOT defined on the page reffed above:
s/&c-reversed-long;/\x{2184}\x{0304}/g ;
s/&c-super;/<sup>c<\/sup>/g ;
s/&hand;/\x{261d}/g ;

s/&frac12;/\x{00bd}/g ;
s/&g-long;/\x{1e21}/g ;
s/&h-bar;/\x{0127}/g ;
s/&ordm;/<sup>m<\/sup>/g ;
s/&rArr;/\x{2192}/g ;
s/&times;/\x{00d7}/g ;

s/&FINGER;/\x{261a}/g ;
s/&OMEGA;/\x{03a9}/g ;
s/&avlig;/a\x{fe20}\x{fe21}v/g ;
s/&infin;/\x{29dc}/g ;

#Incomplete entity declarations (missing ;):
s/&FINGER</\x{261a}</g ;
s/>or&eth</>or\x{00f0}</g ;

# Some tag cleanup:
# empty elements need to be properly closed:
s/<PAGE NUM=\"(.+)\">/<PAGE NUM="$1"\/>/g ;

# XML tags are case sensitive:
s/<i>/<I>/g ;
s/<\/i>/<\/I>/g ;
s/<b>/<B>/g ;
s/<\/b>/<\/B>/g ;

#Incomplete markup (missing end tags):
s/(<B>Þórs-ness-lönd,)/$1<\/B>/ ;
s/(<I>to freight a)/$1<\/I>/ ;
s/(n. <I>glottis.)/$1<\/I>/ ;
s/(<I>vigorous,) $/$1<\/I>/ ;
s/(<I>"bis,,) to $/$1<\/I> to/ ;
s/(<I>to draw) $/$1<\/I>/ ;
s/(<I>fatherly) (<PAGE)/$1<\/I>\n\n$2/ ;
s/(<I>into after death,)/$1<\/I>/ ;
s/(<I>rasta = GREEK,<)(I>)/$1\/$2/ ;
s/(<I>unpromising for peace,)/$1<\/I>/ ;
s/(fool, lubber.)/$1<\/I>/ ;
s/(<I>a shrill sound.)/$1<\/I>/ ;
s/(to be held in small repute.)/$1<\/I>/ ;
s/(and needles.\))/$1<\/I>/ ;
s/(<I>the hoof\.)/$1<\/I>/ ;

# Comma should *follow* the B tag:
s/,<\/B>/<\/B>,/g ;

# Insert a wrapper for the entries after the intro:
s/(<\/INTRODUCTION>)/$1\n\n<entries>/ ;

# Insert an opening <e> element at the first entry:
s/(A\. is the first letter)/<e>$1/ ;

# Remove stranded end tags:
s/^<\/I>$//;
s/<\/I> (<B>ánalegr<\/B>)/$1/ ;

print ;
}

print "\n</e>\n";
print "\n</entries>\n";
print "</dictionary>\n";
