/[pub]/test/html-webhacc/cc.cgi
Suika

Diff of /test/html-webhacc/cc.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by wakaba, Sat Jun 30 14:51:10 2007 UTC revision 1.8 by wakaba, Sun Jul 1 10:02:24 2007 UTC
# Line 23  my $http = SuikaWiki::Input::HTTP->new; Line 23  my $http = SuikaWiki::Input::HTTP->new;
23    
24  ## TODO: _charset_  ## TODO: _charset_
25    
26      if ($http->meta_variable ('PATH_INFO') ne '/') {
27        print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400";
28        exit;
29      }
30    
31    my $input_format = $http->parameter ('i') || 'text/html';    my $input_format = $http->parameter ('i') || 'text/html';
32    my $inner_html_element = $http->parameter ('e');    my $inner_html_element = $http->parameter ('e');
33    my $input_uri = 'thismessage:/';    my $input_uri = 'thismessage:/';
# Line 33  my $http = SuikaWiki::Input::HTTP->new; Line 38  my $http = SuikaWiki::Input::HTTP->new;
38      exit;      exit;
39    }    }
40    
41      load_text_catalog ('en'); ## TODO: conneg
42    
43    my @nav;    my @nav;
44    print STDOUT qq[Content-Type: text/html; charset=utf-8    print STDOUT qq[Content-Type: text/html; charset=utf-8
45    
# Line 88  my $http = SuikaWiki::Input::HTTP->new; Line 95  my $http = SuikaWiki::Input::HTTP->new;
95    
96    my $onerror = sub {    my $onerror = sub {
97      my (%opt) = @_;      my (%opt) = @_;
98        my ($cls, $msg) = get_text ($opt{type}, $opt{level});
99      if ($opt{column} > 0) {      if ($opt{column} > 0) {
100        print STDOUT qq[<dt><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a> column $opt{column}</dt>\n];
101      } else {      } else {
102        $opt{line}--;        $opt{line} = $opt{line} - 1 || 1;
103        print STDOUT qq[<dt><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];        print STDOUT qq[<dt class="$cls"><a href="#line-$opt{line}">Line $opt{line}</a></dt>\n];
104      }      }
105      print STDOUT qq[<dd>@{[htescape $opt{type}]}</dd>\n];      $opt{type} =~ tr/ /-/;
106        $opt{type} =~ s/\|/%7C/g;
107        $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];
108        print STDOUT qq[<dd class="$cls">$msg</dd>\n];
109    };    };
110    
111    $doc = $dom->create_document;    $doc = $dom->create_document;
# Line 133  my $http = SuikaWiki::Input::HTTP->new; Line 144  my $http = SuikaWiki::Input::HTTP->new;
144  <div id="parse-errors" class="section">  <div id="parse-errors" class="section">
145  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
146    
147  <dl>  <dl>];
 ];  
148    push @nav, ['#parse-errors' => 'Parse Error'];    push @nav, ['#parse-errors' => 'Parse Error'];
149    
150    my $onerror = sub {    my $onerror = sub {
# Line 150  my $http = SuikaWiki::Input::HTTP->new; Line 160  my $http = SuikaWiki::Input::HTTP->new;
160    $doc = Message::DOM::XMLParserTemp->parse_byte_stream    $doc = Message::DOM::XMLParserTemp->parse_byte_stream
161        ($fh => $dom, $onerror, charset => 'utf-8');        ($fh => $dom, $onerror, charset => 'utf-8');
162    
163      print STDOUT qq[      print STDOUT qq[</dl>
 </dl>  
164  </div>  </div>
165  ];  ];
166    } else {    } else {
# Line 182  my $http = SuikaWiki::Input::HTTP->new; Line 191  my $http = SuikaWiki::Input::HTTP->new;
191  <div id="document-errors" class="section">  <div id="document-errors" class="section">
192  <h2>Document Errors</h2>  <h2>Document Errors</h2>
193    
194  <dl>  <dl>];
 ];  
