#!/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" . "Log Convertor\n" . "HTML Source Code\n" . "Text Source Code
\n" . "Copy and paste log here:\n" . "
" . "
\n" . "Output format: " . " Wikispaces Wikidot " . " Mediawiki Tumblr Plain Text
\nInput format: IRC (ignore color/bold) IRC (parse color/bold) Skype Roll20 "var messages = ..."\n
" . "(Note: IRC color/bold tags must be completely inside, or completely " . "outside,\ncolor tags)
\n" . "
\nNote: if you are using a logging tool that has never been " . "tested with\nthis convertor before, check the converted logs for " . "possible bugs. It\nis not this tool's provider's fault if you delete " . "your logs after a bad\nconversion, losing the record of what you wished " . "to post.\n"; } if ($query->param("getsource") == 1 || $query->param("getsourcetext") == 1) { if ($query->param("getsource") == 1) { print "
\n";
  }
  open(RD,"<",$ENV{"SCRIPT_FILENAME"});
  while (my $line = readline(RD)) {
    if ($query->param("getsource") == 1) {
      $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)//gs;
      $line =~
    s/(\x03)(09,12)//gs;
      $line =~
    s/(\x03)(09,13)//gs;
      $line =~
    s/(\x03)(09,14)//gs;
      $line =~
    s/(\x03)(09,15)//gs;
      $line =~
    s/(\x03)(09,0)//gs;
      $line =~
    s/(\x03)(09,1)//gs;
      $line =~
    s/(\x03)(09,2)//gs;
      $line =~
    s/(\x03)(09,3)//gs;
      $line =~
    s/(\x03)(09,4)//gs;
      $line =~
    s/(\x03)(09,5)//gs;
      $line =~
    s/(\x03)(09,6)//gs;
      $line =~
    s/(\x03)(09,7)//gs;
      $line =~
    s/(\x03)(09,8)//gs;
      $line =~
    s/(\x03)(09,9)//gs;
      $line =~ s/(\x03)(09)//gs;
      $line =~
    s/(\x03)(10,00)//gs;
      $line =~
    s/(\x03)(10,01)//gs;
      $line =~
    s/(\x03)(10,02)//gs;
      $line =~
    s/(\x03)(10,03)//gs;
      $line =~
    s/(\x03)(10,04)//gs;
      $line =~
    s/(\x03)(10,05)//gs;
      $line =~
    s/(\x03)(10,06)//gs;
      $line =~
    s/(\x03)(10,07)//gs;
      $line =~
    s/(\x03)(10,08)//gs;
      $line =~
    s/(\x03)(10,09)//gs;
      $line =~
    s/(\x03)(10,10)//gs;
      $line =~
    s/(\x03)(10,11)//gs;
      $line =~
    s/(\x03)(10,12)//gs;
      $line =~
    s/(\x03)(10,13)//gs;
      $line =~
    s/(\x03)(10,14)//gs;
      $line =~
    s/(\x03)(10,15)//gs;
      $line =~
    s/(\x03)(10,0)//gs;
      $line =~
    s/(\x03)(10,1)//gs;
      $line =~
    s/(\x03)(10,2)//gs;
      $line =~
    s/(\x03)(10,3)//gs;
      $line =~
    s/(\x03)(10,4)//gs;
      $line =~
    s/(\x03)(10,5)//gs;
      $line =~
    s/(\x03)(10,6)//gs;
      $line =~
    s/(\x03)(10,7)//gs;
      $line =~
    s/(\x03)(10,8)//gs;
      $line =~
    s/(\x03)(10,9)//gs;
      $line =~ s/(\x03)(10)//gs;
      $line =~
    s/(\x03)(11,00)//gs;
      $line =~
    s/(\x03)(11,01)//gs;
      $line =~
    s/(\x03)(11,02)//gs;
      $line =~
    s/(\x03)(11,03)//gs;
      $line =~
    s/(\x03)(11,04)//gs;
      $line =~
    s/(\x03)(11,05)//gs;
      $line =~
    s/(\x03)(11,06)//gs;
      $line =~
    s/(\x03)(11,07)//gs;
      $line =~
    s/(\x03)(11,08)//gs;
      $line =~
    s/(\x03)(11,09)//gs;
      $line =~
    s/(\x03)(11,10)//gs;
      $line =~
    s/(\x03)(11,11)//gs;
      $line =~
    s/(\x03)(11,12)//gs;
      $line =~
    s/(\x03)(11,13)//gs;
      $line =~
    s/(\x03)(11,14)//gs;
      $line =~
    s/(\x03)(11,15)//gs;
      $line =~
    s/(\x03)(11,0)//gs;
      $line =~
    s/(\x03)(11,1)//gs;
      $line =~
    s/(\x03)(11,2)//gs;
      $line =~
    s/(\x03)(11,3)//gs;
      $line =~
    s/(\x03)(11,4)//gs;
      $line =~
    s/(\x03)(11,5)//gs;
      $line =~
    s/(\x03)(11,6)//gs;
      $line =~
    s/(\x03)(11,7)//gs;
      $line =~
    s/(\x03)(11,8)//gs;
      $line =~
    s/(\x03)(11,9)//gs;
      $line =~ s/(\x03)(11)//gs;
      $line =~
    s/(\x03)(12,00)//gs;
      $line =~
    s/(\x03)(12,01)//gs;
      $line =~
    s/(\x03)(12,02)//gs;
      $line =~
    s/(\x03)(12,03)//gs;
      $line =~
    s/(\x03)(12,04)//gs;
      $line =~
    s/(\x03)(12,05)//gs;
      $line =~
    s/(\x03)(12,06)//gs;
      $line =~
    s/(\x03)(12,07)//gs;
      $line =~
    s/(\x03)(12,08)//gs;
      $line =~
    s/(\x03)(12,09)//gs;
      $line =~
    s/(\x03)(12,10)//gs;
      $line =~
    s/(\x03)(12,11)//gs;
      $line =~
    s/(\x03)(12,12)//gs;
      $line =~
    s/(\x03)(12,13)//gs;
      $line =~
    s/(\x03)(12,14)//gs;
      $line =~
    s/(\x03)(12,15)//gs;
      $line =~
    s/(\x03)(12,0)//gs;
      $line =~
    s/(\x03)(12,1)//gs;
      $line =~
    s/(\x03)(12,2)//gs;
      $line =~
    s/(\x03)(12,3)//gs;
      $line =~
    s/(\x03)(12,4)//gs;
      $line =~
    s/(\x03)(12,5)//gs;
      $line =~
    s/(\x03)(12,6)//gs;
      $line =~
    s/(\x03)(12,7)//gs;
      $line =~
    s/(\x03)(12,8)//gs;
      $line =~
    s/(\x03)(12,9)//gs;
      $line =~ s/(\x03)(12)//gs;
      $line =~
    s/(\x03)(13,00)//gs;
      $line =~
    s/(\x03)(13,01)//gs;
      $line =~
    s/(\x03)(13,02)//gs;
      $line =~
    s/(\x03)(13,03)//gs;
      $line =~
    s/(\x03)(13,04)//gs;
      $line =~
    s/(\x03)(13,05)//gs;
      $line =~
    s/(\x03)(13,06)//gs;
      $line =~
    s/(\x03)(13,07)//gs;
      $line =~
    s/(\x03)(13,08)//gs;
      $line =~
    s/(\x03)(13,09)//gs;
      $line =~
    s/(\x03)(13,10)//gs;
      $line =~
    s/(\x03)(13,11)//gs;
      $line =~
    s/(\x03)(13,12)//gs;
      $line =~
    s/(\x03)(13,13)//gs;
      $line =~
    s/(\x03)(13,14)//gs;
      $line =~
    s/(\x03)(13,15)//gs;
      $line =~
    s/(\x03)(13,0)//gs;
      $line =~
    s/(\x03)(13,1)//gs;
      $line =~
    s/(\x03)(13,2)//gs;
      $line =~
    s/(\x03)(13,3)//gs;
      $line =~
    s/(\x03)(13,4)//gs;
      $line =~
    s/(\x03)(13,5)//gs;
      $line =~
    s/(\x03)(13,6)//gs;
      $line =~
    s/(\x03)(13,7)//gs;
      $line =~
    s/(\x03)(13,8)//gs;
      $line =~
    s/(\x03)(13,9)//gs;
      $line =~ s/(\x03)(13)//gs;
      $line =~
    s/(\x03)(14,00)//gs;
      $line =~
    s/(\x03)(14,01)//gs;
      $line =~
    s/(\x03)(14,02)//gs;
      $line =~
    s/(\x03)(14,03)//gs;
      $line =~
    s/(\x03)(14,04)//gs;
      $line =~
    s/(\x03)(14,05)//gs;
      $line =~
    s/(\x03)(14,06)//gs;
      $line =~
    s/(\x03)(14,07)//gs;
      $line =~
    s/(\x03)(14,08)//gs;
      $line =~
    s/(\x03)(14,09)//gs;
      $line =~
    s/(\x03)(14,10)//gs;
      $line =~
    s/(\x03)(14,11)//gs;
      $line =~
    s/(\x03)(14,12)//gs;
      $line =~
    s/(\x03)(14,13)//gs;
      $line =~
    s/(\x03)(14,14)//gs;
      $line =~
    s/(\x03)(14,15)//gs;
      $line =~
    s/(\x03)(14,0)//gs;
      $line =~
    s/(\x03)(14,1)//gs;
      $line =~
    s/(\x03)(14,2)//gs;
      $line =~
    s/(\x03)(14,3)//gs;
      $line =~
    s/(\x03)(14,4)//gs;
      $line =~
    s/(\x03)(14,5)//gs;
      $line =~
    s/(\x03)(14,6)//gs;
      $line =~
    s/(\x03)(14,7)//gs;
      $line =~
    s/(\x03)(14,8)//gs;
      $line =~
    s/(\x03)(14,9)//gs;
      $line =~ s/(\x03)(14)//gs;
      $line =~
    s/(\x03)(15,00)//gs;
      $line =~
    s/(\x03)(15,01)//gs;
      $line =~
    s/(\x03)(15,02)//gs;
      $line =~
    s/(\x03)(15,03)//gs;
      $line =~
    s/(\x03)(15,04)//gs;
      $line =~
    s/(\x03)(15,05)//gs;
      $line =~
    s/(\x03)(15,06)//gs;
      $line =~
    s/(\x03)(15,07)//gs;
      $line =~
    s/(\x03)(15,08)//gs;
      $line =~
    s/(\x03)(15,09)//gs;
      $line =~
    s/(\x03)(15,10)//gs;
      $line =~
    s/(\x03)(15,11)//gs;
      $line =~
    s/(\x03)(15,12)//gs;
      $line =~
    s/(\x03)(15,13)//gs;
      $line =~
    s/(\x03)(15,14)//gs;
      $line =~
    s/(\x03)(15,15)//gs;
      $line =~
    s/(\x03)(15,0)//gs;
      $line =~
    s/(\x03)(15,1)//gs;
      $line =~
    s/(\x03)(15,2)//gs;
      $line =~
    s/(\x03)(15,3)//gs;
      $line =~
    s/(\x03)(15,4)//gs;
      $line =~
    s/(\x03)(15,5)//gs;
      $line =~
    s/(\x03)(15,6)//gs;
      $line =~
    s/(\x03)(15,7)//gs;
      $line =~
    s/(\x03)(15,8)//gs;
      $line =~
    s/(\x03)(15,9)//gs;
      $line =~ s/(\x03)(15)//gs;
      $line =~
    s/(\x03)(0,00)//gs;
      $line =~
    s/(\x03)(0,01)//gs;
      $line =~
    s/(\x03)(0,02)//gs;
      $line =~
    s/(\x03)(0,03)//gs;
      $line =~
    s/(\x03)(0,04)//gs;
      $line =~
    s/(\x03)(0,05)//gs;
      $line =~
    s/(\x03)(0,06)//gs;
      $line =~
    s/(\x03)(0,07)//gs;
      $line =~
    s/(\x03)(0,08)//gs;
      $line =~
    s/(\x03)(0,09)//gs;
      $line =~
    s/(\x03)(0,10)//gs;
      $line =~
    s/(\x03)(0,11)//gs;
      $line =~
    s/(\x03)(0,12)//gs;
      $line =~
    s/(\x03)(0,13)//gs;
      $line =~
    s/(\x03)(0,14)//gs;
      $line =~
    s/(\x03)(0,15)//gs;
      $line =~
    s/(\x03)(0,0)//gs;
      $line =~
    s/(\x03)(0,1)//gs;
      $line =~
    s/(\x03)(0,2)//gs;
      $line =~
    s/(\x03)(0,3)//gs;
      $line =~
    s/(\x03)(0,4)//gs;
      $line =~
    s/(\x03)(0,5)//gs;
      $line =~
    s/(\x03)(0,6)//gs;
      $line =~
    s/(\x03)(0,7)//gs;
      $line =~
    s/(\x03)(0,8)//gs;
      $line =~
    s/(\x03)(0,9)//gs;
      $line =~ s/(\x03)(0)//gs;
      $line =~
    s/(\x03)(1,00)//gs;
      $line =~
    s/(\x03)(1,01)//gs;
      $line =~
    s/(\x03)(1,02)//gs;
      $line =~
    s/(\x03)(1,03)//gs;
      $line =~
    s/(\x03)(1,04)//gs;
      $line =~
    s/(\x03)(1,05)//gs;
      $line =~
    s/(\x03)(1,06)//gs;
      $line =~
    s/(\x03)(1,07)//gs;
      $line =~
    s/(\x03)(1,08)//gs;
      $line =~
    s/(\x03)(1,09)//gs;
      $line =~
    s/(\x03)(1,10)//gs;
      $line =~
    s/(\x03)(1,11)//gs;
      $line =~
    s/(\x03)(1,12)//gs;
      $line =~
    s/(\x03)(1,13)//gs;
      $line =~
    s/(\x03)(1,14)//gs;
      $line =~
    s/(\x03)(1,15)//gs;
      $line =~
    s/(\x03)(1,0)//gs;
      $line =~
    s/(\x03)(1,1)//gs;
      $line =~
    s/(\x03)(1,2)//gs;
      $line =~
    s/(\x03)(1,3)//gs;
      $line =~
    s/(\x03)(1,4)//gs;
      $line =~
    s/(\x03)(1,5)//gs;
      $line =~
    s/(\x03)(1,6)//gs;
      $line =~
    s/(\x03)(1,7)//gs;
      $line =~
    s/(\x03)(1,8)//gs;
      $line =~
    s/(\x03)(1,9)//gs;
      $line =~ s/(\x03)(1)//gs;
      $line =~
    s/(\x03)(2,00)//gs;
      $line =~
    s/(\x03)(2,01)//gs;
      $line =~
    s/(\x03)(2,02)//gs;
      $line =~
    s/(\x03)(2,03)//gs;
      $line =~
    s/(\x03)(2,04)//gs;
      $line =~
    s/(\x03)(2,05)//gs;
      $line =~
    s/(\x03)(2,06)//gs;
      $line =~
    s/(\x03)(2,07)//gs;
      $line =~
    s/(\x03)(2,08)//gs;
      $line =~
    s/(\x03)(2,09)//gs;
      $line =~
    s/(\x03)(2,10)//gs;
      $line =~
    s/(\x03)(2,11)//gs;
      $line =~
    s/(\x03)(2,12)//gs;
      $line =~
    s/(\x03)(2,13)//gs;
      $line =~
    s/(\x03)(2,14)//gs;
      $line =~
    s/(\x03)(2,15)//gs;
      $line =~
    s/(\x03)(2,0)//gs;
      $line =~
    s/(\x03)(2,1)//gs;
      $line =~
    s/(\x03)(2,2)//gs;
      $line =~
    s/(\x03)(2,3)//gs;
      $line =~
    s/(\x03)(2,4)//gs;
      $line =~
    s/(\x03)(2,5)//gs;
      $line =~
    s/(\x03)(2,6)//gs;
      $line =~
    s/(\x03)(2,7)//gs;
      $line =~
    s/(\x03)(2,8)//gs;
      $line =~
    s/(\x03)(2,9)//gs;
      $line =~ s/(\x03)(2)//gs;
      $line =~
    s/(\x03)(3,00)//gs;
      $line =~
    s/(\x03)(3,01)//gs;
      $line =~
    s/(\x03)(3,02)//gs;
      $line =~
    s/(\x03)(3,03)//gs;
      $line =~
    s/(\x03)(3,04)//gs;
      $line =~
    s/(\x03)(3,05)//gs;
      $line =~
    s/(\x03)(3,06)//gs;
      $line =~
    s/(\x03)(3,07)//gs;
      $line =~
    s/(\x03)(3,08)//gs;
      $line =~
    s/(\x03)(3,09)//gs;
      $line =~
    s/(\x03)(3,10)//gs;
      $line =~
    s/(\x03)(3,11)//gs;
      $line =~
    s/(\x03)(3,12)//gs;
      $line =~
    s/(\x03)(3,13)//gs;
      $line =~
    s/(\x03)(3,14)//gs;
      $line =~
    s/(\x03)(3,15)//gs;
      $line =~
    s/(\x03)(3,0)//gs;
      $line =~
    s/(\x03)(3,1)//gs;
      $line =~
    s/(\x03)(3,2)//gs;
      $line =~
    s/(\x03)(3,3)//gs;
      $line =~
    s/(\x03)(3,4)//gs;
      $line =~
    s/(\x03)(3,5)//gs;
      $line =~
    s/(\x03)(3,6)//gs;
      $line =~
    s/(\x03)(3,7)//gs;
      $line =~
    s/(\x03)(3,8)//gs;
      $line =~
    s/(\x03)(3,9)//gs;
      $line =~ s/(\x03)(3)//gs;
      $line =~
    s/(\x03)(4,00)//gs;
      $line =~
    s/(\x03)(4,01)//gs;
      $line =~
    s/(\x03)(4,02)//gs;
      $line =~
    s/(\x03)(4,03)//gs;
      $line =~
    s/(\x03)(4,04)//gs;
      $line =~
    s/(\x03)(4,05)//gs;
      $line =~
    s/(\x03)(4,06)//gs;
      $line =~
    s/(\x03)(4,07)//gs;
      $line =~
    s/(\x03)(4,08)//gs;
      $line =~
    s/(\x03)(4,09)//gs;
      $line =~
    s/(\x03)(4,10)//gs;
      $line =~
    s/(\x03)(4,11)//gs;
      $line =~
    s/(\x03)(4,12)//gs;
      $line =~
    s/(\x03)(4,13)//gs;
      $line =~
    s/(\x03)(4,14)//gs;
      $line =~
    s/(\x03)(4,15)//gs;
      $line =~
    s/(\x03)(4,0)//gs;
      $line =~
    s/(\x03)(4,1)//gs;
      $line =~
    s/(\x03)(4,2)//gs;
      $line =~
    s/(\x03)(4,3)//gs;
      $line =~
    s/(\x03)(4,4)//gs;
      $line =~
    s/(\x03)(4,5)//gs;
      $line =~
    s/(\x03)(4,6)//gs;
      $line =~
    s/(\x03)(4,7)//gs;
      $line =~
    s/(\x03)(4,8)//gs;
      $line =~
    s/(\x03)(4,9)//gs;
      $line =~ s/(\x03)(4)//gs;
      $line =~
    s/(\x03)(5,00)//gs;
      $line =~
    s/(\x03)(5,01)//gs;
      $line =~
    s/(\x03)(5,02)//gs;
      $line =~
    s/(\x03)(5,03)//gs;
      $line =~
    s/(\x03)(5,04)//gs;
      $line =~
    s/(\x03)(5,05)//gs;
      $line =~
    s/(\x03)(5,06)//gs;
      $line =~
    s/(\x03)(5,07)//gs;
      $line =~
    s/(\x03)(5,08)//gs;
      $line =~
    s/(\x03)(5,09)//gs;
      $line =~
    s/(\x03)(5,10)//gs;
      $line =~
    s/(\x03)(5,11)//gs;
      $line =~
    s/(\x03)(5,12)//gs;
      $line =~
    s/(\x03)(5,13)//gs;
      $line =~
    s/(\x03)(5,14)//gs;
      $line =~
    s/(\x03)(5,15)//gs;
      $line =~
    s/(\x03)(5,0)//gs;
      $line =~
    s/(\x03)(5,1)//gs;
      $line =~
    s/(\x03)(5,2)//gs;
      $line =~
    s/(\x03)(5,3)//gs;
      $line =~
    s/(\x03)(5,4)//gs;
      $line =~
    s/(\x03)(5,5)//gs;
      $line =~
    s/(\x03)(5,6)//gs;
      $line =~
    s/(\x03)(5,7)//gs;
      $line =~
    s/(\x03)(5,8)//gs;
      $line =~
    s/(\x03)(5,9)//gs;
      $line =~ s/(\x03)(5)//gs;
      $line =~
    s/(\x03)(6,00)//gs;
      $line =~
    s/(\x03)(6,01)//gs;
      $line =~
    s/(\x03)(6,02)//gs;
      $line =~
    s/(\x03)(6,03)//gs;
      $line =~
    s/(\x03)(6,04)//gs;
      $line =~
    s/(\x03)(6,05)//gs;
      $line =~
    s/(\x03)(6,06)//gs;
      $line =~
    s/(\x03)(6,07)//gs;
      $line =~
    s/(\x03)(6,08)//gs;
      $line =~
    s/(\x03)(6,09)//gs;
      $line =~
    s/(\x03)(6,10)//gs;
      $line =~
    s/(\x03)(6,11)//gs;
      $line =~
    s/(\x03)(6,12)//gs;
      $line =~
    s/(\x03)(6,13)//gs;
      $line =~
    s/(\x03)(6,14)//gs;
      $line =~
    s/(\x03)(6,15)//gs;
      $line =~
    s/(\x03)(6,0)//gs;
      $line =~
    s/(\x03)(6,1)//gs;
      $line =~
    s/(\x03)(6,2)//gs;
      $line =~
    s/(\x03)(6,3)//gs;
      $line =~
    s/(\x03)(6,4)//gs;
      $line =~
    s/(\x03)(6,5)//gs;
      $line =~
    s/(\x03)(6,6)//gs;
      $line =~
    s/(\x03)(6,7)//gs;
      $line =~
    s/(\x03)(6,8)//gs;
      $line =~
    s/(\x03)(6,9)//gs;
      $line =~ s/(\x03)(6)//gs;
      $line =~
    s/(\x03)(7,00)//gs;
      $line =~
    s/(\x03)(7,01)//gs;
      $line =~
    s/(\x03)(7,02)//gs;
      $line =~
    s/(\x03)(7,03)//gs;
      $line =~
    s/(\x03)(7,04)//gs;
      $line =~
    s/(\x03)(7,05)//gs;
      $line =~
    s/(\x03)(7,06)//gs;
      $line =~
    s/(\x03)(7,07)//gs;
      $line =~
    s/(\x03)(7,08)//gs;
      $line =~
    s/(\x03)(7,09)//gs;
      $line =~
    s/(\x03)(7,10)//gs;
      $line =~
    s/(\x03)(7,11)//gs;
      $line =~
    s/(\x03)(7,12)//gs;
      $line =~
    s/(\x03)(7,13)//gs;
      $line =~
    s/(\x03)(7,14)//gs;
      $line =~
    s/(\x03)(7,15)//gs;
      $line =~
    s/(\x03)(7,0)//gs;
      $line =~
    s/(\x03)(7,1)//gs;
      $line =~
    s/(\x03)(7,2)//gs;
      $line =~
    s/(\x03)(7,3)//gs;
      $line =~
    s/(\x03)(7,4)//gs;
      $line =~
    s/(\x03)(7,5)//gs;
      $line =~
    s/(\x03)(7,6)//gs;
      $line =~
    s/(\x03)(7,7)//gs;
      $line =~
    s/(\x03)(7,8)//gs;
      $line =~
    s/(\x03)(7,9)//gs;
      $line =~ s/(\x03)(7)//gs;
      $line =~
    s/(\x03)(8,00)//gs;
      $line =~
    s/(\x03)(8,01)//gs;
      $line =~
    s/(\x03)(8,02)//gs;
      $line =~
    s/(\x03)(8,03)//gs;
      $line =~
    s/(\x03)(8,04)//gs;
      $line =~
    s/(\x03)(8,05)//gs;
      $line =~
    s/(\x03)(8,06)//gs;
      $line =~
    s/(\x03)(8,07)//gs;
      $line =~
    s/(\x03)(8,08)//gs;
      $line =~
    s/(\x03)(8,09)//gs;
      $line =~
    s/(\x03)(8,10)//gs;
      $line =~
    s/(\x03)(8,11)//gs;
      $line =~
    s/(\x03)(8,12)//gs;
      $line =~
    s/(\x03)(8,13)//gs;
      $line =~
    s/(\x03)(8,14)//gs;
      $line =~
    s/(\x03)(8,15)//gs;
      $line =~
    s/(\x03)(8,0)//gs;
      $line =~
    s/(\x03)(8,1)//gs;
      $line =~
    s/(\x03)(8,2)//gs;
      $line =~
    s/(\x03)(8,3)//gs;
      $line =~
    s/(\x03)(8,4)//gs;
      $line =~
    s/(\x03)(8,5)//gs;
      $line =~
    s/(\x03)(8,6)//gs;
      $line =~
    s/(\x03)(8,7)//gs;
      $line =~
    s/(\x03)(8,8)//gs;
      $line =~
    s/(\x03)(8,9)//gs;
      $line =~ s/(\x03)(8)//gs;
      $line =~
    s/(\x03)(9,00)//gs;
      $line =~
    s/(\x03)(9,01)//gs;
      $line =~
    s/(\x03)(9,02)//gs;
      $line =~
    s/(\x03)(9,03)//gs;
      $line =~
    s/(\x03)(9,04)//gs;
      $line =~
    s/(\x03)(9,05)//gs;
      $line =~
    s/(\x03)(9,06)//gs;
      $line =~
    s/(\x03)(9,07)//gs;
      $line =~
    s/(\x03)(9,08)//gs;
      $line =~
    s/(\x03)(9,09)//gs;
      $line =~
    s/(\x03)(9,10)//gs;
      $line =~
    s/(\x03)(9,11)//gs;
      $line =~
    s/(\x03)(9,12)//gs;
      $line =~
    s/(\x03)(9,13)//gs;
      $line =~
    s/(\x03)(9,14)//gs;
      $line =~
    s/(\x03)(9,15)//gs;
      $line =~
    s/(\x03)(9,0)//gs;
      $line =~
    s/(\x03)(9,1)//gs;
      $line =~
    s/(\x03)(9,2)//gs;
      $line =~
    s/(\x03)(9,3)//gs;
      $line =~
    s/(\x03)(9,4)//gs;
      $line =~
    s/(\x03)(9,5)//gs;
      $line =~
    s/(\x03)(9,6)//gs;
      $line =~
    s/(\x03)(9,7)//gs;
      $line =~
    s/(\x03)(9,8)//gs;
      $line =~
    s/(\x03)(9,9)//gs;
      $line =~ s/(\x03)(9)//gs;
      $line =~ s/(\x0f)/<\/span>/gs;
      $tagnum = 0;
      while ($line =~ /^(.*?)(\x02)(.*)$/s) {
        if ($tagnum == 0) {
          $out .= $1 . "";
          $tagnum = 1;
        } else {
          $out .= $1 . "";
          $tagnum = 0;
        }
        $line = $3;
      }
      $line = $out . $line;
      $out = "";
      $line =~ s/(\x03)(\d{1,2})(,\d{1,2})?//gs; # strip out extra color tags
      $line =~ s/(\x03)/<\/span>/gs;
      if ($line =~ /<\/span>/) {
        my @lineparts = split(/<\/span>/,$line);
        for (my $i = 0;$i < $#lineparts;$i++) {
          while ($lineparts[$i] !~ /",@lineparts);
      }
    } else {
      $line =~ s/(\x03)(\d{1,2})?(,\d{1,2})?//gs; # strip out color tags
      $line =~ s/(\x03)//gs; # strip out color tags
      $line =~ s/(\x0f)//gs; # strip out color tags
      $line =~ s/(\x02)//gs; # strip out bold tags
    }
    if ($query->param("input") eq "skype") {
      if ($line =~ /^(\s*\[[0-9:\/\| A-Za-z]+\] .*?\:\s*)/) {
        $prev_head = $1;
      } elsif ($line =~ /\S/) {
        $line = $prev_head . $line;
      }
      $line =~ s/^\s*\[[0-9:\/ APM]+\] (.*?)\:/\<$1\>/;
    }
    $line =~ s/\x{2026}/.../gs; # translate UTF-16 ellipsis to ASCII ellipsis
    $line =~ s/\x{e2}\x{80}\x{a6}/.../gs; # same translation in UTF-8
    $line =~ s/(-)+/-/gs; # get rid of log-breaking multiple -s
    $line =~ s/(_)+/_/gs; # get rid of log-breaking multiple _s
    $line =~ s/^(\s*)((\(|\[)?)(\d+):(\d+)(:(\d+))?( AM)?( PM)?((\)|\])?)//gs;
    # remove time stamps
    $line =~ s/^(\s*)[A-Z][a-z][a-z] (\d+) (\d+):(\d+)(:(\d+))?( AM)?( PM)?//gs;
    # remove time stamps
    $line =~ s/^ \*\*\*(\S*?) /$1 /; # convert GAIM actions and...
    $line =~ s/^ (\S*?):/<$1>/; # ...GAIM who-says to MIRC format for processing
    if ($query->param("output") eq "wikispaces" ||
        $query->param("output") eq "wikidot") {
      $line =~ s/\//``\/``/gs; # get rid of log-breaking /s
      $line =~ s/\*/``*``/gs; # get rid of log-breaking *s
      $star = "``\\\*``";
    }
    $line =~ s/\~/``~``/gs; # get rid of log-breaking ~s
    $line =~ s/=/``=``/gs; # get rid of log-breaking =s
    $line =~ s/&/&/gs;
    $line =~ s//>/gs;
    $line =~ s/\x02//gs;
    $line =~ s/\x03//gs;
    if ($query->param("output") ne "mediawiki") {
      $line =~ s/<``\/``span>/\x02\/span\x03/gs;
    } else {
      $line =~ s/<``\/``span>/\x02``\/``span\x03/gs;
    }
    $line =~
s/<span style``=``"(.+?)">/\x02span style="$1" \x03/gs;
    $line =~ s/\<(.*?)\`\>/\<$1\>/gs;
    $line =~ s/\<([\+\@ ])(.*?)\>/\<$2\>/gs;
    $line =~ s/\<Kagami\>/\<Sugarlips\>/gs; # Kagami = another Slips
    $line =~ s/\<\^Kagami\>/\<Sugarlips\>/gs; # ditto ^Kagami
    $line =~ s/\<RoboYamo\>/\<Sugarlips\>/gs; # ditto RoboYamo
    $line =~ s/\<RoboYamo\d\>/\<Sugarlips\>/gs; # ditto RoboYamoN
    $line =~ s/\<Sugarlips`\>/\<Sugarlips\>/gs; # ditto Sugarlips`
    $line =~ s/\<Chessa(_+)\>/\<Chessa\>/gs; # Chessa aliases
    $line =~ s/\<WinterFortune\>/\<Chessa\>/gs; # Chessa aliases
    $line =~ s/\<RichterBelmont\>/\<DiceMaid-9001\>/gs; # and so on
    $line =~ s/\<HigginsvonHiggins\>/\<DiceMaid-9001\>/gs; # etc.
    if (($prev_line ne "") && ($line =~ /\<(.*?)\> cut-\>(.*)/)) {
      $line = $prev_line . $2;
      $prev_line = "";
    }
    $line =~ s/````//gs;
    $line =~ s/^(\s+)//gs;
    $line =~ s/(\s+)$//gs;
    $line =~ s/(\s+)/ /gs;
    if ($line =~ /^(.*) \<-cut$/) {
      $prev_line = $1;
    } elsif ($line =~ /^(\s*)$/) {
      # nothing, so ignore
    } elsif ($line =~ /^\<\#(\S+)\> /) {
      # system command (GAIM): ignore
    } elsif ($line =~ /^\-\!\-\s/) {
      # system command (Chessa): ignore
    } elsif ($line =~ /^(.*?)\<(.*?)\>(\s+)\(\((.*)\)\)(\s*)$/) {
      my $name = $2;
      $line = $4;
      $name = normalize_name($name);
      $out = "[OOC] " . $name . ": " . $line;
    } elsif ($line =~ /^(.*?)\<(.*?)\>(\s+)\(\((.*)$/) {
      my $name = $2;
      $line = $4;
      $name = normalize_name($name);
      $out = "[OOC] " . $name . ": " . $line;
    } elsif ($line =~ /^(.*?)\<(.*?)\>(\s+)\[(.*)\](\s*)$/) {
      my $name = $2;
      $line = $4;
      $name = normalize_name($name);
      $out = "[OOC] " . $name . ": " . $line;
    } elsif ($line =~ /^(.*?)\<(.*?)\>(\s+)\[(.*)$/) {
      my $name = $2;
      $line = $4;
      $name = normalize_name($name);
      $out = "[OOC] " . $name . ": " . $line;
    } elsif ($line =~ /^(.*)\<(.*?)\>(\s+)\.([a-z])/) {
      # .roll or similar command: ignore
    } elsif ($line =~ /^(.*)\<(.*?)\>(\s+)\!([a-z])/) {
      # !roll or similar command: ignore
    } elsif ($line =~ /^(.*)\<(.*?)\>(\s+)\@([a-z])/) {
      # @roll or similar command: ignore
    } elsif ($line =~ /\<Shurelia\> (.*) malformed expression/) {
      # Shurelia error: ignore
    } elsif ($line =~
        /\<Shurelia\> (\S+) rolled (.*?) --> \[ (.*?) \]\{(.*?)\}/) {
      my $name = $1;
      my $dice = $2;
      my $rolls = $3;
      my $total = $4;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $dice . " and got " . $total .
        " (rolls: " . $rolls . ")" . $end_bold;
    } elsif ($line =~
        /\<Shurelia\> (\S+) rolled (.*?) --> \{(.*?)\}/) {
      my $name = $1;
      my $equation = $2;
      my $total = $3;
      $name = normalize_name($name);
      $out = $start_bold . $name . " checked " . $equation . " and got " .
        $total . $end_bold;
    } elsif ($line =~ /\<Highwind\> Error/) {
      # Highwind error: ignore
    } elsif ($line =~ /\<Highwind\> (\S+) - Total: ([-.0-9]+)/) {
      my $name = $1;
      $line = $2;
      $name = normalize_name($name);
      $out = $start_bold . $name . " got a total of " . $line . $end_bold;
    } elsif ($line =~
    /\<Highwind\> (\S+) - (\S+): ([- ,.0-9]+) \( Total: ([-.0-9]+) \)/) {
      my $name = $1;
      $line = $2;
      my $result = $3;
      my $total = $4;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $line . " and got " . $result .
        " for a total of " . $total . $end_bold;
    } elsif ($line =~ /\<Highwind\> (\S+) - (\S+): ([- ,().0-9]+)/) {
      my $name = $1;
      $line = $2;
      my $result = $3;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $line . " and got " . $result .
        $end_bold;
    } elsif ($line =~ /\<Sugarlips\> Error/) {
      # Sugarlips error: ignore
    } elsif ($line =~
/\<Sugarlips\> (\S+), (.+):([- ,.0-9]+)\[Total: ([-.0-9]+)(.*?)\] -(.*)/
) {
      my $name = $1;
      $line = $2;
      my $result = $3;
      my $total = $4;
      my $comment = $6;
      $name = normalize_name($name);
      $comment =~ s/^(\s*)(.*?)(\s*)$/$2/s;
      $out = $start_bold . $name . " rolled " . $line . " and got" . $result .
        "( Total: " . $total . " ) for " . $comment . $end_bold;
    } elsif ($line =~
        /\<Sugarlips\> (\S+), (.+):([- ,.0-9]+)\[Total: ([-.0-9]+)/) {
      my $name = $1;
      $line = $2;
      my $result = $3;
      my $total = $4;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $line . " and got" . $result .
        "( Total: " . $total . " )" . $end_bold;
    } elsif ($line =~ /\<Sugarlips\> (\S+), (.+):([- ,.0-9]+)/) {
      my $name = $1;
      $line = $2;
      my $result = $3;
      $result =~ s/\s+$//;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $line . " and got" . $result .
        $end_bold;
    } elsif ($line =~ /\<Sugarlips\>(\s+)(\d)(\S+): (.*)$/) {
      $out = $start_bold . "Also rolled " . $2 . $3 . " and got " . $4 .
        $end_bold;
    } elsif ($line =~ /\<Sugarlips\>(\s+)(\S+): (.*)$/) {
      $out = $start_bold . $2 . ": " . $3 . $end_bold;
    } elsif ($line =~
        /\<Sugarlips\>(\s+)Total: ([-.0-9]+), Avg: ([-.0-9]+)/) {
      $out = $start_bold . "For a total of " . $2 . " (average " . $3 . ")" .
        $end_bold;
    } elsif ($line =~ /\<Sugarlips\>(\s+)(.*?)(\s*)$/) {
      $out = "Dicebot:" . $start_italic . " " . $2 . $end_italic;
    } elsif ($line =~ /\<Chessa\> (.*?): (.*)$/) {
      $line = $2;
      my $name = $1;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled up " . $line . $end_bold;
    } elsif ($line =~ /\<DiceMaid-9001\> (.*?), (.*): (.*)$/) {
      $line = $2;
      my $name = $1;
      my $result = $3;
      $result =~ s/\s+$//;
      $name = normalize_name($name);
      $out = $start_bold . $name . " rolled " . $line . " and got " . $result .
        $end_bold;
    } elsif ($line =~ /\<DiceMaid-9001\>(\s+)(.*)/) {
      # ignore all of DiceMaid-9001's non-roll-result lines
    } elsif ($line =~ /^(\s*)$star(\s+)DiceMaid-9001(\s+)/) {
      # ignore all of DiceMaid-9001's non-roll-result lines
    } elsif ($line =~ /^(.*?)\<(.*?)\>(\s+)$star(\s*)(.*)$/) {
      $line = $5;
      $out = parse_quoted_line($line,$start_italic,$end_italic);
    } elsif ($line =~ /^(.*)\<(.*?)\>(\s+)(.*)$/) {
      my $name = $2;
      $line = $4;
      $name = normalize_name($name);
      $out = $name . ": " . parse_quoted_line($line,$start_italic,$end_italic);
      $out =~ s/\/\/(\s*)\/\///gs;
    } elsif ($line =~ /^(.*) has joined \#(\S+)(\s*)$/) {
      # join channel (MIRC): ignore
    } elsif ($line =~
      /^(\s*)(\d*)\[([:0-9]+)\](\s+)$star (\S+) \((.*)\@(.*)\) has joined \#/) {
      # join channel (MIRC): ignore
    } elsif ($line =~ /^(\s*)$star(\s+)(\S+) \((.*)\@(.*)\) has joined \#/) {
      # join channel (MIRC): ignore
    } elsif ($line =~ /^ (\S+) entered the room.$/) {
      # join channel (GAIM): ignore
    } elsif ($line =~
      /^ (\S+) \[([-_`~a-zA-Z0-9.]+)\@([-_a-zA-Z0-9.]+)\] entered the room.$/) {
      # join channel (GAIM): ignore
    } elsif ($line =~ /^(.*) has left \#(\S+)(\s*)$/) {
      # leave channel (MIRC): ignore
    } elsif ($line =~ /^(.*) has left \#(\S+) \((.*)\)(\s*)$/) {
      # leave channel (MIRC): ignore
    } elsif ($line =~
        /^(\s*)(\d*)\[([:0-9]+)\](\s+)$star (\S+) \((.*)\@(.*)\) has left \#/) {
      # leave channel (MIRC): ignore
    } elsif ($line =~ /^(\s*)$star(\s+)(\S+) \((.*)\@(.*)\) has left \#/) {
      # leave channel (MIRC): ignore
    } elsif ($line =~ /^ (\S+) left the room \(quit:(.*)\)\.$/i) {
      # leave channel (GAIM): ignore
    } elsif ($line =~ /^ (\S+) left the room\.$/i) {
      # leave channel (GAIM): ignore
    } elsif ($line =~
        /(\s*)$star (\S+) \(([-_`~a-zA-Z0-9.]+)\@([-_a-zA-Z0-9.]+)\) Quit/) {
      # quit (MIRC): ignore
    } elsif ($line =~ /$star Retrieving \#(\S+) modes\.\.\./) {
      # metadata prelude to +m or ban: ignore
    } elsif ($line =~ /$star (\S+) has quit \((\S+)/) {
      # quit (XChat): ignore
    } elsif ($line =~ / has quit IRC \(/) {
      # quit (MIRC): ignore
    } elsif ($line =~
    /^(\s*)(\d*)\[([:0-9]+)\](\s+)$star (\S+) \((.*)\@(.*)\) Joins: (\s+) \(/) {
      # join (mIRC?): ignore
    } elsif ($line =~ /^(\s*)$star(\s+)(\S+) \((.*)\@(.*)\) Joins: (\s+) \(/) {
      # join (mIRC?): ignore
    } elsif ($line =~
    /^(\s*)(\d*)\[([:0-9]+)\](\s+)$star (\S+) \((.*)\@(.*)\) Quits: (\s+) \(/) {
      # quit (mIRC?): ignore
    } elsif ($line =~ /^(\s*)$star(\s+)(\S+) \((.*)\@(.*)\) Quits: (\s+) \(/) {
      # quit (mIRC?): ignore
    } elsif ($line =~
        /^(\s*)(\d*)\[([:0-9]+)\](\s+)$star (\S+) \((.*)\@(.*)\) Quit \(/) {
      # quit mIRC: ignore
    } elsif ($line =~ /^(\s*)$star(\s+)(\S+) \((.*)\@(.*)\) Quit \(/) {
      # quit mIRC: ignore
    } elsif ($line =~ /$star (\S+) is now known as (\S+)(\s*)$/) {
      # nick change (mIRC): ignore
    } elsif ($line =~ /^ (\S+) is now known as (\S+)(\s*)$/) {
      # nick change (GAIM): ignore
    } elsif ($line =~ /^ You are now known as (\S+)(\s*)$/) {
      # nick change (GAIM): ignore
    } elsif ($line =~ /$star (\S+) sets mode: (\+|\-)/) {
      # mode change (MIRC): ignore
    } elsif ($line =~ /$star (\S+) changes topic to '/) {
      # mode change (MIRC): ignore
    } elsif ($line =~ /$star (\S+)\.(\S+) gives channel operator status to /) {
      # op (XChat): ignore
    } elsif ($line =~ /$star Disconnected$/) {
      # disconnected: ignore
    } elsif ($line =~ /$star Attempting to rejoin channel \#/) {
      # reconnecting: ignore
    } elsif ($line =~ /$star Rejoined channel \#/) {
      # reconnecting: ignore
    } elsif ($line =~ /$star Topic is '/) {
      # reconnecting: ignore
    } elsif ($line =~ /$star Set by /) {
      # reconnecting: ignore
    } elsif ($line =~ /ChanServ /) {
      # ChanServ does something: ignore
    } elsif ($line =~ /^(\d*)([\[\]:0-9]+)$/) {
      # bare timestamp: ignore
    } elsif ($line =~ /^(-|$star)(\S+):\@\#/) {
      # onotice/omsg: ignore
    } elsif ($line =~
        /^(\s*)(\d*)\[([ :0-9a-zA-Z]+)\](\s*)(-|$star)(\S+):\@\#/) {
      # onotice/omsg: ignore
    } elsif ($line =~ /^-/) {
      # private message, onotice/omsg, or reconnecting: ignore
    } elsif ($line =~ /^(\s*)(\d*)\[([ :0-9a-zA-Z]+)\](\s*)-/) {
      # private message, onotice/omsg, or reconnecting: ignore
    } elsif ($line =~ /^Session /) {
      # meta-info, so ignore
    } elsif ($line =~ /^$star Logging #/) {
      # meta-info, so ignore
    } elsif ($line =~ /^(\s*)$star(\s*)(\S+)(\s+)(.*)$/) {
      $name = $3;
      $line = $5;
      $name = normalize_name($name);
      $out = parse_quoted_line($name . " " . $line,$start_italic,$end_italic);
    } elsif ($line =~
        /^(\s*)(\d*)(\[?)([ :0-9a-zA-Z]+)(\]?)(\s*)$star(\s*)(\S+)(\s+)(.*)$/) {
      $name = $8;
      $line = $10;
      $name = normalize_name($name);
      $line = $name . " " . $line;
      $out = parse_quoted_line($name . " " . $line,$start_italic,$end_italic);
    } elsif ($line =~
        /^(\s*)(\d*)(\[?)([ :0-9a-zA-Z]+)(\]?)(\s*)(\S+)(\s+)(.*)$/) {
      $name = $7;
      $line = $9;
      $name = normalize_name($name);
      $out = parse_quoted_line($name . " " . $line,$start_italic,$end_italic);
    } else {
      # echo or otherwise none of the above: ignore
    }
    if ($query->param("output") eq "tumblr") {
      $out =~ s/$start_italic(.*?)$end_italic/\/$1\//g;
      $out =~ s/\/(.*?)\//$start_italic$1$end_italic/g;
      $out =~ s/\*(.*?)\*/$start_bold$1$end_bold/g;
    }
    if ($out ne "") {
      if ($query->param("output") eq "tumblr") {
        $out =~ s/(<\/p>)(\s*)(\S)/$1$2>p<$3/gs;
        $out = "<p>" . $out;
      }
      $out =~ s/\x02/</gs;
      $out =~ s/\x03/>/gs;
      $tagnum = 0;
      $line = $out;
      while ($line =~ /^(.*?)<span (.*)$/s) {
        $tagnum++;
        $line = $2;
      }
      $line = $out;
      while ($line =~ /^(.*?)<\/span(.*)$/s) {
        $tagnum--;
        $line = $2;
      }
      while ($tagnum > 0) {
        if ($query->param("output") ne "mediawiki") {
          $out .= "<\/span>";
        } else {
          $out .= "<``\/``span>";
        }
        $tagnum--;
      }
      if ($query->param("output") eq "wikidot") {
        $out =~ s/<span(.*?)>/\[\[span$1\]\]/gs;
        $out =~ s/<\/span>/\[\[\/span\]\]/gs;
      }
      print $out . $eol;
    }
  }
  print "
"; } if ($query->param("getsourcetext") != 1) { print "\n"; }