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