summaryrefslogtreecommitdiffstats
path: root/contrib/splitup-kde-chunk-online
blob: 53003cc31519c22f5e87f632c7c6ecc15f758086 (plain)
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
#!/usr/bin/perl
#
# split up an HTML file generated with e.g.
#
#   /opt/kde3/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
# <a href=\"/search_form.html\">Search</a>    -literally nothing-
# <a href=\"/\">docs.kde.org</a>              <a href=\"index.html\">Home</a>
#
# 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;
	# .....</FILENAME>....
	if($line =~ /(.*)(<\/FILENAME>)(.*)/) {
		my $s = $1;
		my $e = $3;
		processLine($s);
		endFile();
		processLine($e);
	}
	# .....<FILENAME filename="index.html">....
	elsif($line =~ /(.*)(<FILENAME filename="[^>\"]*">)(.*)/) {
		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#<a href=\"/search_form.html\">Search</a>##g;
		# don't link to docs.kde.org
		$line =~ s#<a href=\"/\">docs.kde.org</a>#<a href=\"index.html\">Home</a>#g;
		print OUT "$line\n";
	}
}

$fileIdx = 0;
open(IN, "< index.xml");
while(<IN>) {
	chomp($_);
	my $line = $_;
	processLine($line);
}
close IN;