Factor wrap_in_para_itemlist_markup() out of generate_markup().
[privoxy.git] / utils / changelog2doc.pl
1 #!/usr/bin/perl
2
3 # $Id: changelog2doc.pl,v 1.4 2010/10/31 13:26:07 fabiankeil Exp $
4 # $Source: /cvsroot/ijbswa/current/utils/changelog2doc.pl,v $
5
6 # Filter to parse the ChangeLog and translate the changes for
7 # the most recent version into something that looks like markup
8 # for the documentation but still needs fine-tuning.
9
10 use strict;
11 use warnings;
12
13 my @entries;
14
15 sub read_entries() {
16     my $section_reached = 0;
17     my $i = -1;
18
19     while (<>) {
20         if (/^\*{3} /) {
21             last if $section_reached;
22             $section_reached = 1;
23             next;
24         }
25         next unless $section_reached;
26         next if /^\s*$/;
27
28         if (/^-/) {
29             $i++; 
30             $entries[$i]{description} = '';
31         }
32         s@^-?\s*@@;
33
34         $entries[$i]{description} .= $_;
35     }
36     print "Parsed " . @entries . " entries.\n";
37 }
38
39 sub create_listitem_markup($) {
40     my $entry = shift;
41     my $description = $entry->{description};
42
43     chomp $description;
44
45     $description =~ s@\n@\n    @g;
46     return "  <listitem>\n" .
47            "   <para>\n" .
48            "    " . $description . "\n" .
49            "   </para>\n" .
50            "  </listitem>\n";
51 }
52
53 sub wrap_in_para_itemlist_markup($) {
54     my $content = shift;
55     my $markup = "<para>\n" .
56                  " <itemizedlist>\n" .
57                  "  $content" .
58                  " </itemizedlist>\n" .
59                  "</para>\n";
60     return $markup;
61 }
62
63 sub generate_markup() {
64     my $markup = '';
65
66     foreach my $entry (@entries) {
67         $markup .= create_listitem_markup(\%{$entry});
68     }
69
70     print wrap_in_para_itemlist_markup($markup);
71 }
72
73 sub main () {
74     read_entries();
75     generate_markup();
76 }
77
78 main();