[projectaon] Re: 19wb Comment Period (Part 2)

  • From: Simon Osborne <outspaced@xxxxxxxxxxxx>
  • To: projectaon@xxxxxxxxxxxxx
  • Date: Fri, 23 Jan 2009 19:24:33 +0000

Ingo Kloecker wrote:
On Thursday 22 January 2009, Simon Osborne wrote:
Hi

Help! I can't seem to get <ch.minus/> to work at all--I just get a
blank space! This breaks Section 304 (not to mention the Combat Rules
sections for Books 1-12).

Here <ch.minus/> appears to works. How do you build the HTML files?

Using gbtoxhtml.pl specially modified to reflect my own directory structure. The simple one-page editions are fine:

<http://www.projectaon.org/test/en/xhtml-simple/lw/19wb.htm#sect304> (works)

versus:

<http://www.projectaon.org/test/en/xhtml/lw/19wb/sect304.htm> (broken)

I've attached the file--is there something I've screwed up in it? Thanks in advance for your help on this, Ingo! :-)

--
Simon Osborne
Project Aon
#!/usr/bin/perl -w
#
# gbtoxhtml.pl
#
#####

use strict;

delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; # clean house for taint mode

my $PROGRAM_NAME    = 'gbtoxhtml';
my $USAGE           = "$PROGRAM_NAME [options] book-code\n\t--meta=[metadata 
file]\n\t--xml=[book XML]\n\t--xsl=[XSL transformation]\n\t--language=[language 
area of input data (output determined by meta file)]\n\t--verbose\n";

my $FILENAME_SEPARATOR = '/';

my $RXP        = '/cygdrive/d/cygwin/bin/rxp';
my $CP         = '/cygdrive/d/cygwin/bin/cp';
my $MV         = '/cygdrive/d/cygwin/bin/mv';
my $TAR        = '/cygdrive/d/cygwin/bin/tar';
my $ZIP        = '/cygdrive/d/cygwin/bin/zip';
my $BZIP2      = '/cygdrive/d/cygwin/bin/bzip2';
my $JAVA       = '/cygdrive/d/cygwin/usr/bin/java';
my $XALAN_JAR  = 'usr/share/java/xalan2.jar';
my $RM         = '/cygdrive/d/cygwin/bin/rm';
my $CHMOD      = '/cygdrive/d/cygwin/bin/chmod';

###

my $bookCode     = '';
my $metaFile     = '';
my $bookXML      = '';
my $xhtmlXSL     = 'common/xsl/xhtml.xsl';
my $language     = 'en';

my $verbose = 0;

while( $#ARGV > -1 ) {
    my $cmdLineItem = shift @ARGV;
    if( $cmdLineItem =~ /^--meta=(.+)$/ ) {
        $metaFile = $1;
    }
    elsif( $cmdLineItem =~ /^--xml=(.+)$/ ) {
        $bookXML = $1;
    }
    elsif( $cmdLineItem =~ /^--xsl=(.+)$/ ) {
        $xhtmlXSL = $1;
    }
    elsif( $cmdLineItem =~ /^--language=(.+)$/ ) {
        $language = $1;
    }
    elsif( $cmdLineItem =~ /^--verbose/ ) {
        $verbose = 1;
    }
    else { 
        $bookCode = $cmdLineItem;
    }
}

if( $bookCode eq '' ) { die "Unspecified book code\n$USAGE"; }
if( $metaFile eq '' ) { $metaFile = "$language/.publisher/rules/standard"; }
if( $bookXML eq '' ) { $bookXML = "$language/xml/$bookCode.xml"; }
if( $xhtmlXSL eq '' ) { die "Unspecified XSL transformation file\n$USAGE"; }

if( -e $metaFile && -f $metaFile && -r $metaFile ) {
    open( META, '<', $metaFile ) or die qq{Unable to open metadata file 
($metaFile): $!\n};
}
else { die qq{Improper metadata file ($metaFile)\n}; }

my $meta = '';
while( my $line = <META> ) {
    $meta .= $line if $line !~ /^[[:space:]]*#/;
}
close META;

