changelog2doc.pl: Don't confuse configure flags with ChangeLog items that need indent...
[privoxy.git] / utils / changelog2doc.pl
1 #!/usr/bin/perl
2
3 ##########################################################################
4 #
5 # Filter to parse the ChangeLog and translate the changes for
6 # the most recent version into something that looks like markup
7 # for the documentation but still needs fine-tuning.
8 #
9 # Copyright (c) 2008, 2010 Fabian Keil <fk@fabiankeil.de>
10 #
11 # Permission to use, copy, modify, and distribute this software for any
12 # purpose with or without fee is hereby granted, provided that the above
13 # copyright notice and this permission notice appear in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 ##########################################################################
23
24 use strict;
25 use warnings;
26
27 my @entries;
28
29 sub read_entries() {
30     my $section_reached = 0;
31     my $i = -1;
32
33     while (<>) {
34         if (/^\*{3} /) {
35             last if $section_reached;
36             $section_reached = 1;
37             next;
38         }
39         next unless $section_reached;
40         next if /^\s*$/;
41
42         if (/^(\s*)- /) {
43             my $indentation = length($1);
44             if ($i > 1 and $entries[$i]{indentation} > $indentation) {
45                 $entries[$i]{last_list_item} = 1;
46             }
47             $i++; 
48             $entries[$i]{description} = '';
49             $entries[$i]{indentation} = $indentation;
50         }
51         if (/:\s*$/) {
52             $entries[$i]{list_header} = 1;
53         }
54
55         s@^\s*-?\s*@@;
56
57         $entries[$i]{description} .= $_;
58     }
59     if ($entries[$i]{indentation} != 0) {
60         $entries[$i]{last_list_item} = 1;
61     }
62     print "Parsed " . @entries . " entries.\n";
63 }
64
65 sub create_listitem_markup($) {
66     my $entry = shift;
67     my $description = $entry->{description};
68     my $markup = '';
69     my $default_lws = '  ';
70     my $lws = $default_lws x ($entry->{indentation} ? 2 : 1);
71
72     chomp $description;
73
74     $description =~ s@\n@\n  ${lws}@g;
75
76     $markup .= $lws . "<listitem>\n" .
77                $lws . " <para>\n";
78
79     $markup .= $lws . "  " . $description . "\n";
80
81     if (defined $entry->{list_header}) {
82         $markup .= $lws . "  <itemizedlist>\n";
83
84     } else {
85         if (defined $entry->{last_list_item}) {
86             $markup .= $lws . " </para>\n";
87             $markup .= $lws . " </listitem>\n";
88             $markup .= $lws . "</itemizedlist>\n";
89             $lws = $default_lws;
90         }
91         $markup .= $lws . " </para>\n" .
92                    $lws . "</listitem>\n";
93     }
94
95     return $markup;
96 }
97
98 sub wrap_in_para_itemlist_markup($) {
99     my $content = shift;
100     my $markup = "<para>\n" .
101                  " <itemizedlist>\n" .
102                  "  $content" .
103                  " </itemizedlist>\n" .
104                  "</para>\n";
105     return $markup;
106 }
107
108 sub generate_markup() {
109     my $markup = '';
110
111     foreach my $entry (@entries) {
112         $markup .= create_listitem_markup(\%{$entry});
113     }
114
115     print wrap_in_para_itemlist_markup($markup);
116 }
117
118 sub main () {
119     read_entries();
120     generate_markup();
121 }
122
123 main();