1#!/usr/bin/perl
2require"timelocal.pl";
3
4#
5# usage scancvslog.pl logfile starttime tag
6#
7# this will extract all entries from the specified cvs log file
8# that have a date later than or equal to starttime and a tag
9# value of tag. If starttime is not specified, all entries are
10# extracted. If tag is not specified then entries for all
11# branches are extracted. starttime must be specified as
12# "monthname day, year"
13#
14# Example to extract all entries for SAMBA_2_2 branch from the
15# log file named cvs.log
16#
17# scancvslog.pl cvs.log "" SAMBA_2_2
18#
19#
20# To extract all log entries after Jan 10, 1999 (Note month name
21# must be spelled out completely).
22#
23# scancvslog.pl cvs.log "January 10, 1999"
24#
25
26open(INFILE,@ARGV[0]) || die "Unable to open @ARGV[0]\n";
27
28%Monthnum = (
29	"January",	0,
30	"February",	1,
31	"March",	2,
32	"April",	3,
33	"May",		4,
34	"June",		5,
35	"July",		6,
36	"August",	7,
37	"September",	8,
38	"October",	9,
39	"November",	10,
40	"December",	11,
41	"Jan",		0,
42	"Feb",		1,
43	"Mar",		2,
44	"Apr",		3,
45	"May",		4,
46	"Jun",		5,
47	"Jul",		6,
48	"Aug",		7,
49	"Sep",		8,
50	"Oct",		9,
51	"Nov",		10,
52	"Dec",		11
53);
54
55$Starttime = (@ARGV[1]) ? &make_time(@ARGV[1]) : 0;
56$Tagvalue = @ARGV[2];
57
58while (&get_entry) {
59  $_=$Entry[0];
60# get rid of extra white space
61  s/\s+/ /g;
62# get rid of any time string in date
63  s/ \d\d:\d\d:\d\d/,/;
64  s/^Date:\s*\w*\s*(\w*)\s*(\w*),\s*(\w*).*/$1 $2 $3/;
65  $Testtime = &make_time($_);
66  $Testtag = &get_tag;
67  if (($Testtime >= $Starttime) && ($Tagvalue eq $Testtag)) {
68    print join("\n",@Entry),"\n";
69  }
70}
71close(INFILE);
72
73sub make_time {
74  $_ = @_[0];
75  s/,//;
76  ($month, $day, $year) = split(" ",$_);
77  if (($year < 1900)||($day < 1)||($day > 31)||not length($Monthnum{$month})) {
78    print "Bad date format @_[0]\n";
79    print "Date needs to be specified as \"Monthname day, year\"\n";
80    print "eg: \"January 10, 1999\"\n";
81    exit 1;
82  }
83  $year = ($year == 19100) ? 2000 : $year;
84  $month = $Monthnum{$month};
85  $Mytime=&timelocal((0,0,0,$day,$month,$year));
86}
87
88sub get_tag {
89  @Mytag = grep (/Tag:/,@Entry);
90  $_ = @Mytag[0];
91  s/^.*Tag:\s*(\w*).*/$1/;
92  return $_;
93}
94
95sub get_entry {
96  @Entry=();
97  if (not eof(INFILE)) {
98    while (not eof(INFILE)) {
99      $_ = <INFILE>;
100      chomp $_;
101      next if (not ($_));
102      if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/) {
103	next if ($#Entry == -1);
104	push(Entry,$_);
105	return @Entry;
106      } else {
107	push(Entry,$_);
108      }
109    }
110  }
111  return @Entry;
112}
113