#!/usr/bin/perl
#
# split up an HTML file generated with e.g.
#
# /opt/trinity/bin/meinproc --check \
# --stylesheet `dirname $(KDE_XSL_STYLESHEET)`/kde-chunk-online.xsl \
# $(srcdir)/index.docbook -o index.xml;
#
# into several HTML files. While processing the input file - which
# must be named index.xml - replace the following occurences:
#
# source destination
# ---------------------------------------------------------------------------
# HEAD/common ../common
# Search -literally nothing-
# docs.kde.org Home
#
# The script should be started in the directory where the file index.xml
# is located. The output files will be generated in the same directory.
#
# (C) 2007,2009 by Thomas Baumgart (ipwizard at users.sourceforge.net)
#
#***************************************************************************
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU General Public License as published by *
#* the Free Software Foundation; either version 2 of the License, or *
#* (at your option) any later version. *
#***************************************************************************/
sub endFile
{
close OUT;
$fileIdx--;
if($fileIdx > 0) {
open(OUT, ">> $fname[$fileIdx]") or die("Unable to open file");
}
}
sub startFile
{
$fileIdx++;
my $node = shift;
$node =~ /FILENAME filename="(.*)"/;
my $name = $1;
$fname[$fileIdx] = $name;
open(OUT, "> $fname[$fileIdx]") or die("Unable to open file");
}
sub processLine
{
my $line = shift;
# .........
if($line =~ /(.*)(<\/FILENAME>)(.*)/) {
my $s = $1;
my $e = $3;
processLine($s);
endFile();
processLine($e);
}
# .........
elsif($line =~ /(.*)()(.*)/) {
my $s = $1;
my $f = $2;
my $e = $3;
processLine($s);
startFile($f);
processLine($e);
}
else {
# replace HEAD/common with ../common
$line =~ s#/HEAD/common#../common#g;
# don't show access to search form
$line =~ s#Search##g;
# don't link to docs.kde.org
$line =~ s#docs.kde.org#Home#g;
print OUT "$line\n";
}
}
$fileIdx = 0;
open(IN, "< index.xml");
while() {
chomp($_);
my $line = $_;
processLine($line);
}
close IN;