File indexing completed on 2024-07-21 04:36:26

0001 #!/usr/bin/perl
0002 #
0003 # split up an HTML file generated with e.g.
0004 #
0005 #   /opt/kde3/bin/meinproc --check \
0006 #      --stylesheet `dirname $(KDE_XSL_STYLESHEET)`/kde-chunk-online.xsl \
0007 #      $(srcdir)/index.docbook -o index.xml;
0008 #
0009 # into several HTML files. While processing the input file - which
0010 # must be named index.xml - replace the following occurrences:
0011 #
0012 # source                                      destination
0013 # ---------------------------------------------------------------------------
0014 # HEAD/common                                 ../common
0015 # <a href=\"/search_form.html\">Search</a>    -literally nothing-
0016 # <a href=\"/\">docs.kde.org</a>              <a href=\"index.html\">Home</a>
0017 #
0018 # The script should be started in the directory where the file index.xml
0019 # is located. The output files will be generated in the same directory.
0020 #
0021 # (C) 2007,2009 by Thomas Baumgart (ipwizard at users.sourceforge.net)
0022 #
0023 #***************************************************************************
0024 #*   This program is free software; you can redistribute it and/or modify  *
0025 #*   it under the terms of the GNU General Public License as published by  *
0026 #*   the Free Software Foundation; either version 2 of the License, or     *
0027 #*   (at your option) any later version.                                   *
0028 #***************************************************************************/
0029 
0030 
0031 sub endFile
0032 {
0033     close OUT;
0034     $fileIdx--;
0035     if($fileIdx > 0) {
0036         open(OUT, ">> $fname[$fileIdx]") or die("Unable to open file");
0037     }
0038 }
0039 
0040 sub startFile
0041 {
0042     $fileIdx++;
0043     my $node = shift;
0044     $node =~ /FILENAME filename="(.*)"/;
0045     my $name = $1;
0046     $fname[$fileIdx] = $name;
0047     open(OUT, "> $fname[$fileIdx]") or die("Unable to open file");
0048 }
0049 
0050 sub processLine
0051 {
0052     my $line = shift;
0053     # .....</FILENAME>....
0054     if($line =~ /(.*)(<\/FILENAME>)(.*)/) {
0055         my $s = $1;
0056         my $e = $3;
0057         processLine($s);
0058         endFile();
0059         processLine($e);
0060     }
0061     # .....<FILENAME filename="index.html">....
0062     elsif($line =~ /(.*)(<FILENAME filename="[^>\"]*">)(.*)/) {
0063         my $s = $1;
0064         my $f = $2;
0065         my $e = $3;
0066         processLine($s);
0067         startFile($f);
0068         processLine($e);
0069     }
0070     else {
0071         # replace HEAD/common with ../common
0072         $line =~ s#/HEAD/common#../common#g;
0073         # don't show access to search form
0074         $line =~ s#<a href=\"/search_form.html\">Search</a>##g;
0075         # don't link to docs.kde.org
0076         $line =~ s#<a href=\"/\">docs.kde.org</a>#<a href=\"index.html\">Home</a>#g;
0077         print OUT "$line\n";
0078     }
0079 }
0080 
0081 $fileIdx = 0;
0082 open(IN, "< index.xml");
0083 while(<IN>) {
0084     chomp($_);
0085     my $line = $_;
0086     processLine($line);
0087 }
0088 close IN;