#!/usr/bin/perl
my
%opts
;
getopts(
'p:'
, \
%opts
);
my
$rules
= new Rules();
my
$parser
= new XML::SAX::ParserFactory->parser(
Handler
=>
$rules
);
my
$infile
;
if
(
$opts
{p}) {
$infile
=
$opts
{p};
}
else
{
my
$path
=
$INC
{
'WAP/wbxml.pm'
};
$path
=~ s/\.pm$//i;
$infile
=
$path
.
'/wap.wbrules.xml'
;
}
my
$io
= new IO::File(
$infile
,
'r'
);
die
"Can't open $infile ($!).\n"
unless
(
defined
$io
);
$parser
->parse_file(
$io
);
delete
$rules
->{app_curr};
delete
$rules
->{ext_curr};
my
$d
= Data::Dumper->new([
$rules
], [
qw(rules)
]);
$d
->Indent(0);
my
$outfile
=
'wbrules2.pl'
;
open
my
$OUT
,
'>'
,
$outfile
or
die
"Can't open $outfile ($!).\n"
;
print
$OUT
"# This file is generated by mkwbrules. DO NOT modify it.\n"
;
print
$OUT
"# From file : "
,
$infile
,
"\n"
;
print
$OUT
"# Generation date : "
,POSIX::ctime(
time
());
print
$OUT
$d
->Dump();
close
$OUT
;
sub
new {
my
$class
=
shift
;
my
$self
= {};
bless
(
$self
,
$class
);
return
$self
;
}
sub
start_element {
my
$self
=
shift
;
my
(
$element
) =
@_
;
my
$name
=
$element
->{Name};
my
$attrs
=
$element
->{Attributes};
if
(
$name
eq
'PublicIdentifier'
) {
$self
->{PublicIdentifier}{
hex
$attrs
->{
'{}value'
}->{Value}} =
$attrs
->{
'{}name'
}->{Value};
}
elsif
(
$name
eq
'App'
) {
my
$publicid
=
$attrs
->{
'{}publicid'
}->{Value};
$self
->{app_curr} =
$publicid
;
$self
->{App}{
$publicid
} =
bless
({},
'App'
);
$self
->{App}{
$publicid
}->{variable_subs} =
$attrs
->{
'{}variable-subs'
}->{Value}
if
(
exists
$attrs
->{
'{}variable-subs'
}
and
$attrs
->{
'{}variable-subs'
}->{Value} eq
'yes'
);
$self
->{App}{
$publicid
}->{systemid} =
$attrs
->{
'{}systemid'
}->{Value}
if
(
exists
$attrs
->{
'{}systemid'
});
}
elsif
(
$name
eq
'TAG'
) {
my
$token
=
hex
$attrs
->{
'{}token'
}->{Value};
$token
+= 256 *
hex
$attrs
->{
'{}codepage'
}->{Value}
if
(
exists
$attrs
->{
'{}codepage'
});
$self
->{App}{
$self
->{app_curr}}->{TAG}{
$token
} =
$attrs
->{
'{}name'
}->{Value};
$self
->{App}{
$self
->{app_curr}}->{TagEncoding}{
$token
} =
$attrs
->{
'{}encoding'
}->{Value}
if
(
exists
$attrs
->{
'{}encoding'
});
}
elsif
(
$name
eq
'ATTRSTART'
) {
my
$token
=
hex
$attrs
->{
'{}token'
}->{Value};
$token
+= 256 *
hex
$attrs
->{
'{}codepage'
}->{Value}
if
(
exists
$attrs
->{
'{}codepage'
});
$self
->{App}{
$self
->{app_curr}}->{ATTRSTART}{
$token
} = {};
$self
->{App}{
$self
->{app_curr}}->{ATTRSTART}{
$token
}{name} =
$attrs
->{
'{}name'
}->{Value};
$self
->{App}{
$self
->{app_curr}}->{ATTRSTART}{
$token
}{value} =
$attrs
->{
'{}value'
}->{Value}
if
(
exists
$attrs
->{
'{}value'
});
$self
->{App}{
$self
->{app_curr}}->{ATTRSTART}{
$token
}{validate} =
$attrs
->{
'{}validate'
}->{Value}
if
(
exists
$attrs
->{
'{}validate'
});
$self
->{App}{
$self
->{app_curr}}->{ATTRSTART}{
$token
}{encoding} =
$attrs
->{
'{}encoding'
}->{Value}
if
(
exists
$attrs
->{
'{}encoding'
});
}
elsif
(
$name
eq
'ATTRVALUE'
) {
my
$token
=
hex
$attrs
->{
'{}token'
}->{Value};
$token
+= 256 *
hex
$attrs
->{
'{}codepage'
}->{Value}
if
(
exists
$attrs
->{
'{}codepage'
});
$self
->{App}{
$self
->{app_curr}}->{ATTRVALUE}{
$token
} =
$attrs
->{
'{}value'
}->{Value};
}
elsif
(
$name
=~ /(Ext[0-2]Value)s/) {
$self
->{ext_curr} =
uc
$1;
}
elsif
(
$name
eq
'EXTVALUE'
) {
my
$index
=
hex
$attrs
->{
'{}index'
}->{Value};
$self
->{App}{
$self
->{app_curr}}->{
$self
->{ext_curr}}{
$index
} =
$attrs
->{
'{}value'
}->{Value};
}
}