#! /usr/bin/perl -w
# vim:syntax=perl
use strict;

use lib '/usr/local/share/perl5';

use Getopt::Long;
use Lire::Config;
use Lire::Program qw( :msg tempfile $PROG $LR_SUPERSERVICE $LR_ID );
use Lire::ReportParser::AsciiWriter;

my %opts = ('target-user'  => $ENV{LR_TARGET_USER} || 'sysadmin',
	     userlevel	    => $ENV{LR_USERLEVEL} || 'normal',
	   );
GetOptions( \%opts, "userlevel=s", "target-user=s" ) && @ARGV == 0
  or lr_err( "Usage $PROG [--userlevel normal|advanced] [--target-user sysadmin|manager] < report.xml" );

lr_err( "wrong value for target-user: $opts{'target-user'} (must be either 'sysadmin' or 'manager' )" )
  unless $opts{'target-user'} =~ /^(sysadmin|manager)$/;

lr_err( "wrong value for userlevel: $opts{userlevel} (must be either 'normal' or 'advanced' )" )
  unless $opts{userlevel} =~ /^(normal|advanced)$/;

my $parser = new Lire::ReportParser::AsciiWriter( %opts );
eval {
    $parser->parse(\*STDIN);
};
lr_err( $@ ) if $@;
lr_info( "parsing xml finished" );

exit 0;

__END__

=pod

=head1 NAME

lr_xml2ascii - generate a formatted report from a raw xml report

=head1 SYNOPSIS

B<lr_xml2ascii> 

=head1 DESCRIPTION

B<lr_xml2ascii> reads a raw xml report from stdin, and prints a nicely
formatted ascii report on stdout. Under some circumstances, it's
needed to tweak LD_LIBRARY_PATH and PERL5LIB, in order to enable
Lire::ReportParser to find XML::Parser. Sourcing
${prefix}/etc/lire/defaults tackles all these issues with environment
variables.

This script is run automatically by lr_log2report(1), and, in a client
setup, by lr_rawmail2mail(1).

=head1 SEE ALSO

lr_dlf2xml(1), lr_log2report(1)

=head1 VERSION

$Id: lr_xml2ascii.in,v 1.44 2002/04/13 22:55:16 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2000-2002 Stichting LogReport Foundation LogReport@LogReport.org

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.

=head1 AUTHOR

Egon Willighagen

=cut

# Local Variables:
# mode: cperl
# End:
