remove all of the CVS "$Id: xxx" lines that GIT doesn't do anything with
[privoxy.git] / utils / filter2docs.pl
1 #!/usr/bin/perl
2
3 # utils/filter2docs.pl
4
5 # Parse the filter names and descriptions from a filter file and
6 # spit out copy&paste-ready markup for the various places in
7 # configuration and documentation where all filters are listed.
8
9 use strict;
10 use warnings;
11
12 my (%comment_lines, %action_lines, %sgml_source_1, %sgml_source_2);
13
14 sub main() {
15
16     die "Usage: $0 filter-file\n" unless (@ARGV == 1) ;
17     open(INPUT, "< $ARGV[0]") or die "Couldn't open input file $ARGV[0]: $!\n";
18
19     parse_file();
20     print_markup();
21 }
22
23 sub sgml_escape($) {
24     my $text = shift;
25
26     $text =~ s@<@&lt;@g;
27     $text =~ s@>@&gt;@g;
28
29     return $text;
30 }
31
32 sub parse_file() {
33     while (<INPUT>) {
34         if (/^((?:(?:SERVER|CLIENT)-HEADER-)?(?:FILTER|TAGGER)): ([-\w]+) (.*)$/) {
35             my $type_uc = $1;
36             my $name = $2;
37             my $description = $3;
38             my $type = lc($type_uc);
39             my $sgml_description = sgml_escape($description);
40             my $white_space = ' ' x (($type eq 'filter' ? 20 : 27) - length($name));
41
42             $comment_lines{$type} .= "#     $name:" . $white_space . "$description\n";
43             $action_lines{$type}  .= "+$type" . "{$name} \\\n";
44             $sgml_source_1{$type} .= "   <para>\n    <anchor id=\"$type-$name\">\n" .
45                 "    <screen>+$type" . "{$name}" . $white_space .
46                 "# $sgml_description</screen>\n   </para>\n";
47             $sgml_source_2{$type} .= ' -<link linkend="' . $type_uc . "-" .
48                 uc($name) . "\">$type" . "{$name}</link> \\\n";
49         }
50     }
51 }
52
53 sub print_markup() {
54
55     my @filter_types = (
56         'filter',
57         'server-header-filter',
58         'client-header-filter',
59         'server-header-tagger',
60         'client-header-tagger'
61     );
62
63     foreach my $type (@filter_types) {
64
65         next unless defined $action_lines{$type};
66
67         print "=" x 90;
68         
69         print <<"        DOCMARKUP";
70
71 Producing $type markup:
72
73 Comment lines for default.action.master:
74
75 $comment_lines{$type}
76 Block of $type actions for default.action.master:
77
78 $action_lines{$type}
79 SGML Source for AF chapter in U-M:
80
81 $sgml_source_1{$type}
82 SGML Source for AF Tutorial chapter in U-M:
83
84 $sgml_source_2{$type}
85         DOCMARKUP
86     }
87 }
88
89 main();