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