2 # $Id: grep-changelog,v 1.1 1999/08/10 13:33:49 gerd Exp $
4 # Copyright (C) 1999 Free Software Foundation, Inc.
6 # This file is part of GNU Emacs.
8 # GNU Emacs is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # GNU Emacs is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Emacs; see the file COPYING. If not, write to the
20 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA.
24 # Extract entries from ChangeLogs matching specified criteria.
25 # Optionally format the resulting output to a form suitable for RCS
26 # logs, like they are used in Emacs, for example. In this format,
27 # author lines leading spaces, and file names are removed.
31 # Parse command line options.
34 $result = GetOptions
("author=s" => \
$author,
36 "exclude=s" => \
$exclude,
37 "from-date=s" => \
$from_date,
38 "to-date=s" => \
$to_date,
39 "rcs-log" => \
$rcs_log,
40 "with-date" => \
$with_date,
41 "version" => \
$version,
44 # If date options are specified, check that they have the format
47 $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/;
48 $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/;
50 # Print usage information and exit when necessary.
52 if ($result == 0 || $help) {
54 Usage: $0 [options] [CHANGELOG...]
55 Print entries in ChangeLogs matching various criteria. Valid options
58 --author=AUTHOR match entries whose author line matches
59 regular expression AUTHOR
60 --text=TEXT match entries whose text matches regular
62 --exclude=TEXT exclude entries matching TEXT.
63 --from-date=YYYY-MM-DD match entries not older than given date
64 --to-date=YYYY-MM-DD match entries not younger than given date
65 --rcs-log format output suitable for RCS log entries.
66 --with-date print short date line in RCS log
67 --version print version info
68 --help print this help
70 If no CHANGELOG is specified scan the files "ChangeLog" and
71 "ChangeLog.[9-1]" in the current directory. Old-style dates in ChangeLogs
77 # Print version info and exit if `--version' was specified.
85 # Value is non-zero if HEADER matches according to command line
86 # options specified, i.e. it matches $author, and its date is in
87 # the range $from_date <= date <= $to_date.
89 sub header_match_p
($) {
92 # No match if AUTHOR-regexp specified and doesn't match.
93 return 0 if $author && $header !~ /$author/;
95 # Check that the date of the entry matches if date options
96 # `--from-date' and/or `--to-date' were specified . Old-style
97 # dates in ChangeLogs are not recognized, and never match.
98 if ($from_date || $to_date) {
99 if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) {
101 return 0 if $from_date && $date lt $from_date;
102 return 0 if $to_date && $date gt $to_date;
104 # Don't bother recognizing old-style dates.
113 # Value is non-zero if ENTRY matches the ciiteria specified on the
114 # command line, i.e. it matches $regexp, and it doesn't match
117 sub entry_match_p
($) {
121 return 1 if ($entry =~ /$regexp/
122 && (!$exclude || $entry !~ $exclude));
124 return 1 if !$exclude || $entry !~ $exclude;
131 # Print HEADER and/or ENTRY in a format suitable for what was
132 # specified on the command line. If $rcs_log is specified, author
133 # lines are not printed, and leading spaces and file names are removed
134 # from ChangeLog entries.
137 my ($header, $entry) = @_;
140 # Remove leading whitespace from entry.
141 $entry =~ s/^\s+//mg;
142 # Remove file name parts.
143 $entry =~ s/^\*.*\(/(/mg;
144 # Remove file name parts, 2.
145 $entry =~ s/^\*.*://mg;
147 $header =~ /(\d\d\d\d-\d\d-\d\d)/;
148 print "!changelog-date $1\n";
152 print $header, $entry;
156 # Scan LOG for matching entries, and print them to standard output.
158 sub parse_changelog
($) {
163 # Open the ChangeLog.
164 open (IN
, "< $log") || die "Cannot open $log: $!";
166 while ($line = <IN
>) {
167 if ($line =~ /^\S/) {
168 # Line is an author-line. Print previous entry if
170 print_log
($header, $entry)
171 if header_match_p
($header) && entry_match_p
($entry);
176 # Add empty lines below the header.
177 while (($line = <IN
>) && $line =~ /^\s*$/) {
178 $header = "$header$line";
182 if ($line =~ /^\s*\*/) {
183 # LINE is the first line of a ChangeLog entry. Print
184 # previous entry if it matches.
185 print_log
($header, $entry)
186 if header_match_p
($header) && entry_match_p
($entry);
189 # Add LINE to the current entry.
190 $entry = "$entry$line";
194 # Print last entry if it matches.
195 print_log
($header, $entry)
196 if header_match_p
($header) && entry_match_p
($entry);
202 # Main program. Process ChangeLogs.
205 # If files were specified on the command line, parse those files.
206 while ($log = shift @ARGV) {
207 parse_changelog
($log);
210 # Parse default files ChangeLog and ChangeLog.9...ChangeLog.1 in
212 parse_changelog
("ChangeLog");
213 for ($i = 9; $i >= 1; --$i) {
214 my $log = "ChangeLog.$i";
215 parse_changelog
($log) if -f
$log;
220 # gre-changelog ends here.