#!/usr/bin/perl
# $File: //member/autrijus/HTML-FromANSI/script/ansi2html $ $Author: autrijus $
# $Revision: #1 $ $Change: 7865 $ $DateTime: 2003/09/04 15:24:44 $

$VERSION = '0.02';

=head1 NAME

ansi2html - Convert ANSI sequence to HTML

=head1 SYNOPSIS

B<ansi2html> S<[ B<-p> ]> S<[ I<infile> ]> S<[ I<outfile> ]>

=head1 DESCRIPTION

This script takes one input file containing text with ANSI sequences,
and outputs the converted HTML code into another file.

If I<outfile> is omitted, it defaults to STDOUT.  If I<infile> is omitted,
it defaults to STDIN.

Note that this script will automatically set the C<fill_cols> option
to 1, filling empty columns with space characters.

If the B<-p> option is specified, it will print HTML header and footers.

=cut

use strict;
use Getopt::Std;
use HTML::FromANSI qw|%Options ansi2html|;

my %args; getopts('p', \%args);
$Options{fill_cols} = 1;

my ($infile, $outfile) = @ARGV;

open IN,  $infile     or die "cannot read $infile: $!"   if $infile;
open OUT, ">$outfile" or die "cannot write $outfile: $!" if $outfile;
select OUT if $outfile;

if ($args{p}) {
    my $title = 'ansi2html' . ($infile ? " - $infile" : '');

    print "<HTML><HEAD><TITLE>$title</TITLE></HEAD><BODY>".
	  ansi2html($infile ? <IN> : <STDIN>).
	  "</BODY></HTML>";
}
else {
    print ansi2html($infile ? <IN> : <STDIN>);
}

exit;

=head1 SEE ALSO

L<HTML::FromANSI>

=head1 AUTHORS

Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>

=head1 COPYRIGHT

Copyright 2001, 2002 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.

This program is free software; you can redistribute it and/or 
modify it under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut
