row of asteriks that indicates new entry must start at beginning of line.
[kai/samba.git] / source3 / script / scancvslog.pl
1 #!/usr/bin/perl
2 require"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
26 open(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 );
42
43 $Starttime = (@ARGV[1]) ? &make_time(@ARGV[1]) : 0;
44 $Tagvalue = @ARGV[2];
45
46 while (&get_entry) {
47   $_=$Entry[0];
48   s/^Date:\s*\w*\s*(\w*)\s*(\w*),\s*(\w*).*/$1 $2 $3/;
49   $Testtime = &make_time($_);
50   $Testtag = &get_tag;
51   if (($Testtime >= $Starttime) && ($Tagvalue eq $Testtag)) {
52     print join("\n",@Entry),"\n";
53   }
54 }
55 close(INFILE);
56
57 sub make_time {
58   $_ = @_[0];
59   s/,//;
60   ($month, $day, $year) = split(" ",$_);
61   if (($year < 1900)||($day < 1)||($day > 31)||not length($Monthnum{$month})) {
62     print "Bad date format @_[0]\n";
63     print "Date needs to be specified as \"Monthname day, year\"\n";
64     print "eg: \"January 10, 1999\"\n";
65     exit 1;
66   }
67   $year = ($year == 19100) ? 2000 : $year;
68   $month = $Monthnum{$month};
69   $Mytime=&timelocal((0,0,0,$day,$month,$year));
70 }
71
72 sub get_tag {
73   @Mytag = grep (/Tag:/,@Entry);
74   $_ = @Mytag[0];
75   s/^.*Tag:\s*(\w*).*/$1/;
76   return $_;
77 }
78
79 sub get_entry {
80   @Entry=();
81   if (not eof(INFILE)) {
82     while (not eof(INFILE)) {
83       $_ = <INFILE>;
84       chomp $_;
85       next if (not ($_));
86       if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/) {
87         next if ($#Entry == -1);
88         push(Entry,$_);
89         return @Entry;
90       } else {
91         push(Entry,$_);
92       }
93     }
94   }
95   return @Entry;
96 }