| 1 |
#!/usr/bin/perl |
| 2 |
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' |
| 3 |
if 0; # not running under some shell |
| 4 |
|
| 5 |
use strict; |
| 6 |
use XML::DOM; |
| 7 |
use WAP::wbxml; |
| 8 |
|
| 9 |
usage() unless @ARGV; |
| 10 |
usage() if $ARGV[0] eq '-h'; |
| 11 |
|
| 12 |
my $infile = $ARGV[0]; |
| 13 |
my $outfile = $ARGV[1]; |
| 14 |
|
| 15 |
my $parser = new XML::DOM::Parser; |
| 16 |
my $doc = $parser->parsefile($infile); |
| 17 |
my $encoding = $doc->getXMLDecl()->getEncoding(); |
| 18 |
my $publicid = $doc->getDoctype()->getPubId(); |
| 19 |
die "$0: error: no PublicId.\n" unless ($publicid); |
| 20 |
|
| 21 |
my $rules = WbRules->Load(); |
| 22 |
my $wbxml = new WbXml($rules, $publicid); |
| 23 |
my $output = $wbxml->compile($doc, $encoding); |
| 24 |
$outfile ||= $wbxml->outfile($infile); |
| 25 |
|
| 26 |
open OUT, ">$outfile" or die "$0: cannot write '$outfile': $! "; |
| 27 |
binmode OUT, ":raw"; |
| 28 |
print OUT $output; |
| 29 |
close OUT; |
| 30 |
|
| 31 |
sub usage { |
| 32 |
print STDERR "usage: $0 input.wml [output.wmlc]\n"; exit |
| 33 |
} |