#!/usr/bin/perl use CGI; sub parse_quoted_line { my ($line,$start_italic,$end_italic) = @_; my $new_line = ""; my $count = 0; my $italic_previous = 0; foreach my $char (split(//,$line)) { if ($char eq "\"") { if ($count % 2 == 1) { $new_line .= "\" " . $start_italic; $italic_previous = 1; } else { $new_line =~ s/\s+$//; $new_line .= $end_italic . " \""; } $count++; } elsif ($char =~ /\s/) { if (!$italic_previous) { $new_line .= " "; } } else { $italic_previous = 0; $new_line .= $char; } } if ($count % 2 != 1) { if ($new_line =~ /$start_italic$/) { $new_line =~ s/$start_italic$//; $new_line =~ s/\s+$//; } else { $new_line =~ s/\s+$//; $new_line .= $end_italic; } } if ($new_line =~ /^$end_italic/) { $new_line =~ s/^$end_italic//; } else { $new_line =~ s/\s+$//; $new_line = $start_italic . $new_line; } return $new_line; } sub normalize_name { my ($name) = @_; $name =~ s/^[\+\@ ]//; $name =~ s/_/ /gs; $name =~ s/^\s+//; $name =~ s/\s+$//; return $name; } my $query = new CGI; my $text = $query->param("text"); if ($query->param("getsourcetext") == 1) { print "Content-Type: text/plain\r\n\r\n"; } else { print "Content-Type: text/html\r\n\r\n" . "
\n"; } open(RD,"<",$ENV{"SCRIPT_FILENAME"}); while (my $line = readline(RD)) { if ($query->param("getsource") == 1) { $line =~ s/&/&/gs; $line =~ s/</gs; $line =~ s/>/>/gs; } print $line; } close(RD); if ($query->param("getsource") == 1) { print ""; } } elsif ($text ne "") { print "
\n";
my $prev_line = "";
my $prev_head = "";
my $out = "";
$text =~ s/(\r|\n)+ //gs;
$eol = "\n"; # End Of Line
$star = "\\\*";
$start_bold = "**";
$end_bold = $start_bold;
$start_italic = "//";
$end_italic = $start_italic;
if ($query->param("output") eq "mediawiki") {
$eol = "\n\n";
$start_bold = "'''";
$end_bold = $start_bold;
$start_italic = "''";
$end_italic = $start_italic;
} elsif ($query->param("output") eq "tumblr") {
$eol = "</p>\n";
$start_bold = "<b>";
$end_bold = "</b>";
$start_italic = "<i>";
$end_italic = "</i>";
} elsif ($query->param("output") eq "text") {
$eol = "\n\n";
$start_bold = "";
$end_bold = "";
$start_italic = "";
$end_italic = "";
}
if ($query->param("input") eq "roll20") {
my $new_text = "";
while ($text =~
/^(.*?)\{\"type\":\"(.*?)\",\"playerid\":\"(.*?)\",\"who\":\"(.*?)\",\"content\":\"(.*?)\"\}(.*)/
) {
my $line_type = $2;
my $line_who = $4;
my $line = $5;
$text = $6;
$line_who =~ s/\\"/"/gs;
$line =~ s/\\"/"/gs;
if ($line_type eq "general") {
$line =~ s/\\"/"/gs;
$new_text .= "<" . $line_who . "> " . $line . "\n";
} elsif ($line_type eq "emote") {
$new_text .= "* " . $line_who . " " . $line . "\n";
} elsif ($line_type eq "rollresult" && $line =~ /(.*?)\|(.*?)\|(.*)/) {
my $dice = $1;
my $roll = $2;
my $result = $3;
$roll =~ s/[{}@#]//gs;
$new_text .= "* " . $line_who . " rolled " . $dice . " and got " .
$roll . "=" . $result . "\n";
}
}
$text = $new_text;
}
foreach my $line (split(/\n/,$text)) {
$out = "";
if ($query->param("input") eq "irc_tags") {
$line =~ s/^(\x03)([0-9,]+)//; # get rid of superfluous start-of-line tags
$line =~
s/(\x03)(00,00)//gs;
$line =~
s/(\x03)(00,01)//gs;
$line =~
s/(\x03)(00,02)//gs;
$line =~
s/(\x03)(00,03)//gs;
$line =~
s/(\x03)(00,04)//gs;
$line =~
s/(\x03)(00,05)//gs;
$line =~
s/(\x03)(00,06)//gs;
$line =~
s/(\x03)(00,07)//gs;
$line =~
s/(\x03)(00,08)//gs;
$line =~
s/(\x03)(00,09)//gs;
$line =~
s/(\x03)(00,10)//gs;
$line =~
s/(\x03)(00,11)//gs;
$line =~
s/(\x03)(00,12)//gs;
$line =~
s/(\x03)(00,13)//gs;
$line =~
s/(\x03)(00,14)//gs;
$line =~
s/(\x03)(00,15)//gs;
$line =~
s/(\x03)(00,0)//gs;
$line =~
s/(\x03)(00,1)//gs;
$line =~
s/(\x03)(00,2)//gs;
$line =~
s/(\x03)(00,3)//gs;
$line =~
s/(\x03)(00,4)//gs;
$line =~
s/(\x03)(00,5)//gs;
$line =~
s/(\x03)(00,6)//gs;
$line =~
s/(\x03)(00,7)//gs;
$line =~
s/(\x03)(00,8)//gs;
$line =~
s/(\x03)(00,9)//gs;
$line =~ s/(\x03)(00)//gs;
$line =~
s/(\x03)(01,00)//gs;
$line =~
s/(\x03)(01,01)//gs;
$line =~
s/(\x03)(01,02)//gs;
$line =~
s/(\x03)(01,03)//gs;
$line =~
s/(\x03)(01,04)//gs;
$line =~
s/(\x03)(01,05)//gs;
$line =~
s/(\x03)(01,06)//gs;
$line =~
s/(\x03)(01,07)//gs;
$line =~
s/(\x03)(01,08)//gs;
$line =~
s/(\x03)(01,09)//gs;
$line =~
s/(\x03)(01,10)//gs;
$line =~
s/(\x03)(01,11)//gs;
$line =~
s/(\x03)(01,12)//gs;
$line =~
s/(\x03)(01,13)//gs;
$line =~
s/(\x03)(01,14)//gs;
$line =~
s/(\x03)(01,15)//gs;
$line =~
s/(\x03)(01,0)//gs;
$line =~
s/(\x03)(01,1)//gs;
$line =~
s/(\x03)(01,2)//gs;
$line =~
s/(\x03)(01,3)//gs;
$line =~
s/(\x03)(01,4)//gs;
$line =~
s/(\x03)(01,5)//gs;
$line =~
s/(\x03)(01,6)//gs;
$line =~
s/(\x03)(01,7)//gs;
$line =~
s/(\x03)(01,8)//gs;
$line =~
s/(\x03)(01,9)//gs;
$line =~ s/(\x03)(01)//gs;
$line =~
s/(\x03)(02,00)//gs;
$line =~
s/(\x03)(02,01)//gs;
$line =~
s/(\x03)(02,02)//gs;
$line =~
s/(\x03)(02,03)//gs;
$line =~
s/(\x03)(02,04)//gs;
$line =~
s/(\x03)(02,05)//gs;
$line =~
s/(\x03)(02,06)//gs;
$line =~
s/(\x03)(02,07)//gs;
$line =~
s/(\x03)(02,08)//gs;
$line =~
s/(\x03)(02,09)//gs;
$line =~
s/(\x03)(02,10)//gs;
$line =~
s/(\x03)(02,11)//gs;
$line =~
s/(\x03)(02,12)//gs;
$line =~
s/(\x03)(02,13)//gs;
$line =~
s/(\x03)(02,14)//gs;
$line =~
s/(\x03)(02,15)//gs;
$line =~
s/(\x03)(02,0)//gs;
$line =~
s/(\x03)(02,1)//gs;
$line =~
s/(\x03)(02,2)//gs;
$line =~
s/(\x03)(02,3)//gs;
$line =~
s/(\x03)(02,4)//gs;
$line =~
s/(\x03)(02,5)//gs;
$line =~
s/(\x03)(02,6)//gs;
$line =~
s/(\x03)(02,7)//gs;
$line =~
s/(\x03)(02,8)//gs;
$line =~
s/(\x03)(02,9)//gs;
$line =~ s/(\x03)(02)//gs;
$line =~
s/(\x03)(03,00)//gs;
$line =~
s/(\x03)(03,01)//gs;
$line =~
s/(\x03)(03,02)//gs;
$line =~
s/(\x03)(03,03)//gs;
$line =~
s/(\x03)(03,04)//gs;
$line =~
s/(\x03)(03,05)//gs;
$line =~
s/(\x03)(03,06)//gs;
$line =~
s/(\x03)(03,07)//gs;
$line =~
s/(\x03)(03,08)//gs;
$line =~
s/(\x03)(03,09)//gs;
$line =~
s/(\x03)(03,10)//gs;
$line =~
s/(\x03)(03,11)//gs;
$line =~
s/(\x03)(03,12)//gs;
$line =~
s/(\x03)(03,13)//gs;
$line =~
s/(\x03)(03,14)//gs;
$line =~
s/(\x03)(03,15)//gs;
$line =~
s/(\x03)(03,0)//gs;
$line =~
s/(\x03)(03,1)//gs;
$line =~
s/(\x03)(03,2)//gs;
$line =~
s/(\x03)(03,3)//gs;
$line =~
s/(\x03)(03,4)//gs;
$line =~
s/(\x03)(03,5)//gs;
$line =~
s/(\x03)(03,6)//gs;
$line =~
s/(\x03)(03,7)//gs;
$line =~
s/(\x03)(03,8)//gs;
$line =~
s/(\x03)(03,9)//gs;
$line =~ s/(\x03)(03)//gs;
$line =~
s/(\x03)(04,00)//gs;
$line =~
s/(\x03)(04,01)//gs;
$line =~
s/(\x03)(04,02)//gs;
$line =~
s/(\x03)(04,03)//gs;
$line =~
s/(\x03)(04,04)//gs;
$line =~
s/(\x03)(04,05)//gs;
$line =~
s/(\x03)(04,06)//gs;
$line =~
s/(\x03)(04,07)//gs;
$line =~
s/(\x03)(04,08)//gs;
$line =~
s/(\x03)(04,09)//gs;
$line =~
s/(\x03)(04,10)//gs;
$line =~
s/(\x03)(04,11)//gs;
$line =~
s/(\x03)(04,12)//gs;
$line =~
s/(\x03)(04,13)//gs;
$line =~
s/(\x03)(04,14)//gs;
$line =~
s/(\x03)(04,15)//gs;
$line =~
s/(\x03)(04,0)//gs;
$line =~
s/(\x03)(04,1)//gs;
$line =~
s/(\x03)(04,2)//gs;
$line =~
s/(\x03)(04,3)//gs;
$line =~
s/(\x03)(04,4)//gs;
$line =~
s/(\x03)(04,5)//gs;
$line =~
s/(\x03)(04,6)//gs;
$line =~
s/(\x03)(04,7)//gs;
$line =~
s/(\x03)(04,8)//gs;
$line =~
s/(\x03)(04,9)//gs;
$line =~ s/(\x03)(04)//gs;
$line =~
s/(\x03)(05,00)//gs;
$line =~
s/(\x03)(05,01)//gs;
$line =~
s/(\x03)(05,02)//gs;
$line =~
s/(\x03)(05,03)//gs;
$line =~
s/(\x03)(05,04)//gs;
$line =~
s/(\x03)(05,05)//gs;
$line =~
s/(\x03)(05,06)//gs;
$line =~
s/(\x03)(05,07)//gs;
$line =~
s/(\x03)(05,08)//gs;
$line =~
s/(\x03)(05,09)//gs;
$line =~
s/(\x03)(05,10)//gs;
$line =~
s/(\x03)(05,11)//gs;
$line =~
s/(\x03)(05,12)//gs;
$line =~
s/(\x03)(05,13)//gs;
$line =~
s/(\x03)(05,14)//gs;
$line =~
s/(\x03)(05,15)//gs;
$line =~
s/(\x03)(05,0)//gs;
$line =~
s/(\x03)(05,1)//gs;
$line =~
s/(\x03)(05,2)//gs;
$line =~
s/(\x03)(05,3)//gs;
$line =~
s/(\x03)(05,4)//gs;
$line =~
s/(\x03)(05,5)//gs;
$line =~
s/(\x03)(05,6)//gs;
$line =~
s/(\x03)(05,7)//gs;
$line =~
s/(\x03)(05,8)//gs;
$line =~
s/(\x03)(05,9)//gs;
$line =~ s/(\x03)(05)//gs;
$line =~
s/(\x03)(06,00)//gs;
$line =~
s/(\x03)(06,01)//gs;
$line =~
s/(\x03)(06,02)//gs;
$line =~
s/(\x03)(06,03)//gs;
$line =~
s/(\x03)(06,04)//gs;
$line =~
s/(\x03)(06,05)//gs;
$line =~
s/(\x03)(06,06)//gs;
$line =~
s/(\x03)(06,07)//gs;
$line =~
s/(\x03)(06,08)//gs;
$line =~
s/(\x03)(06,09)//gs;
$line =~
s/(\x03)(06,10)//gs;
$line =~
s/(\x03)(06,11)//gs;
$line =~
s/(\x03)(06,12)//gs;
$line =~
s/(\x03)(06,13)//gs;
$line =~
s/(\x03)(06,14)//gs;
$line =~
s/(\x03)(06,15)//gs;
$line =~
s/(\x03)(06,0)//gs;
$line =~
s/(\x03)(06,1)//gs;
$line =~
s/(\x03)(06,2)//gs;
$line =~
s/(\x03)(06,3)//gs;
$line =~
s/(\x03)(06,4)//gs;
$line =~
s/(\x03)(06,5)//gs;
$line =~
s/(\x03)(06,6)//gs;
$line =~
s/(\x03)(06,7)//gs;
$line =~
s/(\x03)(06,8)//gs;
$line =~
s/(\x03)(06,9)//gs;
$line =~ s/(\x03)(06)//gs;
$line =~
s/(\x03)(07,00)//gs;
$line =~
s/(\x03)(07,01)//gs;
$line =~
s/(\x03)(07,02)//gs;
$line =~
s/(\x03)(07,03)//gs;
$line =~
s/(\x03)(07,04)//gs;
$line =~
s/(\x03)(07,05)//gs;
$line =~
s/(\x03)(07,06)//gs;
$line =~
s/(\x03)(07,07)//gs;
$line =~
s/(\x03)(07,08)//gs;
$line =~
s/(\x03)(07,09)//gs;
$line =~
s/(\x03)(07,10)//gs;
$line =~
s/(\x03)(07,11)//gs;
$line =~
s/(\x03)(07,12)//gs;
$line =~
s/(\x03)(07,13)//gs;
$line =~
s/(\x03)(07,14)//gs;
$line =~
s/(\x03)(07,15)//gs;
$line =~
s/(\x03)(07,0)//gs;
$line =~
s/(\x03)(07,1)//gs;
$line =~
s/(\x03)(07,2)//gs;
$line =~
s/(\x03)(07,3)//gs;
$line =~
s/(\x03)(07,4)//gs;
$line =~
s/(\x03)(07,5)//gs;
$line =~
s/(\x03)(07,6)//gs;
$line =~
s/(\x03)(07,7)//gs;
$line =~
s/(\x03)(07,8)//gs;
$line =~
s/(\x03)(07,9)//gs;
$line =~ s/(\x03)(07)//gs;
$line =~
s/(\x03)(08,00)//gs;
$line =~
s/(\x03)(08,01)//gs;
$line =~
s/(\x03)(08,02)//gs;
$line =~
s/(\x03)(08,03)//gs;
$line =~
s/(\x03)(08,04)//gs;
$line =~
s/(\x03)(08,05)//gs;
$line =~
s/(\x03)(08,06)//gs;
$line =~
s/(\x03)(08,07)//gs;
$line =~
s/(\x03)(08,08)//gs;
$line =~
s/(\x03)(08,09)//gs;
$line =~
s/(\x03)(08,10)//gs;
$line =~
s/(\x03)(08,11)//gs;
$line =~
s/(\x03)(08,12)//gs;
$line =~
s/(\x03)(08,13)//gs;
$line =~
s/(\x03)(08,14)//gs;
$line =~
s/(\x03)(08,15)//gs;
$line =~
s/(\x03)(08,0)//gs;
$line =~
s/(\x03)(08,1)//gs;
$line =~
s/(\x03)(08,2)//gs;
$line =~
s/(\x03)(08,3)//gs;
$line =~
s/(\x03)(08,4)//gs;
$line =~
s/(\x03)(08,5)//gs;
$line =~
s/(\x03)(08,6)//gs;
$line =~
s/(\x03)(08,7)//gs;
$line =~
s/(\x03)(08,8)//gs;
$line =~
s/(\x03)(08,9)//gs;
$line =~ s/(\x03)(08)//gs;
$line =~
s/(\x03)(09,00)//gs;
$line =~
s/(\x03)(09,01)//gs;
$line =~
s/(\x03)(09,02)//gs;
$line =~
s/(\x03)(09,03)//gs;
$line =~
s/(\x03)(09,04)//gs;
$line =~
s/(\x03)(09,05)//gs;
$line =~
s/(\x03)(09,06)//gs;
$line =~
s/(\x03)(09,07)//gs;
$line =~
s/(\x03)(09,08)//gs;
$line =~
s/(\x03)(09,09)//gs;
$line =~
s/(\x03)(09,10)//gs;
$line =~
s/(\x03)(09,11)/