create-package-feed.pl: Add usage instructions
[privoxy.git] / utils / filter2docs.pl
1 #!/usr/bin/perl
2
3 # $Id: filter2docs.pl,v 1.8 2013/03/02 14:38:38 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 "Couldn't open input file $ARGV[0]: $!\n";
19
20     parse_file();
21     print_markup();
22 }
23
24 sub sgml_escape($) {
25     my $text = shift;
26
27     $text =~ s@<@&lt;@g;
28     $text =~ s@>@&gt;@g;
29
30     return $text;
31 }
32
33 sub parse_file() {
34     while (<INPUT>) {
35         if (/^((?:(?:SERVER|CLIENT)-HEADER-)?(?:FILTER|TAGGER)): ([-\w]+) (.*)$/) {
36             my $type_uc = $1;
37             my $name = $2;
38             my $description = $3;
39             my $type = lc($type_uc);
40             my $sgml_description = sgml_escape($description);
41             my $white_space = ' ' x (($type eq 'filter' ? 20 : 27) - length($name));
42
43             $comment_lines{$type} .= "#     $name:" . $white_space . "$description\n";
44             $action_lines{$type}  .= "+$type" . "{$name} \\\n";
45             $sgml_source_1{$type} .= "   <para>\n    <anchor id=\"$type-$name\">\n" .
46                 "    <screen>+$type" . "{$name}" . $white_space .
47                 "# $sgml_description</screen>\n   </para>\n";
48             $sgml_source_2{$type} .= ' -<link linkend="' . $type_uc . "-" .
49                 uc($name) . "\">$type" . "{$name}</link> \\\n";
50         }
51     }
52 }
53
54 sub print_markup() {
55
56     my @filter_types = (
57         'filter',
58         'server-header-filter',
59         'client-header-filter',
60         'server-header-tagger',
61         'client-header-tagger'
62     );
63
64     foreach my $type (@filter_types) {
65
66         next unless defined $action_lines{$type};
67
68         print "=" x 90;
69         
70         print <<"        DOCMARKUP";
71
72 Producing $type markup:
73
74 Comment lines for default.action.master:
75
76 $comment_lines{$type}
77 Block of $type actions for default.action.master:
78
79 $action_lines{$type}
80 SGML Source for AF chapter in U-M:
81
82 $sgml_source_1{$type}
83 SGML Source for AF Tutorial chapter in U-M:
84
85 $sgml_source_2{$type}
86         DOCMARKUP
87     }
88 }
89
90 main();