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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#!@PERL@ -w
# gen_codestructure_doc - generate code_structure.html from dir_contents files
#
# Copyright (C) 2007 Olly Betts
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use POSIX;
if (scalar @ARGV < 2) {
die "usage: gen_codestructure_doc <output> <root input> [<input>...]\n";
}
my $output = shift @ARGV;
my $version = html_escape("@PACKAGE_STRING@");
my %desc = ();
my $rootdir = $ARGV[0];
$rootdir =~ s![^/]+$!!;
for my $dir_contents (@ARGV) {
open DIR_CONTENTS, "<$dir_contents" or die "$dir_contents: $!\n";
local $/ = undef;
my $xml = <DIR_CONTENTS>;
close DIR_CONTENTS;
my ($xmldir) = ($xml =~ m!<Directory>\s*(\S+)\s*</Directory>!);
if (!defined $xmldir) {
die "$dir_contents: No valid <Directory> tag found\n";
}
if ($xmldir eq "ROOT") {
$xmldir = "";
}
my $dir = $dir_contents;
unless ($dir =~ s!^\Q$rootdir\E!!) {
die "$dir_contents: not under `$rootdir'.\n";
}
$dir =~ s![^/]+$!!;
$dir =~ s!/$!!;
if ($dir ne $xmldir) {
die "$dir_contents: File is in `$dir', but <Directory> says `$xmldir'\n";
}
my ($desc) = ($xml =~ m!<Description>\s*(.*?)\s*</Description>!s);
if (!defined $desc) {
die "$dir_contents: No valid <Description> tag found\n";
}
$desc{$dir} = $desc;
}
my $output_tmp = $output . "T";
open OUTPUT, ">$output_tmp" or die "$output_tmp: $!\n";
print OUTPUT <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- automatically generated from $version source code -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Xapian: Code structure</title>
</head>
<body bgcolor="white" text="black">
<h1>Index</h1>
EOF
my $depth = -1;
for my $dir (sort keys(%desc)) {
my $tmp = $dir;
my $d = $tmp =~ s!/!!g;
if ($d <= $depth) {
print OUTPUT "</ul>\n" x ($depth - $d);
} else {
print OUTPUT "<ul>\n" x ($d - $depth);
}
$depth = $d;
if ($dir eq "") {
$dir = "ROOT";
}
my $id = $dir;
$id =~ s!_!__!g;
$id =~ s!/+!_!g;
print OUTPUT "<li><a href=\"#$id\">$dir</a>\n";
}
if ($depth >= 0) {
print OUTPUT "</ul>\n" x ($depth + 1);
}
print OUTPUT "<hr>\n";
print OUTPUT "<h1>Directory structure</h1>\n";
foreach my $dir (sort keys(%desc)) {
my $desc = $desc{$dir};
my $tmp = $dir;
my $d = $tmp =~ s!/!!g;
$d += 2;
if ($d > 6) {
$d = 6;
}
my $url = "http://trac.xapian.org/browser/tags/@VERSION@/xapian-core/$dir";
if ($dir eq "") {
$dir = "ROOT";
} else {
$url .= "/";
}
my $id = $dir;
$id =~ s!_!__!g;
$id =~ s!/+!_!g;
print OUTPUT "<div id=\"$id\">\n";
print OUTPUT "<h$d><a href=\"$url\">$dir</a></h$d>\n";
print OUTPUT "<p>", html_escape($desc), "</p>\n";
print OUTPUT "</div>\n\n";
}
my $date = POSIX::strftime("%Y-%m-%d", gmtime());
print OUTPUT <<EOF;
<hr>
<address>
Generated for $version on $date by gen_codestructure_doc.
</address>
</body>
</html>
EOF
unless (close OUTPUT) {
my $bang = $!;
unlink $output_tmp;
die "$output_tmp: $bang\n";
}
rename $output_tmp, $output or die "$output: $!\n";
sub html_escape {
my $s = shift;
$s =~ s/&/&/g;
$s =~ s/</</g;
$s =~ s/>/>/g;
$s =~ s/\n\n/\n\n<p>/g;
return $s;
}
|