File: split.pl

package info (click to toggle)
swish-e 2.4.3-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,308 kB
  • ctags: 7,642
  • sloc: ansic: 47,402; sh: 8,508; perl: 5,281; makefile: 723; xml: 9
file content (70 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
use strict;

# swish-e -S program to index the HTML docs in sections.



my $pat = qr[<h\d><a name="([^"]+)">([^<]+)</a></h\d>]i;

opendir( DIR, '.' ) || die "Failed to opendir current directory: $!";

while ( my $name = readdir DIR ) {
    next unless $name =~ /\.html$/;
    next if $name =~ /^index/;

    unless ( open( FH, "<$name" ) ) {
        warn "Failed to open file [$name]\n";
        next;
    }

    local $/;
    index_doc( $name, <FH> );
}

sub index_doc {
    my ($name, $doc) = @_;


    my @sections = split /$pat/, $doc;
    die unless @sections;

    # Get rid of the first part
    shift @sections;


    my ( $title ) = $doc =~ m[<title>([^<]+)]is;
    $title ||= "Swish-e Documentation";

    $title =~ s/^SWISH-Enhanced: //;


    while ( @sections ) {
        my ( $section, $sec_text, $text ) = splice( @sections, 0, 3 );
        output( $name, $section, $sec_text, $text, $title );
    }

}
sub output {
    my ( $name, $section, $sec_text, $text, $title ) = @_;

    my $date = (stat $name)[9];


    my $doc = <<EOF;
<html><head><title>$title : $sec_text</title></head>
<body>$text</body>
</html>
EOF

    my $len = length $doc;
    print <<EOF;
Path-Name: $name#$section
Content-Length: $len
Last-Mtime: $date
Document-Type: HTML*

EOF

    print $doc;
}