ba904efd64
1.92 -> 1.93 index.sgml 1.10 -> 1.11 internal/developer.sgml 1.2 -> 1.3 ports/Makefile.inc0 - Fix routines around $pos_date for malformed $FreeBSD:...$: prehtml
143 lines
3.8 KiB
Perl
Executable file
143 lines
3.8 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 to localtop>] <SGML filename>
|
|
# (ex. % prehtml -revcheck ../.. news/1996 index.sgml)
|
|
#
|
|
# $FreeBSD: www/ja/prehtml,v 1.1 2000/10/02 09:16:04 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;
|
|
|
|
while(defined($_ = $ARGV[0])) {
|
|
|
|
if ($opt_state eq sOPT) {
|
|
# option expected
|
|
if(/^-(.+)/) {
|
|
shift @ARGV; # discard option itself;
|
|
local $_ = $1;
|
|
/revcheck/ and do {
|
|
$topdir = shift @ARGV;
|
|
$reldir = shift @ARGV;
|
|
if($reldir ne '' and $reldir !~ /\/$/) {
|
|
$reldir .= "/";
|
|
}
|
|
$revcheck = 1;
|
|
next;
|
|
};
|
|
} else {
|
|
# this is not a option but an argument
|
|
$opt_state = sARG;
|
|
next;
|
|
}
|
|
} elsif ($opt_state eq sARG) {
|
|
$file{target} = $_;
|
|
if($revcheck) {
|
|
s/.sgml$//;
|
|
my $basename = $_;
|
|
$file{cvsweb} = "www/en/${reldir}${basename}.sgml";
|
|
$file{orgbase} = "${topdir}/../en/${reldir}${basename}";
|
|
$rev{org} = get_rev_org($file{orgbase}.".sgml");
|
|
}
|
|
last;
|
|
}
|
|
die "internal error: option parsing abnormally terminated.\n";
|
|
}
|
|
|
|
### add and replace entities .........................................
|
|
###
|
|
open TARGET,"<$file{target}" or die "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/\"\$Free[B]SD: [^\s]+ [.0-9]+ ([\/0-9]+)[^\$]*\$\"/) {
|
|
$date = "<!ENTITY date \"Last modified: $1\">";
|
|
} else {
|
|
$date = "<!ENTITY date \"Last modified: 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/element "date" or "title" is not defined.\n/;
|
|
}
|
|
$pos_date = $pos_title;
|
|
}
|
|
|
|
### next, put lines and replace the line with
|
|
### $date + entity difinitions for revcheck
|
|
seek TARGET,0,0;
|
|
while(defined($_ = <TARGET>)) {
|
|
if(tell(TARGET) == $pos_date) {
|
|
print $date,"\n";
|
|
if($revcheck) {
|
|
#print STDERR "$rev{org} -> $rev{target}\n";
|
|
print "<!ENTITY base CDATA '$topdir'>\n";
|
|
print "<!ENTITY file.cvsweb CDATA '$file{cvsweb}'>\n";
|
|
print "<!ENTITY file.orgbase CDATA '$file{orgbase}'>\n";
|
|
print "<!ENTITY rev.latest CDATA '$rev{org}'>\n";
|
|
print "<!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(/\$Free[B]SD: [^\s]+ ([.0-9]+) [\/0-9]+[^\$]*\$/) {
|
|
$rev_org = $1;
|
|
last;
|
|
}
|
|
}
|
|
close ORG;
|
|
return $rev_org;
|
|
}
|
|
|
|
__END__
|