e3b2b55e20b0ff676abdeba051bf5010ae759a40
[privoxy.git] / utils / prepare-configfile.pl
1 #!/usr/local/bin/perl
2
3 use strict;
4 use warnings;
5
6 sub main() {
7     my $hit_header = 0;
8     my $hit_option = 0;
9     my $header_len;
10
11     while (<>) {
12         s/^1\. \@\@TITLE\@\@/     /i;
13
14         if (m/^(\d\.)(\d\.)(\d\.)?\s/) {
15             # Remove the first digit as it's the
16             # config file section in the User Manual.
17             s/^(\d\.)//;
18
19             # If it's a section header, uppercase it.
20             $_ = uc() if (/^\d\.\s+/);
21
22             # Remember to underline it.
23             $hit_header = 1;
24             $header_len = length($_);
25         }
26
27         s/^/#  /;
28
29         # XXX: someone should figure out what this stuff
30         # is supposed to do (and if it really does that).
31         s/^#  #/####/ if /^#  #{12,}/;
32         s/^.*$// if $hit_option;
33         $hit_option = 0;
34         s/^\n//;
35         s/^#\s*-{20,}//;
36         s/ *$//;
37         $hit_option = 1 if s/^#\s+@@//;
38     
39         print;
40
41         if ($hit_header) {
42             # The previous line was a section
43             # header so we better underline it.
44             die "Invalid header length" unless defined $header_len;
45             print "#  " . "=" x $header_len . "\n";
46             $hit_header = 0;
47         };
48     }
49 }
50 main();