Mercurial > emacs
annotate lib-src/grep-changelog @ 43694:2d2700949b8c
(x_display_and_set_cursor): Fix typo.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Mon, 04 Mar 2002 08:32:28 +0000 |
parents | 6bd3c93022e7 |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
28823 | 1 #! /usr/bin/perl |
25216 | 2 |
38500
3db3b0888252
(parse_changelog): Add test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
29638
diff
changeset
|
3 # Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
25216 | 4 # |
5 # This file is part of GNU Emacs. | |
6 # | |
7 # GNU Emacs is free software; you can redistribute it and/or modify | |
8 # it under the terms of the GNU General Public License as published by | |
9 # the Free Software Foundation; either version 2, or (at your option) | |
10 # any later version. | |
11 # | |
12 # GNU Emacs is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU General Public License | |
18 # along with GNU Emacs; see the file COPYING. If not, write to the | |
19 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 # Boston, MA 02111-1307, USA. | |
21 | |
22 | |
23 # Extract entries from ChangeLogs matching specified criteria. | |
24 # Optionally format the resulting output to a form suitable for RCS | |
25 # logs, like they are used in Emacs, for example. In this format, | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
26 # author lines, leading spaces, and file names are removed. |
25216 | 27 |
28 require 5; | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
29 use strict; |
25216 | 30 |
31 # Parse command line options. | |
32 | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
33 use vars qw($author $regexp $exclude $from_date $to_date |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
34 $rcs_log $with_date $version $help $reverse |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
35 @entries); |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
36 |
25216 | 37 use Getopt::Long; |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
38 my $result = GetOptions ("author=s" => \$author, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
39 "text=s" => \$regexp, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
40 "exclude=s" => \$exclude, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
41 "from-date=s" => \$from_date, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
42 "to-date=s" => \$to_date, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
43 "rcs-log" => \$rcs_log, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
44 "with-date" => \$with_date, |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
45 "reverse!" => \$reverse, |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
46 "version" => \$version, |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
47 "help" => \$help); |
25216 | 48 |
49 # If date options are specified, check that they have the format | |
50 # YYYY-MM-DD. | |
51 | |
52 $result = 0 if $from_date && $from_date !~ /^\d\d\d\d-\d\d-\d\d$/; | |
53 $result = 0 if $to_date && $to_date !~ /^\d\d\d\d-\d\d-\d\d$/; | |
54 | |
55 # Print usage information and exit when necessary. | |
56 | |
57 if ($result == 0 || $help) { | |
58 print <<USAGE; | |
59 Usage: $0 [options] [CHANGELOG...] | |
60 Print entries in ChangeLogs matching various criteria. Valid options | |
61 are | |
62 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
63 --author=AUTHOR match entries whose author line matches |
25216 | 64 regular expression AUTHOR |
65 --text=TEXT match entries whose text matches regular | |
66 expression TEXT. | |
67 --exclude=TEXT exclude entries matching TEXT. | |
68 --from-date=YYYY-MM-DD match entries not older than given date | |
69 --to-date=YYYY-MM-DD match entries not younger than given date | |
70 --rcs-log format output suitable for RCS log entries. | |
71 --with-date print short date line in RCS log | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
72 --reverse show entries in reverse (chronological) order |
25216 | 73 --version print version info |
74 --help print this help | |
75 | |
76 If no CHANGELOG is specified scan the files "ChangeLog" and | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
77 "ChangeLog.[9-1]" in the current directory. Old-style dates in ChangeLogs |
25216 | 78 are not recognized. |
79 USAGE | |
80 exit $help ? 0 : 1; | |
81 } | |
82 | |
83 # Print version info and exit if `--version' was specified. | |
84 | |
85 if ($version) { | |
86 print "0.1\n"; | |
87 exit 0; | |
88 } | |
89 | |
90 | |
91 # Value is non-zero if HEADER matches according to command line | |
92 # options specified, i.e. it matches $author, and its date is in | |
93 # the range $from_date <= date <= $to_date. | |
94 | |
95 sub header_match_p ($) { | |
96 my $header = shift; | |
97 | |
38502
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
98 return 0 unless $header; |
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
99 |
25216 | 100 # No match if AUTHOR-regexp specified and doesn't match. |
101 return 0 if $author && $header !~ /$author/; | |
102 | |
103 # Check that the date of the entry matches if date options | |
104 # `--from-date' and/or `--to-date' were specified . Old-style | |
105 # dates in ChangeLogs are not recognized, and never match. | |
106 if ($from_date || $to_date) { | |
107 if ($header =~ /^(\d\d\d\d-\d\d-\d\d)/) { | |
108 my $date = $1; | |
109 return 0 if $from_date && $date lt $from_date; | |
110 return 0 if $to_date && $date gt $to_date; | |
111 } else { | |
112 # Don't bother recognizing old-style dates. | |
113 return 0; | |
114 } | |
115 } | |
116 | |
117 return 1; | |
118 } | |
119 | |
120 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
121 # Value is non-zero if ENTRY matches the criteria specified on the |
25216 | 122 # command line, i.e. it matches $regexp, and it doesn't match |
123 # $exclude. | |
124 | |
125 sub entry_match_p ($) { | |
126 my $entry = shift; | |
127 | |
38502
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
128 return 0 unless $entry; |
180f542bf5b4
(entry_match_p, header_match_p): Fix handling of null or empty
Gerd Moellmann <gerd@gnu.org>
parents:
38500
diff
changeset
|
129 |
25216 | 130 if ($regexp) { |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
131 return 1 if ($entry =~ /$regexp/ |
25216 | 132 && (!$exclude || $entry !~ $exclude)); |
133 } else { | |
134 return 1 if !$exclude || $entry !~ $exclude; | |
135 } | |
136 | |
137 return 0; | |
138 } | |
139 | |
140 | |
141 # Print HEADER and/or ENTRY in a format suitable for what was | |
142 # specified on the command line. If $rcs_log is specified, author | |
143 # lines are not printed, and leading spaces and file names are removed | |
144 # from ChangeLog entries. | |
145 | |
146 sub print_log ($$) { | |
147 my ($header, $entry) = @_; | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
148 my $output = ''; |
25216 | 149 |
150 if ($rcs_log) { | |
151 # Remove leading whitespace from entry. | |
152 $entry =~ s/^\s+//mg; | |
153 # Remove file name parts. | |
154 $entry =~ s/^\*.*\(/(/mg; | |
155 # Remove file name parts, 2. | |
156 $entry =~ s/^\*.*://mg; | |
157 if ($with_date) { | |
158 $header =~ /(\d\d\d\d-\d\d-\d\d)/; | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
159 $output = "!changelog-date $1\n"; |
25216 | 160 } |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
161 $output .= $entry; |
25216 | 162 } else { |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
163 $output .= $header . $entry; |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
164 } |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
165 |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
166 if ($reverse) { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
167 push @entries, $output; |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
168 } else { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
169 print $output; |
25216 | 170 } |
171 } | |
172 | |
173 # Scan LOG for matching entries, and print them to standard output. | |
174 | |
175 sub parse_changelog ($) { | |
176 my $log = shift; | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
177 my $entry = undef; |
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
178 my $header = undef; |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
179 |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
180 @entries = () if $reverse; |
25216 | 181 |
182 # Open the ChangeLog. | |
183 open (IN, "< $log") || die "Cannot open $log: $!"; | |
184 | |
38509
59acf1c91dd2
(main, parse_changelog): Make "use strict"-clean.
Gerd Moellmann <gerd@gnu.org>
parents:
38504
diff
changeset
|
185 while (defined(my $line = <IN>)) { |
25216 | 186 if ($line =~ /^\S/) { |
187 # Line is an author-line. Print previous entry if | |
188 # it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
189 print_log ($header, $entry) |
25216 | 190 if header_match_p ($header) && entry_match_p ($entry); |
191 | |
192 $entry = ""; | |
193 $header = $line; | |
194 | |
195 # Add empty lines below the header. | |
38500
3db3b0888252
(parse_changelog): Add test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
29638
diff
changeset
|
196 while (defined($line = <IN>) && $line =~ /^\s*$/) { |
25216 | 197 $header = "$header$line"; |
198 } | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
199 } |
25216 | 200 |
38504
1d53627a58ae
(parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
38502
diff
changeset
|
201 last unless defined $line; |
1d53627a58ae
(parse_changelog): Add another test for defined value to
Gerd Moellmann <gerd@gnu.org>
parents:
38502
diff
changeset
|
202 |
25216 | 203 if ($line =~ /^\s*\*/) { |
204 # LINE is the first line of a ChangeLog entry. Print | |
205 # previous entry if it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
206 print_log ($header, $entry) |
25216 | 207 if header_match_p ($header) && entry_match_p ($entry); |
208 $entry = $line; | |
209 } else { | |
210 # Add LINE to the current entry. | |
211 $entry = "$entry$line"; | |
212 } | |
213 } | |
214 | |
215 # Print last entry if it matches. | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
216 print_log ($header, $entry) |
25216 | 217 if header_match_p ($header) && entry_match_p ($entry); |
218 | |
219 close IN; | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
220 |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
221 if ($reverse) { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
222 while (defined (my $entry = pop @entries)) { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
223 print $entry; |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
224 } |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
225 } |
25216 | 226 } |
227 | |
228 | |
229 # Main program. Process ChangeLogs. | |
230 | |
38551
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
231 # If files were specified on the command line, parse those files in the |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
232 # order supplied by the user; otherwise parse default files ChangeLog and |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
233 # ChangeLog.9...ChangeLog.1 according to $reverse. |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
234 unless (@ARGV > 0) { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
235 @ARGV = ("ChangeLog", map {"ChangeLog.$_"} reverse 1..9); |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
236 @ARGV = reverse @ARGV if $reverse; |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
237 } |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
238 |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
239 while (defined (my $log = shift @ARGV)) { |
6bd3c93022e7
(parse_changelog): Remove unused local variable.
Gerd Moellmann <gerd@gnu.org>
parents:
38510
diff
changeset
|
240 parse_changelog ($log) if -f $log; |
25216 | 241 } |
242 | |
243 | |
29638
f6a97d806845
Fix typos in comments. Remove trailing blanks.
Jim Meyering <jim@meyering.net>
parents:
28823
diff
changeset
|
244 # grep-changelog ends here. |