#!/usr/bin/perl -w

#=======================================================================
# $Id: dings_it 11596 2004-10-23 16:58:27Z sunny256 $
# Eat stdin, smack those @ENGLISH* markers around it and send it to 
# stdout. After that, print all the XML elements with all the text 
# outside of the elements removed. Some attempt to automate things a 
# bit.
#
# This complicated piece of software is licensed under the GNU General 
# Public License version 2 or later.
#=======================================================================

use strict;

$| = 1;

use Getopt::Std;
our ($opt_h) = (0);
getopts('h') || die("Option error. Use -h for help.\n");

$opt_h && usage(0);

my $Data = join("", <>);
my $Orig = $Data;
my $Indent = "";

# Save indent for the rest of the lines
$Orig =~ /^(\s+)/ && ($Indent = $1);

# Remove everything except elements
$Data =~ s/>[^<>]+?</></gs;

# Remove line breaks inside elements and replace it with exactly one 
# space.
$Data =~ s/\s*\n\s*[^\S\$]/ /gs;

print("$Indent<!-- \@ENGLISH \x7B\x7B\x7B\n" .
      "$Orig$Indent\@ENGLISH }}} -->\n" .
      "$Data");

sub usage {
    my $Retval = shift;
    print(<<END);

Usage: $0 [file [...]]

Eat stdin, smack those \@ENGLISH* markers around it and send it to 
stdout. After that, print all the XML elements with all the text outside 
of the elements removed. Some attempt to automate things a bit.

END
    exit($Retval);
}

__END__

# vim: set fenc=UTF-8 ts=4 sw=4 sts=4 et fo+=w2 fo-=n :
# vim: set ft=perl fdm=marker fdl=0 :
# End of file $Id: dings_it 11596 2004-10-23 16:58:27Z sunny256 $
