#!/usr/bin/perl # Script to take an ansi formatted file and generate an HTML file from it. # (c) 2000 Joe Sunday All rights reserved # You may not redistribute any modified versions of this program without # my consent, nor use it for any commercial purposes. # Specifically, you may not use this program if you charge # players for your door games. # # Version 1.0 # print << "HEAD"; $ARGV[0]
HEAD

# Hash table of the non-brite colors. This could probably use some tweaking.

my %clo = (
	"30" => "black",
	"31" => "#ff0000",
	"32" => "green",
        "33" => "brown",  
        "34" => "#0000ff",
        "35" => "magenta",
        "36" => "cyan",
	"37" => "white"
);

# Hash table for the hi colors.
my %chi = (
	"30" => "black",
	"31" => "red",
	"32" => "higreen",
	"33" => "yellow",
	"34" => "#3333ff",
	"35" => "magenta",
	"36" => "hicyan",
	"37" => "white"
);

# Various Status flags and variables

# Bold attribute
my $bold = 0;
my $blink = 0;

#The current foreground and background colors
my $color;
my $bcolor;

while () {
	chop;
	s/\015/\n/g;

	# Pull out an escape code and text.	
        while( m/([^\e]*)\e(\[[\d\;]+)([a-zA-Z])([^\e]*)/g ) {
		$ftag = "";
		$ctag = "";
		my $ptext = $1;
		my $esc = $2 . $3;
		my $code = $3;
		my $text = $4;

		while( $esc =~ m/([\d]+)[\;m]/g ) {
			if( $code == "m" ) {
				if( $1 == 0 ) {  # Reset to normal
					$bold = 0;
					$color = 37;
					$bcolor = 40;
					$blink = 0;
				}
				elsif( $1 == 1 ) { $bold = 1; }
				elsif( $1 == 5 ) { $blink = 1; }
				elsif( $1 >= 40 ) { $bcolor = $1; }
				elsif( $1 >= 30 ) { $color = $1; }
			}

			if( $bold == 0 ) {
				$ftag = "";
				$ctag = "";
			}	
			else {
				$ftag = "";
				$ctag = "";
			}

			if( $bcolor != 40 ) {
				$ftag = "" . $ftag;
				$ctag = $ctag . "";
			}	
			if( $blink ) {
				$ftag = "" . $ftag;
				$ctag = $ctag . "";
			}
		}
		if($ptext || $text) {
			print $ptext, $ftag, $text, $ctag;
		}
	}
}		

print << "TAIL";
TAIL