#!/usr/bin/perl -s -p

# ansi2latin - filter text to convert ANSI chars 128-159 to Latin-1 visibles
# Steve Kinzler, steve@kinzler.com, Jul 05
# https://kinzler.com/me/home.html#unix

# Gmail text cleanup filter
if ($g) {
	s/^\*\* \*\*$//;
	s/([^*])\*\*\*\*$/$1/;
}

s/&#([1-9]\d*);/chr $1/ge;

s/\360\237\231\202/:-)/g;	# smiley

# other useful (non-ANSI) filterings
s/\033\$B!G\033\(B/'/g;
s/\303([\240-\277])/chr(ord($1) + 64)/ge;	# eg, Atilde \240 => \340
s/\240/ /g;			# nbsp
s/\302\255/-/g;			# Acirc shy
s/\302\260/deg/g;		# Acirc deg
s/\342''/=/g;			# acirc ' '
s/\342\200\223/--/g;		# acirc ~@ ~S
s/\342\200\224/.../g;		# acirc ~@ ~T
s/\342\200\230/'/g;		# acirc ~@ ~X
s/\342\200\231/'/g;		# acirc ~@ ~Y
s/\342\200\234/"/g;		# acirc ~@ ~\
s/\342\200\235/"/g;		# acirc ~@ ~]
s/\342\200\242/*/g;		# acirc ~@ cent
s/\342\200\246/.../g;		# acirc ~@ brvbar
s/\342\224\200/-/g;		# acirc ~T ~@
s/\342\224\202/|/g;		# acirc ~T ~B
s/\342\224\224/+/g;		# acirc ~T ~T
s/\342\224\234/+/g;		# acirc ~T ~\
s/\342\231\200/<female>/g;	# acirc ~Y ~@
s/\342\231\202/<male>/g;	# acirc ~Y ~B

s/\303\205/\305/g;		# Atilde ~E => Aring

# see http://www.fingertipsoft.com/3dkbd/ansitable.html

s/\200/<euro>/g;		# 128 ~@ UNUSED / euro
s/\201/[]/g;			# 129 ~A UNUSED
s/\202/'/g;			# 130 ~B baseline single quote
s/\203/<f>/g;			# 131 ~C florin
s/\204/"/g;			# 132 ~D baseline double quote
s/\205/.../g;			# 133 ~E ellipsis
s/\206/<*>/g;			# 134 ~F dagger (single)
s/\207/<*><*>/g;		# 135 ~G dagger (double)
s/\210/'/g;			# 136 ~H circumflex
s/\211/<0\/00>/g;		# 137 ~I per mil
s/\212/<S_caron>/g;		# 138 ~J S caron
s/\213/</g;			# 139 ~K left single guillemet
s/\214/OE/g;			# 140 ~L OE ligature
s/\215/[]/g;			# 141 ~M UNUSED
s/\216/<Z_caron>/g;		# 142 ~N UNUSED / Z caron
s/\217/[]/g;			# 143 ~O UNUSED
s/\220/[]/g;			# 144 ~P UNUSED
s/\221/'/g;			# 145 ~Q open single quote
s/\222/'/g;			# 146 ~R close single quote
s/\223/"/g;			# 147 ~S open double quote
s/\224/"/g;			# 148 ~T close double quote
s/\225/<\267>/g;		# 149 ~U bullet (large)
s/\226/--/g;			# 150 ~V en dash
s/\227/---/g;			# 151 ~W em dash
s/\230/~/g;			# 152 ~X tilde
s/\231/(TM)/g;			# 153 ~Y unregistered trademark
s/\232/<s_caron>/g;		# 154 ~Z s caron
s/\233/>/g;			# 155 ~[ right single guillemet
s/\234/oe/g;			# 156 ~\ oe ligature
s/\235/[]/g;			# 157 ~] UNUSED
s/\236/<z_caron>/g;		# 158 ~^ UNUSED / z caron
s/\237/<Y:>/g;			# 159 ~_ Y diaeresis