195      push @nav, ['#document-errors' => 'Document Error'];      push @nav, ['#document-errors' => 'Document Error'];
196    
197      require Whatpm::ContentChecker;      require Whatpm::ContentChecker;
198      my $onerror = sub {      my $onerror = sub {
199        my %opt = @_;        my %opt = @_;
200        print STDOUT qq[<dt>] . get_node_link ($opt{node}) .        my ($cls, $msg) = get_text ($opt{type}, $opt{level});
201            "</dt>\n<dd>", htescape $opt{type}, "</dd>\n";        $opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level};
202          $opt{type} =~ tr/ /-/;
203          $opt{type} =~ s/\|/%7C/g;
204          $msg .= qq[ [<a href="../error-description#$opt{type}">Description</a>]];
205          print STDOUT qq[<dt class="$cls">] . get_node_link ($opt{node}) .
206              qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";
207      };      };
208    
209      my $elements;      my $elements;
# Line 200  my $http = SuikaWiki::Input::HTTP->new; Line 213  my $http = SuikaWiki::Input::HTTP->new;
213        $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);        $elements = Whatpm::ContentChecker->check_document ($doc, $onerror);
214      }      }
215    
216      print STDOUT qq[      print STDOUT qq[</dl>
 </dl>  
217  </div>  </div>
218  ];  ];
219    
# Line 295  sub print_source_string ($) { Line 307  sub print_source_string ($) {
307    my $s = $_[0];    my $s = $_[0];
308    my $i = 1;    my $i = 1;
309    print STDOUT qq[<ol lang="">\n];    print STDOUT qq[<ol lang="">\n];
310    while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {    if (length $$s) {
311      print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {
312      $i++;        print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";
313    }        $i++;
314    if ($$s =~ /\G([^\x0A]+)/gc) {      }
315      print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";      if ($$s =~ /\G([^\x0A]+)/gc) {
316          print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";
317        }
318      } else {
319        print STDOUT q[<li id="line-1"></li>];
320    }    }
321    print STDOUT "</ol>";    print STDOUT "</ol>";
322  } # print_input_string  } # print_input_string
# Line 334  sub print_document_tree ($) { Line 350  sub print_document_tree ($) {
350          $r .= '</ul>';          $r .= '</ul>';
351        }        }
352    
353        if ($node->has_child_nodes) {        if ($child->has_child_nodes) {
354          $r .= '<ol class="children">';          $r .= '<ol class="children">';
355          unshift @node, @{$child->child_nodes}, '</ol></li>';          unshift @node, @{$child->child_nodes}, '</ol></li>';
356        } else {        } else {
# Line 348  sub print_document_tree ($) { Line 364  sub print_document_tree ($) {
364        $r .= qq'<li id="$node_id" class="tree-comment"><code>&lt;!--</code><q lang="">' . htescape ($child->data) . '</q><code>--&gt;</code></li>';        $r .= qq'<li id="$node_id" class="tree-comment"><code>&lt;!--</code><q lang="">' . htescape ($child->data) . '</q><code>--&gt;</code></li>';
365      } elsif ($nt == $child->DOCUMENT_NODE) {      } elsif ($nt == $child->DOCUMENT_NODE) {
366        $r .= qq'<li id="$node_id" class="tree-document">Document';        $r .= qq'<li id="$node_id" class="tree-document">Document';
367          $r .= qq[<ul class="attributes">];
368          $r .= qq[<li>@{[scalar get_text ('manakaiIsHTML:'.($child->manakai_is_html?1:0))]}</li>];
369          $r .= qq[<li>@{[scalar get_text ('manakaiCompatMode:'.$child->manakai_compat_mode)]}</li>];
370          $r .= qq[</ul>];
371        if ($child->has_child_nodes) {        if ($child->has_child_nodes) {
372          $r .= '<ol>';          $r .= '<ol class="children">';
373          unshift @node, @{$child->child_nodes}, '</ol></li>';          unshift @node, @{$child->child_nodes}, '</ol></li>';
374        }        }
375      } elsif ($nt == $child->DOCUMENT_TYPE_NODE) {      } elsif ($nt == $child->DOCUMENT_TYPE_NODE) {
# Line 400  sub get_node_link ($) { Line 420  sub get_node_link ($) {
420        htescape (get_node_path ($_[0])) . qq[</a>];        htescape (get_node_path ($_[0])) . qq[</a>];
421  } # get_node_link  } # get_node_link
422    
423    {
424      my $Msg = {};
425    
426    sub load_text_catalog ($) {
427      my $lang = shift; # MUST be a canonical lang name
428      open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!";
429      while (<$file>) {
430        if (s/^([^;]+);([^;]*);//) {
431          my ($type, $cls, $msg) = ($1, $2, $_);
432          $msg =~ tr/\x0D\x0A//d;
433          $Msg->{$type} = [$cls, $msg];
434        }
435      }
436    } # load_text_catalog
437    
438    sub get_text ($) {
439      my ($type, $level) = @_;
440      $type = $level . ':' . $type if defined $level;
441      my @arg;
442      {
443        if (defined $Msg->{$type}) {
444          my $msg = $Msg->{$type}->[1];
445          $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge;
446          return ($Msg->{$type}->[0], $msg);
447        } elsif ($type =~ s/:([^:]*)$//) {
448          unshift @arg, $1;
449          redo;
450        }
451      }
452      return ('', htescape ($_[0]));
453    } # get_text
454    
455    }
456    
457  =head1 AUTHOR  =head1 AUTHOR
458    
459  Wakaba <w@suika.fam.cx>.  Wakaba <w@suika.fam.cx>.

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24