/[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.31 by wakaba, Sun Feb 10 02:05:30 2008 UTC revision 1.33 by wakaba, Sun Feb 10 02:42:01 2008 UTC
# Line 147  sub add_error ($$$) { Line 147  sub add_error ($$$) {
147    
148  sub check_and_print ($$) {  sub check_and_print ($$) {
149    my ($input, $result) = @_;    my ($input, $result) = @_;
150      $input->{id_prefix} = '';
151      #$input->{nested} = 1/0;
152    
153    print_http_header_section ($input, $result);    print_http_header_section ($input, $result);
154    
# Line 178  sub check_and_print ($$) { Line 180  sub check_and_print ($$) {
180    }    }
181    
182    if (defined $doc or defined $el) {    if (defined $doc or defined $el) {
183      print_structure_dump_dom_section ($doc, $el);      print_structure_dump_dom_section ($input, $doc, $el);
184      my $elements = print_structure_error_dom_section ($doc, $el, $result);      my $elements = print_structure_error_dom_section
185      print_table_section ($elements->{table}) if @{$elements->{table}};          ($input, $doc, $el, $result);
186      print_id_section ($elements->{id}) if keys %{$elements->{id}};      print_table_section ($input, $elements->{table}) if @{$elements->{table}};
187      print_term_section ($elements->{term}) if keys %{$elements->{term}};      print_listing_section ({
188      print_class_section ($elements->{class}) if keys %{$elements->{class}};        id => 'identifiers', label => 'IDs', heading => 'Identifiers',
189        }, $input, $elements->{id}) if keys %{$elements->{id}};
190        print_listing_section ({
191          id => 'terms', label => 'Terms', heading => 'Terms',
192        }, $input, $elements->{term}) if keys %{$elements->{term}};
193        print_listing_section ({
194          id => 'classes', label => 'Classes', heading => 'Classes',
195        }, $input, $elements->{class}) if keys %{$elements->{class}};
196    } elsif (defined $manifest) {    } elsif (defined $manifest) {
197      print_structure_dump_manifest_section ($manifest);      print_structure_dump_manifest_section ($input, $manifest);
198      print_structure_error_manifest_section ($manifest, $result);      print_structure_error_manifest_section ($input, $manifest, $result);
199    }    }
200  } # check_and_print  } # check_and_print
201    
# Line 196  sub print_http_header_section ($$) { Line 205  sub print_http_header_section ($$) {
205        defined $input->{header_status_text} or        defined $input->{header_status_text} or
206        @{$input->{header_field}};        @{$input->{header_field}};
207        
208    push @nav, ['#source-header' => 'HTTP Header'];    push @nav, ['#source-header' => 'HTTP Header'] unless $input->{nested};
209    print STDOUT qq[<div id="source-header" class="section">    print STDOUT qq[<div id="$input->{id_prefix}source-header" class="section">
210  <h2>HTTP Header</h2>  <h2>HTTP Header</h2>
211    
212  <p><strong>Note</strong>: Due to the limitation of the  <p><strong>Note</strong>: Due to the limitation of the
# Line 231  sub print_syntax_error_html_section ($$) Line 240  sub print_syntax_error_html_section ($$)
240    require Whatpm::HTML;    require Whatpm::HTML;
241        
242    print STDOUT qq[    print STDOUT qq[
243  <div id="parse-errors" class="section">  <div id="$input->{id_prefix}parse-errors" class="section">
244  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
245    
246  <dl>];  <dl>];
247    push @nav, ['#parse-errors' => 'Parse Error'];    push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested};
248    
249    my $onerror = sub {    my $onerror = sub {
250      my (%opt) = @_;      my (%opt) = @_;
# Line 289  sub print_syntax_error_xml_section ($$) Line 298  sub print_syntax_error_xml_section ($$)
298    require Message::DOM::XMLParserTemp;    require Message::DOM::XMLParserTemp;
299        
300    print STDOUT qq[    print STDOUT qq[
301  <div id="parse-errors" class="section">  <div id="$input->{id_prefix}parse-errors" class="section">
302  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
303    
304  <dl>];  <dl>];
305    push @nav, ['#parse-errors' => 'Parse Error'];    push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{prefix};
306    
307    my $onerror = sub {    my $onerror = sub {
308      my $err = shift;      my $err = shift;
# Line 331  sub print_syntax_error_manifest_section Line 340  sub print_syntax_error_manifest_section
340    require Whatpm::CacheManifest;    require Whatpm::CacheManifest;
341    
342    print STDOUT qq[    print STDOUT qq[
343  <div id="parse-errors" class="section">  <div id="$input->{id_prefix}parse-errors" class="section">
344  <h2>Parse Errors</h2>  <h2>Parse Errors</h2>
345    
346  <dl>];  <dl>];
347    push @nav, ['#parse-errors' => 'Parse Error'];    push @nav, ['#parse-errors' => 'Parse Error'] unless $input->{nested};
348    
349    my $onerror = sub {    my $onerror = sub {
350      my (%opt) = @_;      my (%opt) = @_;
351      my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});      my ($type, $cls, $msg) = get_text ($opt{type}, $opt{level});
352      print STDOUT qq[<dt class="$cls">], get_error_label (\%opt), qq[</dt>];      print STDOUT qq[<dt class="$cls">], get_error_label ($input, \%opt),
353            qq[</dt>];
354      $type =~ tr/ /-/;      $type =~ tr/ /-/;
355      $type =~ s/\|/%7C/g;      $type =~ s/\|/%7C/g;
356      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
# Line 367  sub print_source_string_section ($$) { Line 377  sub print_source_string_section ($$) {
377    
378    my $s = \($enc->decode (${$_[0]}));    my $s = \($enc->decode (${$_[0]}));
379    my $i = 1;                                my $i = 1;                            
380    push @nav, ['#source-string' => 'Source'];    push @nav, ['#source-string' => 'Source'] unless $input->{nested};
381    print STDOUT qq[<div id="source-string" class="section">    print STDOUT qq[<div id="$input->{id_prefix}source-string" class="section">
382  <h2>Document Source</h2>  <h2>Document Source</h2>
383  <ol lang="">\n];  <ol lang="">\n];
384    if (length $$s) {    if (length $$s) {
385      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {      while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) {
386        print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,
387              "</li>\n";
388        $i++;        $i++;
389      }      }
390      if ($$s =~ /\G([^\x0A]+)/gc) {      if ($$s =~ /\G([^\x0A]+)/gc) {
391        print STDOUT qq[<li id="line-$i">], htescape $1, "</li>\n";        print STDOUT qq[<li id="$input->{id_prefix}line-$i">], htescape $1,
392              "</li>\n";
393      }      }
394    } else {    } else {
395      print STDOUT q[<li id="line-1"></li>];      print STDOUT q[<li id="$input->{id_prefix}line-1"></li>];
396    }    }
397    print STDOUT "</ol></div>";    print STDOUT "</ol></div>";
398  } # print_input_string_section  } # print_input_string_section
# Line 397  sub print_document_tree ($) { Line 409  sub print_document_tree ($) {
409        next;        next;
410      }      }
411    
412      my $node_id = 'node-'.refaddr $child;      my $node_id = $input->{id_prefix} . 'node-'.refaddr $child;
413      my $nt = $child->node_type;      my $nt = $child->node_type;
414      if ($nt == $child->ELEMENT_NODE) {      if ($nt == $child->ELEMENT_NODE) {
415        my $child_nsuri = $child->namespace_uri;        my $child_nsuri = $child->namespace_uri;
# Line 408  sub print_document_tree ($) { Line 420  sub print_document_tree ($) {
420          $r .= '<ul class="attributes">';          $r .= '<ul class="attributes">';
421          for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] }          for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value, $_->namespace_uri, 'node-'.refaddr $_] }
422                        @{$child->attributes}) {                        @{$child->attributes}) {
423            $r .= qq[<li id="$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case?            $r .= qq[<li id="$input->{id_prefix}$attr->[3]" class="tree-attribute"><code title="@{[defined $attr->[2] ? htescape ($attr->[2]) : '']}">] . htescape ($attr->[0]) . '</code> = '; ## ISSUE: case?
424            $r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children            $r .= '<q>' . htescape ($attr->[1]) . '</q></li>'; ## TODO: children
425          }          }
426          $r .= '</ul>';          $r .= '</ul>';
# Line 477  sub print_document_tree ($) { Line 489  sub print_document_tree ($) {
489    print STDOUT $r;    print STDOUT $r;
490  } # print_document_tree  } # print_document_tree
491    
492  sub print_structure_dump_dom_section ($$) {  sub print_structure_dump_dom_section ($$$) {
493    my ($doc, $el) = @_;    my ($input, $doc, $el) = @_;
494    
495    print STDOUT qq[    print STDOUT qq[
496  <div id="document-tree" class="section">  <div id="$input->{id_prefix}document-tree" class="section">
497  <h2>Document Tree</h2>  <h2>Document Tree</h2>
498  ];  ];
499    push @nav, ['#document-tree' => 'Tree'];    push @nav, ['#document-tree' => 'Tree'] unless $input->{nested};
500    
501    print_document_tree ($el || $doc);    print_document_tree ($el || $doc);
502    
503    print STDOUT qq[</div>];    print STDOUT qq[</div>];
504  } # print_structure_dump_dom_section  } # print_structure_dump_dom_section
505    
506  sub print_structure_dump_manifest_section ($) {  sub print_structure_dump_manifest_section ($$) {
507    my $manifest = shift;    my ($input, $manifest) = @_;
508    
509    print STDOUT qq[    print STDOUT qq[
510  <div id="dump-manifest" class="section">  <div id="$input->{id_prefix}dump-manifest" class="section">
511  <h2>Cache Manifest</h2>  <h2>Cache Manifest</h2>
512  ];  ];
513    push @nav, ['#dump-manifest' => 'Caceh Manifest'];    push @nav, ['#dump-manifest' => 'Caceh Manifest'] unless $input->{nested};
514    
515    print STDOUT qq[<dl><dt>Explicit entries</dt>];    print STDOUT qq[<dl><dt>Explicit entries</dt>];
516    for my $uri (@{$manifest->[0]}) {    for my $uri (@{$manifest->[0]}) {
# Line 525  sub print_structure_dump_manifest_sectio Line 537  sub print_structure_dump_manifest_sectio
537    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
538  } # print_structure_dump_manifest_section  } # print_structure_dump_manifest_section
539    
540  sub print_structure_error_dom_section ($$$) {  sub print_structure_error_dom_section ($$$$) {
541    my ($doc, $el, $result) = @_;    my ($input, $doc, $el, $result) = @_;
542    
543    print STDOUT qq[<div id="document-errors" class="section">    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">
544  <h2>Document Errors</h2>  <h2>Document Errors</h2>
545    
546  <dl>];  <dl>];
547    push @nav, ['#document-errors' => 'Document Error'];    push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested};
548    
549    require Whatpm::ContentChecker;    require Whatpm::ContentChecker;
550    my $onerror = sub {    my $onerror = sub {
# Line 541  sub print_structure_error_dom_section ($ Line 553  sub print_structure_error_dom_section ($
553      $type =~ tr/ /-/;      $type =~ tr/ /-/;
554      $type =~ s/\|/%7C/g;      $type =~ s/\|/%7C/g;
555      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
556      print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) .      print STDOUT qq[<dt class="$cls">] . get_error_label ($input, \%opt) .
557          qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt);          qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt);
558      print STDOUT $msg, "</dd>\n";      print STDOUT $msg, "</dd>\n";
559      add_error ('structure', \%opt => $result);      add_error ('structure', \%opt => $result);
# Line 562  sub print_structure_error_dom_section ($ Line 574  sub print_structure_error_dom_section ($
574  } # print_structure_error_dom_section  } # print_structure_error_dom_section
575    
576  sub print_structure_error_manifest_section ($$$) {  sub print_structure_error_manifest_section ($$$) {
577    my ($manifest, $result) = @_;    my ($input, $manifest, $result) = @_;
578    
579    print STDOUT qq[<div id="document-errors" class="section">    print STDOUT qq[<div id="$input->{id_prefix}document-errors" class="section">
580  <h2>Document Errors</h2>  <h2>Document Errors</h2>
581    
582  <dl>];  <dl>];
583    push @nav, ['#document-errors' => 'Document Error'];    push @nav, ['#document-errors' => 'Document Error'] unless $input->{nested};
584    
585    require Whatpm::CacheManifest;    require Whatpm::CacheManifest;
586    Whatpm::CacheManifest->check_manifest ($manifest, sub {    Whatpm::CacheManifest->check_manifest ($manifest, sub {
# Line 577  sub print_structure_error_manifest_secti Line 589  sub print_structure_error_manifest_secti
589      $type =~ tr/ /-/;      $type =~ tr/ /-/;
590      $type =~ s/\|/%7C/g;      $type =~ s/\|/%7C/g;
591      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];      $msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]];
592      print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) .      print STDOUT qq[<dt class="$cls">] . get_error_label ($input, \%opt) .
593          qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";          qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n";
594      add_error ('structure', \%opt => $result);      add_error ('structure', \%opt => $result);
595    });    });
# Line 585  sub print_structure_error_manifest_secti Line 597  sub print_structure_error_manifest_secti
597    print STDOUT qq[</div>];    print STDOUT qq[</div>];
598  } # print_structure_error_manifest_section  } # print_structure_error_manifest_section
599    
600  sub print_table_section ($) {  sub print_table_section ($$) {
601    my $tables = shift;    my ($input, $tables) = @_;
602        
603    push @nav, ['#tables' => 'Tables'];    push @nav, ['#tables' => 'Tables'] unless $input->{nested};
604    print STDOUT qq[    print STDOUT qq[
605  <div id="tables" class="section">  <div id="$input->{id_prefix}tables" class="section">
606  <h2>Tables</h2>  <h2>Tables</h2>
607    
608  <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->  <!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
# Line 605  sub print_table_section ($) { Line 617  sub print_table_section ($) {
617    my $i = 0;    my $i = 0;
618    for my $table_el (@$tables) {    for my $table_el (@$tables) {
619      $i++;      $i++;
620      print STDOUT qq[<div class="section" id="table-$i"><h3>] .      print STDOUT qq[<div class="section" id="$input->{id_prefix}table-$i"><h3>] .
621          get_node_link ($table_el) . q[</h3>];          get_node_link ($input, $table_el) . q[</h3>];
622    
623      ## TODO: Make |ContentChecker| return |form_table| result      ## TODO: Make |ContentChecker| return |form_table| result
624      ## so that this script don't have to run the algorithm twice.      ## so that this script don't have to run the algorithm twice.
# Line 638  sub print_table_section ($) { Line 650  sub print_table_section ($) {
650                    
651      print STDOUT '</div><script type="text/javascript">tableToCanvas (';      print STDOUT '</div><script type="text/javascript">tableToCanvas (';
652      print STDOUT JSON::objToJson ($table);      print STDOUT JSON::objToJson ($table);
653      print STDOUT qq[, document.getElementById ('table-$i'));</script>];      print STDOUT qq[, document.getElementById ('$input->{id_prefix}table-$i')];
654        print STDOUT qq[, '$input->{id_prefix}');</script>];
655    }    }
656        
657    print STDOUT qq[</div>];    print STDOUT qq[</div>];
658  } # print_table_section  } # print_table_section
659    
660  sub print_id_section ($) {  sub print_listing_section ($$$) {
661    my $ids = shift;    my ($opt, $input, $ids) = @_;
662        
663    push @nav, ['#identifiers' => 'IDs'];    push @nav, ['#' . $opt->{id} => $opt->{label}] unless $input->{nested};
664    print STDOUT qq[    print STDOUT qq[
665  <div id="identifiers" class="section">  <div id="$input->{id_prefix}$opt->{id}" class="section">
666  <h2>Identifiers</h2>  <h2>$opt->{heading}</h2>
667    
668  <dl>  <dl>
669  ];  ];
670    for my $id (sort {$a cmp $b} keys %$ids) {    for my $id (sort {$a cmp $b} keys %$ids) {
671      print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>];      print STDOUT qq[<dt><code>@{[htescape $id]}</code></dt>];
672      for (@{$ids->{$id}}) {      for (@{$ids->{$id}}) {
673        print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>];        print STDOUT qq[<dd>].get_node_link ($input, $_).qq[</dd>];
     }  
   }  
   print STDOUT qq[</dl></div>];  
 } # print_id_section  
   
 sub print_term_section ($) {  
   my $terms = shift;  
     
   push @nav, ['#terms' => 'Terms'];  
   print STDOUT qq[  
 <div id="terms" class="section">  
 <h2>Terms</h2>  
   
 <dl>  
 ];  
   for my $term (sort {$a cmp $b} keys %$terms) {  
     print STDOUT qq[<dt>@{[htescape $term]}</dt>];  
     for (@{$terms->{$term}}) {  
       print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>];  
674      }      }
675    }    }
676    print STDOUT qq[</dl></div>];    print STDOUT qq[</dl></div>];
677  } # print_term_section  } # print_listing_section
   
 sub print_class_section ($) {  
   my $classes = shift;  
     
   push @nav, ['#classes' => 'Classes'];  
   print STDOUT qq[  
 <div id="classes" class="section">  
 <h2>Classes</h2>  
   
 <dl>  
 ];  
   for my $class (sort {$a cmp $b} keys %$classes) {  
     print STDOUT qq[<dt><code>@{[htescape $class]}</code></dt>];  
     for (@{$classes->{$class}}) {  
       print STDOUT qq[<dd>].get_node_link ($_).qq[</dd>];  
     }  
   }  
   print STDOUT qq[</dl></div>];  
 } # print_class_section  