my $rulesString = '';
if( $meta =~ /^[[:space:]]*$bookCode[[:space:]]*{([^}]*)}/sm ) {
    $rulesString = $1;
}
else {
    die "Book code ($bookCode) not found in metadata file or invalid file 
syntax\n";
}

my @rules = split( /[[:space:]\n]*;[[:space:]\n]*/, $rulesString );
my %rulesHash;
foreach my $rule (@rules) {
    if( $rule =~ /[[:space:]]*([^:]+)[[:space:]]*:[[:space:]]*(.+)$/s ) {
        $rulesHash{ $1 } = $2;
    }
    else {
        die "Unrecognized rule syntax:\n$rule\n";
    }
}

if( $bookXML =~ m{^([-\w\@./]+)$} ) {
    $bookXML = $1;
    if( -e $bookXML && -f $bookXML && -r $bookXML ) {
#       system( $RXP, '-Vs', $bookXML ) == 0 or die( "XML validation failed\n" 
);
    }
    unless( defined $rulesHash{'language'} ) { die "Metadata file leaves 
language unspecified\n"; }
    unless( defined $rulesHash{'book-series'} ) { die "Metadata file leaves 
book series unspecified\n"; }

    my $outPath = $rulesHash{'language'} . $FILENAME_SEPARATOR . 'xhtml' . 
$FILENAME_SEPARATOR . $rulesHash{'book-series'} .$FILENAME_SEPARATOR . 
$bookCode;
    unless( -e $outPath && -d $outPath ) {
        my @dirs = split ( /$FILENAME_SEPARATOR/, $outPath );
        my $dirPath = '';
        for( my $i = 0; $i <= $#dirs; ++$i ) {
            $dirPath .= $dirs[$i] . $FILENAME_SEPARATOR;
            if( -e $dirPath && ! -d $dirPath ) { die "Output directory name 
exists and is not a directory\n"; }
            unless( -e $dirPath ) {
                mkdir $dirPath or die( "Unable to create output directory 
($outPath): $!\n" );
            }
        }
    }
    unless( -e $outPath && -d $outPath ) {
        die "Unknown error creating output directory\n";
    }

    my $bookPath = "$outPath${FILENAME_SEPARATOR}";
    print qx{$RM ${bookPath}*};
    print qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN 
"$bookXML" -XSL "$xhtmlXSL" -OUT "${bookPath}foo.xml" -PARAM background-color 
"$rulesHash{'background-color'}" -PARAM text-color "$rulesHash{'text-color'}" 
-PARAM link-color "$rulesHash{'link-color'}" -PARAM use-illustrators 
"$rulesHash{'use-illustrators'}" -PARAM language "$rulesHash{'language'}"};
    print qx{$RM ${bookPath}foo.xml};

    foreach my $cssTemplate (split( /:/, $rulesHash{'csst'} )) {
        $cssTemplate =~ m/([^${FILENAME_SEPARATOR}]+)t$/;
        my $templateFilename = $1;
        open( TEMPLATE, '<', $cssTemplate ) or die "Unable to open CSS template 
file ($cssTemplate): $!\n";
        open( STYLESHEET, '>', "$bookPath${templateFilename}" ) or die "Unable 
to open stylesheet file ($bookPath${templateFilename}) for writing: $!\n";
        while( my $templateLine = <TEMPLATE> ) {
            while( $templateLine =~ /%%([^%[:space:]]+)%%/ ) {
                my $name = $1;
                $templateLine =~ s/%%${name}%%/$rulesHash{$name}/g;
            }
            print STYLESHEET $templateLine;
        }
    }
    close TEMPLATE;
    close STYLESHEET;

    foreach my $imagePath (split( /:/, $rulesHash{'images'} )) {
        unless( -e $imagePath && -d $imagePath ) {
            die "Image path ($imagePath) does not exist or is not a 
directory\n";
        }
        print qx{$CP $imagePath${FILENAME_SEPARATOR}* $bookPath};
    }

    print qx{$TAR cf ${bookCode}.tar ${bookPath}*};
    print qx{$ZIP -8 -q ${bookCode}.zip ${bookPath}*};
    print qx{$BZIP2 -9 ${bookCode}.tar};
    print qx{$MV ${bookCode}* $bookPath};
}

print "Success\n" if $verbose;

Other related posts: