magicword => undef,
textcontent => undef,
unknownWords => {},
+ mirrorFile => undef,
};
$data->{'sth'} = $data->{'dbh'}->prepare('select shaw from words where latn=?');
return bless($data, $class);
}
+sub possiblyMirror {
+ my ($self, $str) = @_;
+
+ return unless $self->{'mirrorFile'};
+
+ my $fh = $self->{'mirrorFile'};
+
+ print $fh $str;
+}
+
sub shavianise {
my ($self, $latn, $line) = @_;
$latn = lc $latn;
$latn);
if (scalar(@$shaw)==0) {
- warn "$latn is unknown at line $line. Using ??? for the Shavian.\n";
+ $self->warning("$latn is unknown; using ??? for the Shavian",
+ $line);
$self->{'unknownWords'}->{$latn} = 1;
return '???';
}
if (scalar(@$shaw)!=1) {
- warn "$latn is ambiguous at line $line. Using ??? for the Shavian.\n";
+ $self->warning("$latn is ambiguous; using ??? for the Shavian.",
+ $line);
return '???';
}
if ($self->{'quotedepth'}!=0 &&
$self->{'quotedepth'}!=1) {
- warn "Quote depth at line $line was weird\n";
+ $self->warning("Quote depth was weird",
+ $line);
}
}
$self->{'textcontent'} = undef;
}
+sub warning {
+ my ($self, $message, $line) = @_;
+
+ warn "$message at line $line\n";
+
+ if ($self->{'mirrorFile'}) {
+ my $fh = $self->{'mirrorFile'};
+ print $fh "<warn about=\"$message\"/>";
+ }
+}
+
sub parse {
- my ($self, $filename, $callback) = @_;
+ my ($self, $filename, $callback, $doMirror) = @_;
my $skipping = 0;
+ if ($doMirror) {
+ open MIRROR, ">mirror.xml" or die;
+ print MIRROR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ $self->{'mirrorFile'} = *MIRROR;
+ }
+
my $p = new XML::Parser(Handlers => {
Start => sub {
return if $skipping;
my ($parser, $tag, %attrs) = @_;
+ $self->possiblyMirror($parser->original_string()) unless $tag eq 'warn';
+
if ($tag eq 'i') {
$self->addTextContentToPara($parser->current_line());
$self->{'italics'} = 1;
return if $skipping;
my ($parser, $tag) = @_;
+ $self->possiblyMirror($parser->original_string());
+
if ($tag eq 'i') {
$self->addTextContentToPara($parser->current_line());
$self->{'italics'} = 0;
$self->{'quotedepth'} = 0;
} elsif ($tag eq 'magic') {
my $shavian_content = $self->{'textcontent'};
+ $shavian_content = '' unless defined $shavian_content;
$shavian_content = $self->shavianise_phrase($shavian_content, $parser->current_line);
$callback->('MAGI',
$self->{'magicword'},
return if $skipping;
my ($parser, $text) = @_;
+ $self->possiblyMirror($parser->original_string());
+
$text =~ s/([\[\]])/$self->do_quotes($1)/eg;
if ($text =~ m!\p{Shavian}!) {
- warn "Shavian text found at line ".
- $parser->current_line()."\n";
+ $self->warning("Shavian text found",
+ $parser->current_line());
}
if (defined $self->{'textcontent'}) {
return;
}
},
+ Comment => sub {
+ my ($parser) = @_;
+
+ $self->possiblyMirror($parser->original_string());
+ },
+ Proc => sub {
+ my ($parser) = @_;
+
+ $self->possiblyMirror($parser->original_string());
+ },
});
$p->parsefile($filename);
+
+ if ($doMirror) {
+ print MIRROR "\n";
+ close MIRROR or die;
+ $self->{'mirrorFile'} = undef;
+ }
}
sub printUnknownWords {