678    
679  sub print_result_section ($) {  sub print_result_section ($) {
680    my $result = shift;    my $result = shift;
# Line 822  sub print_result_input_error_section ($) Line 797  sub print_result_input_error_section ($)
797  <p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p>  <p><em><strong>Input Error</strong>: @{[htescape ($input->{error_status_text})]}</em></p>
798  </div>];  </div>];
799    push @nav, ['#result-summary' => 'Result'];    push @nav, ['#result-summary' => 'Result'];
800  } # print_Result_input_error_section  } # print_result_input_error_section
801    
802  sub get_error_label ($) {  sub get_error_label ($$) {
803    my $err = shift;    my ($input, $err) = @_;
804    
805    my $r = '';    my $r = '';
806    
# Line 840  sub get_error_label ($) { Line 815  sub get_error_label ($) {
815    
816    if (defined $err->{node}) {    if (defined $err->{node}) {
817      $r .= ' ' if length $r;      $r .= ' ' if length $r;
818      $r = get_node_link ($err->{node});      $r = get_node_link ($input, $err->{node});
819    }    }
820    
821    if (defined $err->{index}) {    if (defined $err->{index}) {
# Line 909  sub get_node_path ($) { Line 884  sub get_node_path ($) {
884    return join '/', @r;    return join '/', @r;
885  } # get_node_path  } # get_node_path
886    
887  sub get_node_link ($) {  sub get_node_link ($$) {
888    return qq[<a href="#node-@{[refaddr $_[0]]}">] .    return qq[<a href="#$_[0]->{id_prefix}node-@{[refaddr $_[1]]}">] .
889        htescape (get_node_path ($_[0])) . qq[</a>];        htescape (get_node_path ($_[1])) . qq[</a>];
890  } # get_node_link  } # get_node_link
891    
892  {  {

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.33

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24