#!/usr/bin/perl

use CGI; my $CGI = new CGI;
use YAPE::Regex::Explain;

print "Content-Type: text/html\n\n";

my $regex = $CGI->param('regex');
$regex =~ s|^/(.+)/$|$1|;

print <<"EOL";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

	<head>
		<title>Explain Regular Expressions</title>
	</head>

	<body>

		<form method="get">
			Regex: <input type="text" name="regex" size="45" value="$regex"><br>
			<input type="submit" value="Explain">
		</form>
EOL

if($regex){
	print "<hr>\n";
	my $parser = YAPE::Regex::Explain->new($regex);
	my $explaination = $parser->explain();
	my @explaination = split(/\n-+\n/, $explaination);
	splice( @explaination, 1, 1 );
	splice( @explaination, -1 );
	$explaination = join("\n" . ('-' x 80) . "\n", @explaination);
	$explaination =~ s/^.+?matches as follows://s;
	$explaination =~ s/</&lt;/g;
	$explaination =~ s/>/&gt;/g;
	$explaination =~ s/"/&quot;/g;
	print "<pre>" . $explaination . "</pre>"
}

print <<"EOL";

	</body>
</html>
EOL

