d560e5620b
1.55 -> 1.58 Makefile 1.95 -> 1.100 index.sgml 1.201 -> 1.206 support.sgml 1.88 -> 1.91 projects/projects.sgml 1.55 -> 1.58 search/search.sgml 1.17 -> 1.18 tutorials/index.sgml - Add &enbase; into "prehtml" script to support not-translated docs. This was defined in ja/tutorials/index.sgml only. Prehtml now requires at least two arguments "localtop" and "relative path from localtop". Using prehtml w/ and w/o a option -revcheck, we don't need a definition of &base; in individual SGML files because prehtml generates it automatically (of course, it doesn't break build process of conventional docs).
158 lines
4.3 KiB
Perl
Executable file
158 lines
4.3 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
#
|
|
# The FreeBSD Japanese Documentation Project
|
|
#
|
|
# This is a preprocessor for HTML docs.
|
|
#
|
|
# usage: prehtml [-revcheck] <localtop> <relative pathname from localtop> <SGML filename>
|
|
# (ex. % prehtml -revcheck ../.. news/1996 index.sgml)
|
|
#
|
|
# $FreeBSD: www/ja/prehtml,v 1.3 2000/10/31 10:14:38 kuriyama Exp $
|
|
|
|
my $revcheck;
|
|
my $topdir;
|
|
my $reldir;
|
|
|
|
my %file;
|
|
my %rev;
|
|
|
|
### parse options ....................................................
|
|
###
|
|
sub sOPT {1};
|
|
sub sARG {2};
|
|
|
|
my $opt_state = sOPT;
|
|
my $argv;
|
|
|
|
die "$0: too few arguments.\n" if (scalar @ARGV < 2);
|
|
|
|
while(defined($_ = $ARGV[0])) {
|
|
|
|
if ($opt_state eq sOPT) {
|
|
# option expected
|
|
if(/^-(.+)/) {
|
|
shift @ARGV; # discard option itself
|
|
local $_ = $1;
|
|
/revcheck/ and do { $revcheck = 1; next; };
|
|
|
|
die qq/$0: invalid option "-$1"\n/;
|
|
} else {
|
|
# this is not a option but an argument
|
|
$opt_state = sARG;
|
|
next;
|
|
}
|
|
} elsif ($opt_state eq sARG) {
|
|
die "$0: too few arguments.\n" if (scalar @ARGV < 2);
|
|
|
|
$topdir = shift @ARGV;
|
|
$reldir = shift @ARGV;
|
|
|
|
### normalize $reldir into the form "foo/bar/"
|
|
if($reldir ne '' and $reldir !~ /\/$/) {
|
|
$reldir .= "/";
|
|
}
|
|
|
|
if(@ARGV) {
|
|
$file{target} = shift @ARGV;
|
|
if($revcheck) {
|
|
local $_ = $file{target};
|
|
s/\.sgml$//;
|
|
$file{cvsweb} = "www/en/${reldir}$_.sgml";
|
|
$file{orgbase} = "${topdir}/../en/${reldir}$_";
|
|
$rev{org} = get_rev_org($file{orgbase}.".sgml");
|
|
}
|
|
} else {
|
|
### If not specified SGML filename, then use stdin
|
|
### (but revcheck facility is disabled).
|
|
### This is mainly for debugging purpose.
|
|
$file{target} = "-";
|
|
undef $revcheck;
|
|
}
|
|
last;
|
|
}
|
|
die "$0: internal error: option parsing abnormally terminated.\n";
|
|
}
|
|
|
|
### add and replace entities .........................................
|
|
###
|
|
open TARGET,"<$file{target}" or die "$0: cannot open a target file: $!\n";
|
|
my $pos_date;
|
|
### first, get date string and rev_target
|
|
while(defined($_ = <TARGET>)) {
|
|
if(/<!ENTITY\s+date/) {
|
|
$pos_date = tell(TARGET);
|
|
if(m/\"\x24FreeBSD: [^\s]+ [.0-9]+ ([\/0-9]+)[^\x24]*\x24\"/) {
|
|
$date = $1;
|
|
} else {
|
|
$date = "UNKNOWN";
|
|
}
|
|
}
|
|
if(/<!ENTITY\s+title/) {
|
|
$pos_title = tell(TARGET);
|
|
}
|
|
|
|
if($revcheck) {
|
|
if(/[Oo]riginal [Rr]evision:[ \t]*([0-9.]+)/) {
|
|
$rev{target} = $1;
|
|
}
|
|
last if($revcheck and $rev{target} and $date);
|
|
} else {
|
|
last if($date);
|
|
}
|
|
}
|
|
|
|
$rev{target} ||= "TARGET revision not found";
|
|
$rev{org} ||= "ORG revision not found";
|
|
|
|
### if offset of "date" string is not found,
|
|
### use "title"'s instead.
|
|
if(not defined $pos_date) {
|
|
if(not defined $pos_title) {
|
|
die qq/$0: element "date" or "title" is not defined.\n/;
|
|
}
|
|
$pos_date = $pos_title;
|
|
}
|
|
|
|
### next, put lines and replace the line with
|
|
### $date + entity definitions for revcheck
|
|
seek TARGET,0,0;
|
|
while(defined($_ = <TARGET>)) {
|
|
if(tell(TARGET) == $pos_date) {
|
|
print qq|<!ENTITY date CDATA 'Last modified: ${date}'>\n|;
|
|
print qq|<!ENTITY base CDATA '${topdir}'>\n|;
|
|
if($revcheck) {
|
|
#print STDERR "$rev{org} -> $rev{target}\n";
|
|
print qq|<!ENTITY enbase CDATA '${topdir}/../en'>\n|;
|
|
print qq|<!ENTITY file.cvsweb CDATA '$file{cvsweb}'>\n|;
|
|
print qq|<!ENTITY file.orgbase CDATA '$file{orgbase}'>\n|;
|
|
print qq|<!ENTITY rev.latest CDATA '$rev{org}'>\n|;
|
|
print qq|<!ENTITY rev.target CDATA '$rev{target}'>\n|;
|
|
printf "<!ENTITY %% rev.diff '%s'>\n", ($rev{org} eq $rev{target}) ? "IGNORE" : "INCLUDE";
|
|
}
|
|
} else {
|
|
# for backward compatibility
|
|
s/<!ENTITY \% rev.incl SYSTEM "[-a-zA-Z0-9]+.revinc"> \%rev.incl;//;
|
|
print;
|
|
}
|
|
}
|
|
close TARGET;
|
|
|
|
exit 0;
|
|
|
|
sub get_rev_org
|
|
{
|
|
my $infile = shift @_;
|
|
my $rev_org;
|
|
|
|
open ORG,"<$infile" or return undef;
|
|
while(defined($_ = <ORG>)) {
|
|
if(/\x24Free[B]SD: [^\s]+ ([.0-9]+) [\/0-9]+[^\x24]*\x24/) {
|
|
$rev_org = $1;
|
|
last;
|
|
}
|
|
}
|
|
close ORG;
|
|
return $rev_org;
|
|
}
|
|
|
|
__END__
|