forked from LMS-Community/slimserver-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl2html.pl
executable file
·198 lines (152 loc) · 4.77 KB
/
cl2html.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/perl
# cl2html.pl - Convert the XML output of cvs2cl.pl to (X)HTML
# Copyright (C) 2003 Anderson Lizardo
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id$
use strict;
use warnings;
use XML::Parser;
use Getopt::Long;
use Pod::Usage;
use POSIX qw(strftime);
# Output only the last $entries_limit CVS changes
my $entries_limit = 2000;
# Convert ISO 8601 date (yyyy-mm-dd) to the specified format
sub isodate2any {
my ($date, $format) = @_;
if ($date =~ /(\d{4})-(\d{2})-(\d{2})/) {
return strftime($format, 0, 0, 0, $3, $2 - 1, $1 - 1900);
}
else {
return undef;
}
}
my $help = 0;
my $man = 0;
my $infile = "";
my $with_filename = 0;
GetOptions(
"help" => \$help,
"man" => \$man,
"infile=s" => \$infile,
"with-filename", \$with_filename,
) or pod2usage(1);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
my $date = ""; # Current date
my $buffer = ""; # Current text in buffer
my $author = ""; # Current author
my @messages = (); # Commit messages of the same author
my $files = ""; # Files affected by CVS change
my $entry_count = 0;
sub print_log {
exit 0 if $entry_count++ == $entries_limit;
# print "<li>" . $author . " - " . isodate2any($date, '%Y/%m/%d') . "\n";
# print "\t<ul>\n";
foreach (@messages) {
print "\t\t<li>" . $_->{files} . ' ' . $_->{text} . "</li>\n";
}
# print "\t\t</ul>\n";
# print "\t</li>\n";
@messages = ();
}
my $parser = new XML::Parser(
Handlers => {
Start => \&handle_StartTag,
End => \&handle_EndTag,
Char => \&handle_Text,
},
);
if ($infile) {
eval { $parser->parsefile($infile) } or pod2usage("$0: $@");
}
else {
$parser->parse(\*STDIN);
}
sub handle_StartTag {
$buffer = "";
}
sub handle_EndTag {
my (undef, $tag) = @_;
if ($tag eq "date") {
print_log() if ($buffer ne $date and @messages and $author and $date);
$date = $buffer;
}
elsif ($tag eq "author") {
print_log() if ($buffer ne $author and @messages and $author and $date);
$author = $buffer;
}
elsif ($tag eq "msg") {
my %message = ();
if ($with_filename) {
$files =~ s/, $/ /;
$message{files} = $files;
$files = "";
}
$message{text} = $buffer;
unshift @messages, \%message;
}
elsif ($tag eq "name" and $with_filename) {
$files .= $buffer . ", ";
}
}
sub handle_Text {
my ($expat, $text) = @_;
# Encode "special" entities
$text =~ s/\&/\&/g;
$text =~ s/</\</g;
$text =~ s/>/\>/g;
#$text =~ s/\"/\"/g;
#$text =~ s/\'/\'/g;
# Add current text to the buffer
$buffer .= $text;
}
__END__
=head1 NAME
cl2html.pl - convert the XML output of cvs2cl.pl to (X)HTML
=head1 SYNOPSIS
cl2html.pl [--help|--man] [--with-filename] [--infile xml_file]
Options:
--infile Parse XML from a file
--with-filename Prepend filenames to commit messages
--help Show brief help message
--man Full documentation
=head1 DESCRIPTION
B<cl2html.pl> converts the XML outputted by cvs2cl.pl's C<--xml> option to
HTML or XHTML code.
=head1 OPTIONS
=over
=item B<--infile xml_file>
Specify which XML file to parse. This file must be the output of cvs2cl.pl's
C<--xml> option. By default, B<cl2html.pl> reads XML code from standard input.
=item B<--with-filename>
This option prepends filenames to each commit message.
=item B<--help>
Print a brief help message and exits.
=item B<--man>
Print the manual page and exits.
=back
=head1 AUTHOR
Copyright (C) 2003 Anderson Lizardo <andersonlizardo@yahoo.com.br>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
=cut