#
# cf_generate.pl
#
# cf_generate: Build the files cf_byprog.html, cf_byname.html and
# attrs.html from the informations found
# in ../htcommon/defaults.cc.
# attrs.html : attrs_head.html + generation + attrs_tail.html
# cf_byprog.html : cf_byprog_head.html + generation + cf_byprog_tail.html
# cf_byname.html : cf_byname_head.html + generation + cf_byname_tail.html
#
# Part of the ht://Dig package
# Copyright (c) 1999-2004 The ht://Dig Group
# For copyright details, see the file COPYING in your distribution
# or the GNU Library General Public License (LGPL) version 2 or later
#
#
# $Id: cf_generate.pl,v 1.9 2004/06/05 04:30:47 lha Exp $
#
use strict;
use vars qw(%char2quote);
%char2quote = (
'>' => '>',
'<' => '<',
'&' => '&',
"'" => ''',
'"' => '"',
);
sub html_escape {
my($toencode) = @_;
return undef if(!defined($toencode));
$toencode =~ s;([&\"<>\']);$char2quote{$1};ge;
return $toencode;
}
#
# Read and parse attributes descriptions found in defaults.cc
#
my($dir);
if (scalar(@ARGV) == 0) {
$dir = '..';
}
else {
$dir = @ARGV[0];
}
local($/) = undef;
my($file) = $dir . "/htcommon/defaults.cc";
my($content);
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
close(FILE);
#
# Change curly to square brackets to generate perl arrays instead
# of hashes. Order is important.
#
$content =~ s/.*ConfigDefaults.*?\{(.*)\{0, 0.*/[$1]/s;
$content =~ s/\s*\\*$//mg;
$content =~ s/([\@\$])/\\$1/gs;
$content =~ s/^\{/\[/mg;
$content =~ s/^\"\s*\},$/\" \],/mg;
#
# Transform macro substituted strings by @strings@ (substitued by ../configure)
# Three step process ( -> \@ string\@ -> \@string\@ -> @string@ )
# as perl seems to get confused by @$2.
#
$content =~ s|^(\[ \"\w+\", )([A-Z].*?),\n|$1\"\\\@$2\\@\",\n|mg;
#$content =~ s/^(\[ \"\w+\", )\"(.*?)\"(.*?)\"(.*?)\",\n/$1\"$2\\\"$3\\\"$4\",\n/mg;
$content =~ s/BIN_DIR/bindir/g;
my($config);
eval "\$config = $content";
if(!$config) {
die "could not extract any configuration info from $file";
}
#
# Spit the HTML pages
#
my($file);
#
# Complete list of attributes with descriptions and examples.
#
$file = "attrs.html.in";
open(ATTR, ">$file") or die "cannot open $file for writing : $!";
$file = $dir . "/htdoc/attrs_head.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
print ATTR $content;
close(FILE);
#
# Index by attribute name
#
$file = "cf_byname.html";
open(BYNAME, ">$file") or die "cannot open $file for writing : $!";
$file = $dir . "/htdoc/cf_byname_head.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
print BYNAME $content;
close(FILE);
my($letter) = '';
my($record);
foreach $record (@$config) {
my($name, $default, $type, $programs, $block, $version, $category, $example, $description) = @$record;
if($letter ne uc(substr($name, 0, 1))) {
print BYNAME "\t
\n" if($letter);
$letter = uc(substr($name, 0, 1));
print BYNAME "\t$letter
\n";
}
print BYNAME "\t
$name
\n";
my($used_by) = join(",\n\t\t\t",
map {
my($top) = $_ eq 'htsearch' ? " target=\"_top\"" : "";
"$_";
}
split(' ', $programs));
if ($block eq '') {
$block = "Global";
}
if($version != 'all') {
$version = "$version or later";
}
if(!($example =~ /^$name:/)) {
$example = "\t\t\t No example provided |
\n";
} elsif($example =~ /\A$name:\s*\Z/s) {
$example = "\t\t\t $name: |
\n";
} else {
my($one);
my($html) = '';
foreach $one (split("$name:", $example)) {
next if($one =~ /^\s*$/);
$html .= <
$name:
|
$one
|
EOF
}
$example = $html;
}
if($default =~ /^\s*$/) {
$default = "No default";
} else {
$default =~ s/^([A-Z][A-Z_]*) \" (.*?)\"/$1 $2/; # for PDF_PARSER
$default = html_escape($default);
# hyperlink default values defined in terms of other attributes
$default =~ s/\${([A-Za-z_]*)}/\${$1<\/a>}/;
}
print ATTR <
$name
-
type:
-
$type
-
used by:
-
$used_by
-
default:
-
$default
-
block:
-
$block
-
version:
-
$version
-
description:
- $description
-
example:
-
EOF
}
open(FILE, "date |") or die "cannot open pipe to date command for reading : $!";
$content = ;
close(FILE);
my($date) = $content;
my($file) = $dir . "/htdoc/attrs_tail.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
$content =~ s/Last modified: [^\n]*\n/Last modified: $date/;
print ATTR $content;
close(FILE);
my($file) = $dir . "/htdoc/cf_byname_tail.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
print BYNAME $content;
close(FILE);
close(ATTR);
close(BYNAME);
#
# Index by program name
#
$file = "cf_byprog.html";
open(BYPROG, ">$file") or die "cannot open $file for writing : $!";
$file = $dir . "/htdoc/cf_byprog_head.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
print BYPROG $content;
close(FILE);
my(%prog2attr);
foreach $record (@$config) {
my($name, $default, $type, $programs, $example, $description) = @$record;
my($prog);
foreach $prog (split(' ', $programs)) {
push(@{$prog2attr{$prog}}, $record);
}
}
my($prog);
foreach $prog (sort(keys(%prog2attr))) {
my($top) = $prog eq 'htsearch' ? "target=\"_top\"" : "target=\"body\"";
print BYPROG "\t
$prog
\n";
my($record);
foreach $record (@{$prog2attr{$prog}}) {
my($name, $default, $type, $programs, $example, $description) = @$record;
print BYPROG "\t
$name
\n";
}
}
my($file) = $dir . "/htdoc/cf_byprog_tail.html";
open(FILE, "<$file") or die "cannot open $file for reading : $!";
$content = ;
print BYPROG $content;
close(FILE);
close(BYPROG);