#!/usr/bin/perl -w
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  txt2abc - Convert non-ascii text chars to ABC escape sequences
#
#SYNOPSIS
#  txt2abc [file]..
#REQUIRES
#
#DESCRIPTION
#
#OPTIONS
# None yet, but there may be some soon.
#
#EXAMPLES
# The input data (from files or STDIN) is output to STDOUT with non-ASCII
# chars converted to the corresponding ABC escape sequences.
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
binmode STDIN, ':utf8';
#binmode STDOUT, ':utf8';
use open qw(:std :utf8);

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 1;	# Verbose level.

%map = (
   '£'   => '\243',
   'ä'   => '\"a',
   'Ä'   => '\"A',
   'ö'   => '\"o',
   'Ö'   => '\"O',
   'ü'   => '\"u',
   'Ü'   => '\"U',
);

while (<>) {
   $_ =~ s/[\r\s]+$//;     # Trim away white space and linefeed chars
   @ichars = @ochars = split //, $_;
   for ($i=0; $i<int(@ichars); $i++) {
      $c = $ochars[$i];     # Look at one utf-8 "char"
      print "$i: c='$c'\n" if $V>1;
      $r = $map{$c} || '';
      if ($r) {  # Is this one we convert?
         print "$i: '$c' -> '$r' \n" if $V>1;
#        $ochars[$i] = $r;
      }
   }
   print foreach(@ochars), "\n";
   print foreach(@ochars), "\n";
}

exit $exitstat;
