head	1.5;
access;
symbols
	HRS_XML_CLEANUP:1.5
	HRS_XML_CLEANUP_PRE:1.5
	EMILYBOYD_REDESIGN:1.5
	PRE_REDESIGN:1.5
	XML_XSL_XP:1.5.0.2
	XML_XSL_XP_BP:1.5;
locks; strict;
comment	@# @;


1.5
date	2001.01.01.18.41.42;	author hrs;	state Exp;
branches;
next	1.4;

1.4
date	2000.12.28.06.59.10;	author hrs;	state Exp;
branches;
next	1.3;

1.3
date	2000.10.31.10.14.38;	author kuriyama;	state Exp;
branches;
next	1.2;

1.2
date	2000.10.03.11.10.47;	author hrs;	state Exp;
branches;
next	1.1;

1.1
date	2000.10.02.09.16.04;	author kuriyama;	state Exp;
branches;
next	;


desc
@@


1.5
log
@- Merge the following from the English version:

	1.91  -> 1.93 	projects/projects.sgml

- Fix malformed &enbase; definition:

	prehtml
	internal/about.sgml
	ports/portindex

Pointed out by:	wosch
@
text
@#!/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.4 2000/12/28 06:59:10 hrs 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}/../${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($_ = <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-NOT-FOUND";
$rev{org}    ||= "ORG-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}/..'>\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__
@


1.4
log
@- Merge the following from the English version:

	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).
@
text
@d10 1
a10 1
# $FreeBSD: www/ja/prehtml,v 1.3 2000/10/31 10:14:38 kuriyama Exp $
d61 2
a62 2
                $file{orgbase} = "${topdir}/../en/${reldir}$_";
                $rev{org} = get_rev_org($file{orgbase}.".sgml");
d104 2
a105 2
$rev{target} ||= "TARGET revision not found";
$rev{org}    ||= "ORG revision not found";
d125 1
a125 1
            print qq|<!ENTITY enbase CDATA '${topdir}/../en'>\n|;
@


1.3
log
@Escape period and $.
@
text
@d7 1
a7 1
# usage: prehtml [-revcheck <localtop> <relative to localtop>] <SGML filename>
d10 1
a10 1
# $FreeBSD: www/ja/prehtml,v 1.2 2000/10/03 11:10:47 hrs Exp $
d27 2
d32 3
a34 3
        # option expected        
        if(/^-(.+)/) {
            shift @@ARGV; # discard option itself;
d36 3
a38 9
            /revcheck/ and do {
                $topdir = shift @@ARGV;
                $reldir = shift @@ARGV;
                if($reldir ne '' and $reldir !~ /\/$/) {
                    $reldir .= "/";
                }
                $revcheck = 1;
                next;
            };
d45 25
a69 7
        $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");
d73 1
a73 1
    die "internal error: option parsing abnormally terminated.\n";
d78 1
a78 1
open TARGET,"<$file{target}" or die "cannot open a target file: $!\n";
d84 2
a85 2
        if(m/\"\x24FreeBSD: [^\s]+ [.0-9]+ ([\/0-9]+)[^\$]*\$\"/) {
            $date = "<!ENTITY date \"Last modified: $1\">";
d87 1
a87 1
            $date = "<!ENTITY date \"Last modified: UNKNOWN\">";
d111 1
a111 1
        die qq/element "date" or "title" is not defined.\n/;
d117 1
a117 1
### $date + entity difinitions for revcheck 
d121 2
a122 1
        print $date,"\n";
d125 5
a129 5
            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";
d149 1
a149 1
        if(/\$Free[B]SD: [^\s]+ ([.0-9]+) [\/0-9]+[^\$]*\$/) {
@


1.2
log
@- Merge the following from the English version:

	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
@
text
@d10 1
a10 1
# $FreeBSD: www/ja/prehtml,v 1.1 2000/10/02 09:16:04 kuriyama Exp $
d51 1
a51 1
            s/.sgml$//;
d70 1
a70 1
        if(m/\"\$Free[B]SD: [^\s]+ [.0-9]+ ([\/0-9]+)[^\$]*\$\"/) {
@


1.1
log
@Clean-up around directory traversing and revision checking.

Submitted by:	hrs
@
text
@d10 1
a10 1
# $FreeBSD$
d68 1
a68 1
    if(/<!ENTITY\s+date\s+\"\$Free[B]SD: [^\s]+ [.0-9]+ ([\/0-9]+)[^\$]*\$\">/) {
d70 8
a77 1
        $date = "<!ENTITY date \"Last modified: $1\">";
d92 9
@

