#!/usr/bin/perl -w # # The FreeBSD Japanese Documentation Project # # This is a preprocessor for HTML docs. # # usage: prehtml [-revcheck] # (ex. % prehtml -revcheck ../.. news/1996 index.sgml) # # $FreeBSD$ 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}/../${reldir}$_"; $rev{org} = get_rev_org("${topdir}/../en/${reldir}$_".".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($_ = )) { if(/)) { if(tell(TARGET) == $pos_date) { print qq|\n|; print qq|\n|; if($revcheck) { #print STDERR "$rev{org} -> $rev{target}\n"; print qq|\n|; print qq|\n|; print qq|\n|; print qq|\n|; print qq|\n|; printf "\n", ($rev{org} eq $rev{target}) ? "IGNORE" : "INCLUDE"; } } else { # for backward compatibility s/ \%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($_ = )) { if(/\x24Free[B]SD: [^\s]+ ([.0-9]+) [\/0-9]+[^\x24]*\x24/) { $rev_org = $1; last; } } close ORG; return $rev_org; } __END__