#!/usr/bin/perl
open FILELIST, ">GNUstep.hhp";
print FILELIST '[OPTIONS]', "\n";
print FILELIST 'Binary TOC=Yes', "\n";
print FILELIST 'Compatibility=1.1 or later', "\n";
print FILELIST 'Compiled file=GNUstep.chm', "\n";
print FILELIST 'Contents file=GNUstep.hhc', "\n";
print FILELIST 'Default Window=Help Viewer', "\n";
print FILELIST 'Default topic=index.html', "\n";
print FILELIST 'Display compile progress=No', "\n";
print FILELIST 'Full-text search=Yes', "\n";
print FILELIST 'Index file=GNUstep.hhk', "\n";
print FILELIST 'Language=0x409 English (United States)', "\n";
print FILELIST 'Title=GNUstep System Documentation', "\n";
print FILELIST '', "\n";
print FILELIST '', "\n";
print FILELIST '[INFOTYPES]', "\n";
print FILELIST '', "\n";
print FILELIST '[WINDOWS]', "\n";
print FILELIST 'Help Viewer=,"GNUstep.hhc","GNUstep.hhk","index.html",,,,,,0x40520,,0x280e,,0x30000,,,,,,0', "\n";
print FILELIST '', "\n";
print FILELIST '[FILES]', "\n";
print FILELIST 'index.html', "\n";
print FILELIST 'style.css', "\n";
print FILELIST 'masthead-bg.jpg', "\n";
open TOC, ">GNUstep.hhc";
print TOC '', "\n";
print TOC '', "\n";
print TOC '
', "\n";
print TOC ' ', "\n";
print TOC '', "\n";
print TOC '', "\n";
print TOC '', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC '', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
print TOC ' ', "\n";
open IDX, ">GNUstep.hhk";
print IDX '', "\n";
print IDX '', "\n";
print IDX '', "\n";
print IDX ' ', "\n";
print IDX '', "\n";
print IDX '', "\n";
print IDX '', "\n";
# Generated items start here
# User FAQ
toc_entry('User FAQ', 'User/GNUstep/userfaq.html');
print TOC "\n";
parse_toc('User/GNUstep', 'userfaq_toc.html');
print TOC " \n";
# Developer FAQ
toc_entry('Developer FAQ', 'User/GNUstep/faq.html');
print TOC "\n";
parse_toc('User/GNUstep', 'faq_toc.html');
print TOC " \n";
# How-To
toc_entry('How-To', 'User/GNUstep/gnustep-howto.html');
print TOC "\n";
parse_toc('User/GNUstep', 'gnustep-howto_toc.html');
print TOC " \n";
# Filesystem Layout
toc_entry('Filesystem Layout', 'User/GNUstep/filesystem.html');
print TOC "\n";
parse_toc('User/GNUstep', 'filesystem_toc.html');
print TOC " \n";
# Base Programming Manual
toc_entry('Objective-C GNUstep Base Programming Manual', 'Developer/Base/ProgrammingManual/manual.html');
print TOC "\n";
parse_toc('Developer/Base/ProgrammingManual', 'manual_toc.html');
print TOC " \n";
# Make Utility
toc_entry('Make Utility', 'Developer/Make/Manual/make.html');
print TOC "\n";
parse_toc('Developer/Make/Manual', 'make_toc.html');
print TOC " \n";
# Developer/Tools/Reference/index.html
# Command-line Tools
toc_entry('Command-line Tools', 'Developer/Tools/Reference/BaseTools.html');
print TOC "\n";
parse_gsdoc_index('Developer/Tools/Reference', 'MainIndex.html');
print TOC " \n";
build_gsdoc_index('Developer/Tools/Reference');
# Developer/Base/Reference
# Base Library API
toc_entry('Base Library API', 'Developer/Base/Reference/Base.html');
print TOC "\n";
#Developer/Base/ReleaseNotes/ReleaseNotes.html
toc_entry('Release Notes', 'Developer/Base/ReleaseNotes/ReleaseNotes.html', 1);
parse_gsdoc_index('Developer/Base/Reference', 'MainIndex.html');
print TOC " \n";
build_gsdoc_index('Developer/Base/Reference');
# Developer/BaseAdditions/Reference
# Base Additions API
toc_entry('Base Additions API', 'Developer/BaseAdditions/Reference/BaseAdditions.html');
print TOC "\n";
parse_gsdoc_index('Developer/BaseAdditions/Reference', 'MainIndex.html');
print TOC " \n";
build_gsdoc_index('Developer/BaseAdditions/Reference');
toc_entry('OpenStep and OS X Compliance', 'Developer/Base/General/OpenStepCompliance.html');
# Developer/CodingStandards/coding-standards_toc.html">GNUstep Coding Standards
toc_entry('GNUstep Coding Standards', 'Developer/CodingStandards/coding-standards.html');
print TOC "\n";
parse_toc('Developer/CodingStandards', 'coding-standards_toc.html');
print TOC " \n";
toc_entry('Debugging Information', 'Developer/Base/General/Debugging.html');
print IDX ' ', "\n";
print IDX '', "\n";
close IDX;
print TOC ' ', "\n";
print TOC '', "\n";
close TOC;
close FILELIST;
exit 0;
sub parse_toc($$) {
my $path = $_[0];
my $tocfile = $_[1];
my $depth = 0;
my %newfiles;
print FILELIST "$path/$tocfile\n";
$newfiles{$tocfile} = 1;
open INFILE, "<$path/$tocfile";
while () {
if (//) {
$depth++;
if ($depth > 1) {
print TOC "\n";
}
}
if (/<\/UL>/) {
$depth--;
if ($depth >= 1) {
print TOC " \n";
}
}
if (/([^<]*)<\/A>/) {
my $file = $1;
my $topic = $2;
my $desc = $3;
if (!$newfiles{$file}) {
print FILELIST "$path/$file\n";
$newfiles{$file} = 1;
}
$desc =~ s/^\s*[0-9]+(\.[0-9]+(\.[0-9]+(\.[0-9]+)?)?)?\.?\s*//;
toc_entry($desc, $path."/".$file.$topic);
idx_entry($desc, $path."/".$file.$topic);
}
}
close INFILE;
}
sub toc_entry($$;$) {
my $desc = $_[0];
my $link = $_[1];
my $new = $_[2];
print TOC ' ', "\n";
print TOC " \n";
if ($link ne "") {
print TOC " \n";
}
if ($new) {
print TOC " \n";
}
print TOC ' ', "\n";
}
sub idx_entry($$) {
my $desc = $_[0];
my $link = $_[1];
print IDX ' ', "\n";
print IDX " \n";
print IDX " \n";
print IDX ' ', "\n";
}
sub parse_gsdoc_index($$) {
my $path = $_[0];
my $index = $_[1];
open GSINDEX, "<$path/$index";
while () {
if (/]*>([^<]*)<\/A>/) {
my $file = $1;
my $desc = $2;
toc_entry($desc, "");
print TOC "\n";
parse_gsdoc_toc($path, $file);
print TOC " \n";
}
}
close GSINDEX;
}
sub parse_gsdoc_toc($$) {
my $path = $_[0];
my $tocfile = $_[1];
open GSTOC, "<$path/$tocfile";
while () {
if (/([^<]*)<\/a>/) {
toc_entry($2, "$path/$1");
}
}
close GSTOC;
}
sub build_gsdoc_index($)
{
my $path=$_[0];
my $name;
opendir DIR, $path;
while ($name = readdir(DIR)) {
next if ($name eq "." || $name eq "..");
next if ($name =~ /TOC\.html$/);
if ($name =~ /\.html$/) {
#print $name, "\n";
open FILE, "<$path/$name";
my $class="";
while () {
chomp;
if (/([^<]*)<\/a>/) {
my $ref = $1;
my $desc= $2;
next if ($ref =~ /^ivariable\$/); #We don't need ivars in the index
if ($ref =~ /^class\$(.*)$/) {
$class=$1;
}
if ($ref =~ /^method\$(.*)$/) {
$desc = $1;
$desc =~ s/\$/:/g;
if ($desc =~ /(.+)\([^\)]*\)([-+].*)/) {
my $altdesc = $1.$2;
idx_entry($altdesc, "$path\\$name#$ref");
}
}
if ($ref =~ /^category\$(.*)$/) {
$desc = $1;
$desc =~ s/\$/:/g;
}
idx_entry($desc, "$path\\$name#$ref");
}
}
close FILE;
}
}
closedir DIR;
}