#!/usr/bin/perl
# dbipg_logprint
#    $Id: dbipg_logprint,v 1.1.1.1 2002/12/26 04:37:47 nakahira Exp $
#    Last updated: 12/22/2002
#
# Copyright (C) 2002 The Nagoya University Consumers' Co-operative Association
#   Written by K.Nakahira
#
#  This program is licensed under the GNU GPL.
#  See the following URL for more details:
#    http://www.gnu.org/licenses/gpl.txt
#

use strict;
use File::Basename;
use Getopt::Long;

use DBIPgSystem::DB;

my $VERSION = '0.1.00';

# 
my $opt = { num => 1,
		  };
my $optlist = [ 'help!', 'num=i' ];
my $init = { basename => basename($0),
			 basedir => dirname($0),
		   };

sub usage {
  my $ver = "(version $VERSION)" if($VERSION);
  print <<USAGE;
$init->{basename} $ver
Usage: $init->{basename} [ץ] logfile
ARGS:
  logfile    ե
Options:
  --num      ɽ (default: '$opt->{num}')
USAGE
  exit;
}

{
  GetOptions($opt, @$optlist);
  &usage if(@ARGV != 1 or $opt->{help});
  my ($file) = @ARGV;

  # եƤɤ߹
  my $lines = [ ];
  open(IN, $file) or die "Cannot open '$file': $!";
  push(@$lines, $_) while(<IN>);

  my $str;
  my ($date, $ver, $type, $file, $msg, $group, $addr, $agent, @msg, $k, $v);
  # ɽԿ򷫤֤
  foreach my $n (reverse 1 .. $opt->{num}) {
	$str = $lines->[-$n];
	$str =~ s/;; /\n/g;
	($date, $ver, $type, $file, $msg, $group, $addr, $agent, @msg) =
	  split(/ \*\* /, $str);
	foreach ($date, $ver, $type, $file, $msg, @msg) { s/([*;]) /$1/g; }

	print <<MESSAGE;
######################################################################
$date   \[ $type \]   Ver. $ver
$file
msg: $msg   group: $group
addr: $addr
agent: $agent\n
MESSAGE
	foreach (@msg) {
	  ($k, $v) = split(/ == /, $_, 2);
	  print "[$k]\n$v\n";
	}
  }
}
exit;

__END__

=for html
<div class="header">
<div class="bar">
<a href="../index.html">Top</a>
<a href="index.html">ޥ˥奢</a>
</div>
<h1>dbipg_logprint</h1></div>

=for html
<div class="pod">

=head1 NAME

dbipg_logprint - ɽ

=head1 DESCRIPTION

  $ dbipg_logprint logfile
  $ dbipg_logprint -num=3 logfile

ꤷեƺǶΥɽ롣

=head1 SEE ALSO

F<DBIPgSystem>, F<DBIPgSystem::DB>

=head1 COPYRIGHT

Copyright (C) 2002 The Nagoya University Consumers' Co-operative Association

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the following URL for more details:
  http://www.gnu.org/licenses/gpl.txt

Written by Kenji Nakahira <nakahira@coop.nagoya-u.ac.jp>

=for html
</div>

=cut

