#!/usr/bin/perl -w

use strict;
use Time::Local;

my %monnametonum = (
    'Jan' => 1,
    'Feb' => 2,
    'Mar' => 3,
    'Apr' => 4,
    'May' => 5,
    'Jun' => 6,
    'Jul' => 7,
    'Aug' => 8,
    'Sep' => 9,
    'Oct' => 10,
    'Nov' => 11,
    'Dec' => 12,
);

while(<>) {
    my ($record);
    if (/([-a-zA-Z0-9.]+)\s
         ([-0-9a-fx]+)\s
	 (\S+)\s
	 \[(\d\d\/\w\w\w\/\d{4}:\d\d:\d\d:\d\d\s [-+]\d{4}
	   )\]\s
	 "(\w+)\s (\S+)\s (\w+\/\d+\.\d+)"\s
	 (\d+)\s
	 (\d+)\s
	 (\S+)\s
	 (\S+)
	/x
    ) {
	my ($host, $weakuid, $authuid, $datestr, $method, $file, $httpversion, $code, $size, $referrer, $useragent) =
	   ($1,    $2,	     $3,       $4,	 $5,      $6,    $7,	       $8,    $9,    $10,	$11);
	if ($datestr =~ m/^(\d\d)\/(\w\w\w)\/(\d{4}):(\d\d):(\d\d):(\d\d)/) {
	    my ($mday, $monstr, $year, $hour, $min, $sec) =
	       ($1,    $2,	$3,    $4,    $5,   $6);
	    my $mon = $monnametonum{$monstr};
	    my $time = timelocal($sec, $min, $hour, $mday, $mon-1, $year-1900);
	    if ($weakuid eq "-") { $weakuid = 0 }
	    $record = 
		[$host, $weakuid, $authuid, $time, $method, $file,
		$httpversion, $code, $size, $referrer, $useragent];
	    print "@$record\n";
	
	} else {
	    print STDERR "$0: unparseable date: $datestr\n";
	    next;
	}
    } else {
	print STDERR "$0: unparseable: $_";
	next;
    }
}

