File: filter2docs.pl

package info (click to toggle)
privoxy 3.0.21-7
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 7,352 kB
  • sloc: ansic: 30,233; sh: 10,643; perl: 3,889; makefile: 218; xml: 14
file content (90 lines) | stat: -rwxr-xr-x 2,346 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl

# $Id: filter2docs.pl,v 1.9 2013/03/02 14:38:51 fabiankeil Exp $
# $Source: /cvsroot/ijbswa/current/utils/filter2docs.pl,v $

# Parse the filter names and descriptions from a filter file and
# spit out copy&paste-ready markup for the various places in
# configuration and documentation where all filters are listed.

use strict;
use warnings;

my (%comment_lines, %action_lines, %sgml_source_1, %sgml_source_2);

sub main() {

    die "Usage: $0 filter-file\n" unless (@ARGV == 1) ;
    open(INPUT, "< $ARGV[0]") or die "Couldn't open input file $ARGV[0]: $!\n";

    parse_file();
    print_markup();
}

sub sgml_escape($) {
    my $text = shift;

    $text =~ s@<@&lt;@g;
    $text =~ s@>@&gt;@g;

    return $text;
}

sub parse_file() {
    while (<INPUT>) {
        if (/^((?:(?:SERVER|CLIENT)-HEADER-)?(?:FILTER|TAGGER)): ([-\w]+) (.*)$/) {
            my $type_uc = $1;
            my $name = $2;
            my $description = $3;
            my $type = lc($type_uc);
            my $sgml_description = sgml_escape($description);
            my $white_space = ' ' x (($type eq 'filter' ? 20 : 27) - length($name));

            $comment_lines{$type} .= "#     $name:" . $white_space . "$description\n";
            $action_lines{$type}  .= "+$type" . "{$name} \\\n";
            $sgml_source_1{$type} .= "   <para>\n    <anchor id=\"$type-$name\">\n" .
                "    <screen>+$type" . "{$name}" . $white_space .
                "# $sgml_description</screen>\n   </para>\n";
            $sgml_source_2{$type} .= ' -<link linkend="' . $type_uc . "-" .
                uc($name) . "\">$type" . "{$name}</link> \\\n";
        }
    }
}

sub print_markup() {

    my @filter_types = (
        'filter',
        'server-header-filter',
        'client-header-filter',
        'server-header-tagger',
        'client-header-tagger'
    );

    foreach my $type (@filter_types) {

        next unless defined $action_lines{$type};

        print "=" x 90;
        
        print <<"        DOCMARKUP";

Producing $type markup:

Comment lines for default.action.master:

$comment_lines{$type}
Block of $type actions for default.action.master:

$action_lines{$type}
SGML Source for AF chapter in U-M:

$sgml_source_1{$type}
SGML Source for AF Tutorial chapter in U-M:

$sgml_source_2{$type}
        DOCMARKUP
    }
}

main();