Disable scintilla buffer draw on OS X (with Quartz backend)
[geany-mirror.git] / scripts / changelist.pl
blobf3e1ebe45b5da5826220e5ddf640c85632716bb2
1 #!/usr/bin/env perl
2 # Copyright: 2008-2011, Nick Treleaven
3 # License: GNU GPL V2 or later, as published by the Free Software Foundation, USA.
4 # Warranty: NONE
6 # Searches a ChangeLog file for a line matching 'matchstring', then matches
7 # all lines until two consecutive empty lines are found. The process then
8 # repeats until all matching blocks of text are found.
9 # Results are printed in reverse, hence in chronological order (as ChangeLogs
10 # are usually written in reverse date order).
12 # The resulting lines are then formatted to be easier to read and edit into a
13 # NEWS file.
15 # Example ChangeLog format:
16 #2009-04-03 Joe Author <joe@example.net>
18 # * src/file.c, src/file.h,
19 # src/another.c:
20 # Some change description,
21 # spanning several lines.
22 # * foo.c: Combined line.
24 use strict;
25 use warnings;
27 my $argc = $#ARGV + 1;
28 my ($matchstr, $infile);
30 if ($argc == 1)
32 ($infile) = @ARGV;
33 $matchstr = '.';
35 elsif ($argc == 2)
37 ($matchstr, $infile) = @ARGV;
39 else {
40 die <<END;
41 Usage:
42 $0 changelogfile >outfile
43 $0 matchstring changelogfile >outfile
45 matchstring is a case-insensitive regular expression, e.g. 'joe|fred'.
46 END
49 open(INPUT, $infile)
50 or die "Couldn't open $infile for reading: $!\n";
52 my $entry; # the current matching block of text
53 my @entries; # changelog entries, one per date
55 # first parse each ChangeLog entry into an array
57 my $found = 0; # if we're in a matching block of text
58 my $blank = 0; # whether the last line was empty
60 while (<INPUT>) {
61 my $line = $_; # read a line, including \n char
63 if (! $found) {
64 ($line =~ m/$matchstr/) and $found = 1;
65 } else {
66 if (length($line) <= 1) { # current line is empty
67 if ($blank > 0) { # previous line was also empty
68 push(@entries, $entry); # append entry
69 $entry = "";
70 $found = 0; # now look for next match
71 $blank = 0;
73 else {
74 $blank = 1;
78 if ($found) {
79 $entry .= $line;
82 close(INPUT);
84 # reformat entries
85 foreach $entry (reverse @entries) {
86 my @lines = split(/\n/, $entry);
87 my $fl = 0; # in file list lines
88 my $cm = 0; # in commit message lines
90 foreach my $line (@lines){
91 my $flset = $fl;
93 # strip trailing space
94 $line =~ s/\s+$//g;
96 if (!$cm){
97 # check if in filelist
98 ($line =~ m/ \* /) and $fl = 1;
99 # join filelist together on one line
100 $fl and ($line =~ s/^ / /);
101 if ($fl and ($line =~ m/:/)){
102 $fl = 0;
103 # separate ' * foo.c: Some edit.' messages:
104 if (!($line =~ m/:$/)) {
105 ($line =~ s/:/:\n*/);
108 $fl and ($line =~ m/,$/) or $fl = 0;
110 if (!$flset){
111 # Asterisk commit messages
112 if (!$cm and ($line =~ m/^ /)){
113 $cm = 1;
114 $line =~ s/^( )/$1* /;
115 } else {
116 $cm and ($line =~ s/^( )/$1 /); # indent continuing lines
118 $cm and ($line =~ m/\.$/) and $cm = 0;
120 #~ print $fl.','.$cm.','.$line."\n"; next; # debug
122 # change file list start char to easily distinguish between file list and commit messages
123 $line =~ s/^ \* /@ /g;
124 # strip <email> from date line
125 $line =~ s/^([0-9-]+.*?)\s+<.+>$/$1/g;
126 # remove indent
127 $line =~ s/^ //g;
129 if ($line ne ""){
130 print $line;
131 (!$fl) and print "\n";
134 print "\n";