chiark / gitweb /
save warnings to mirror file
authorThomas Thurman <tthurman@gnome.org>
Mon, 15 Mar 2010 00:31:44 +0000 (20:31 -0400)
committerThomas Thurman <tthurman@gnome.org>
Mon, 15 Mar 2010 00:31:44 +0000 (20:31 -0400)
htmlfury.pl
lib/Fury/Parse.pm

index dd4bd0c..3e7e15f 100644 (file)
@@ -14,7 +14,7 @@ my %settings;
 my $in_stanza = 0;
 
 my $chapcount = 0;
-my $maxchaps = 12;
+my $maxchaps = 1000;
 
 print ALICE << "EOT";
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -105,7 +105,9 @@ $furyparse->parse('source.xml',
                          print ALICE "</p>\n\n";
                      }
                      return 1;
-                 });
+                 },
+                 1 # do the mirror thing
+    );
 
 print ALICE "</body></html>\n";
 close ALICE;
index 91d44ee..ebc5972 100644 (file)
@@ -23,6 +23,7 @@ sub new {
        magicword => undef,
        textcontent => undef,
        unknownWords => {},
+       mirrorFile => undef,
     };
 
     $data->{'sth'} = $data->{'dbh'}->prepare('select shaw from words where latn=?');
@@ -30,6 +31,16 @@ sub new {
     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;
@@ -41,13 +52,15 @@ sub shavianise {
                                                  $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 '???';
     }
 
@@ -91,7 +104,8 @@ sub checkQuoteDepth {
 
     if ($self->{'quotedepth'}!=0 &&
        $self->{'quotedepth'}!=1) {
-       warn "Quote depth at line $line was weird\n";
+       $self->warning("Quote depth was weird",
+                      $line);
     }
 }
 
@@ -138,16 +152,35 @@ sub addTextContentToPara {
     $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;
@@ -215,6 +248,8 @@ sub parse {
            return if $skipping;
            my ($parser, $tag) = @_;
 
+           $self->possiblyMirror($parser->original_string());
+
            if ($tag eq 'i') {
                $self->addTextContentToPara($parser->current_line());
                $self->{'italics'} = 0;
@@ -252,6 +287,7 @@ sub parse {
                $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'},
@@ -265,11 +301,13 @@ sub parse {
            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'}) {
@@ -277,9 +315,25 @@ sub parse {
                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 {