#!/usr/bin/perl
#
# Legger en HTML-tabell rundt to preformaterte tekstfelter/tabeller
# (ultragriseri)

$org_file = $ARGV[0];

open ORG, $org_file;
@html = <ORG>;
$html = "@html";
close ORG;


sub makeTable1 {
    $text = $_[0];
    $text =~ s/(.*)?\s\s+(\d+)\n/<tr><td> $1 <\/td><td align=right> $2 <\/td><\/tr>\n/g;
    return "<table border=0>\n".$text."</table>\n";
}
$html =~ s/<PRE>\n(.+?\n.+?\n.+?\n.+?\n) <\/PRE>/makeTable1($1)/e;


sub makeTable2 {
    $text = $_[0];

    $text =~ s/^([^\n]+?\n){2,2}/
<tr><td align=right> %Reqs <\/td>
<td align=right> %Bytes <\/td>
<td align=right> Bytes sent <\/td>
<td align=right> Requests <\/td> <td>&nbsp;&nbsp;&nbsp;
<\/td><td>Date<\/td> <\/tr>
<tr><td colspan=5>&nbsp;<\/td><\/tr>\n/;  

    $text =~ s/ *([^ ]+)? +([^ ]+)? +([^ ]+)? +([^ ]+)? +\| +([^\n]+)/
<tr><td align=right><font size=-1>$1<\/font><\/td>
<td align=right><font size=-1>$2 <\/font><\/td>
<td align=right><font size=-1> $3<\/font><\/td>
<td align=right><font size=-1>$4 <\/font><\/td>
<td><\/td>
<td><font size=-1>$5<\/font><\/td><\/tr>
\n/g;

    return "<table border=0 cellspacing=0 cellpadding=0>\n".$text."</table>\n";
}
$html =~ s/<PRE>\n([\n\w\-\|\.%\s]+)?<\/PRE>/makeTable2($1)/e;


sub makeTable3 {
    $text = $_[0];

    $text =~ s/^([^\n]+?\n){2,2}/
<tr><td align=right> %Reqs <\/td>
<td align=right> %Bytes <\/td>
<td align=right> Bytes sent <\/td>
<td align=right> Requests <\/td> <td>&nbsp;&nbsp;&nbsp;
<\/td><td>Domain<\/td> <\/tr>
<tr><td colspan=5>&nbsp;<\/td><\/tr>\n/;  

    $text =~ s/ *([^ ]+)? +([^ ]+)? +([^ ]+)? +([^ ]+)? +\| +([^\n]+)/
<tr><td align=right><font size=-1>$1<\/font><\/td>
<td align=right><font size=-1>$2 <\/font><\/td>
<td align=right><font size=-1> $3<\/font><\/td>
<td align=right><font size=-1>$4 <\/font><\/td>
<td><\/td>
<td><font size=-1>$5<\/font><\/td><\/tr>
\n/g;

    return "<table border=0 cellspacing=0 cellpadding=0>\n".$text."</table>\n";
}

$html =~ s/<PRE>\n([^\^]+?)<\/PRE>/makeTable3($1)/e;


sub makeTable4 {
    $text = $_[0];

    $text =~ s/^([^\n]+?\n){2,2}/
<tr><td align=right> %Reqs <\/td>
<td align=right> %Bytes <\/td>
<td align=right> Bytes sent <\/td>
<td align=right> Requests <\/td> <td>&nbsp;&nbsp;&nbsp;
<\/td><td>Archive section<\/td> <\/tr>
<tr><td colspan=5>&nbsp;<\/td><\/tr>\n/;  

    $text =~ s/ *([^ ]+)? +([^ ]+)? +([^ ]+)? +([^ ]+)? +\| +([^\n]+)/
<tr><td align=right><font size=-1>$1<\/font><\/td>
<td align=right><font size=-1>$2 <\/font><\/td>
<td align=right><font size=-1> $3<\/font><\/td>
<td align=right><font size=-1>$4 <\/font><\/td>
<td><\/td>
<td><font size=-1>$5<\/font><\/td><\/tr>
\n/g;

    return "<table border=0 cellspacing=0 cellpadding=0>\n".$text."</table>\n";
}

$html =~ s/<PRE>\n([^\^]+?)<\/PRE>/makeTable4($1)/e;


open (OUT, ">$org_file") or die("farsken");
print OUT $html;
close OUT;






























































