| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Id: gen_pod.pl,v 2.3 2007-01-02 22:03:21 pajas Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw(%enc); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | if ($ARGV[0]=~'^(-h|--help)?$') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | print <<EOF; | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | Generates POD documentation from RecDescentXML source. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | Usage: $0 <source.xml> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | %enc=('>' => 'gt', '<' => 'lt', '/' => 'sol', '|' => 'verbar'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $parser=XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | $parser->load_ext_dtd(1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $parser->validation(1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $parser->keep_blanks(1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $doc=$parser->parse_file($ARGV[0]); | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $dom=$doc->getDocumentElement(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my ($rules)=$dom->findnodes('./rules'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $ruledoc; | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | my $title; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my @seealso; | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my @usage; | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $desc; | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2693 | ▶ | sub pprint (@) { $output .= join '',@_ }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pprint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | pprint "=for comment\n This file was automatically generated from $ARGV[0]\n on ",scalar(localtime),"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | pprint <<'PREAMB'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | XSH - scripting language for XPath-based editing of XML | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | PREAMB | ||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | foreach my $sec ($dom->findnodes('/recdescent-xml/doc/section')) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 13 | my $name=$sec->getAttribute('id'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 13 | ($title)=$sec->findnodes('./title'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 13 | ▶ | my $t= $title ? get_text($title,0,2) : $name; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 13 | pprint "\n=head1 ",uc($t),"\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | print_description($sec,"",""); | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 13 | my @commands=$dom->findnodes("//rules/rule[\@type='command' and ". | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | "documentation[contains(\@sections,'$name')]]"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ▶ | if (@commands) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | pprint "\n\n=head2 RELATED COMMANDS\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 9 | pprint join ", ", sort map { get_name($_) } | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | @commands; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | pprint "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | #pprint "\n=head1 COMMAND REFERENCE\n\n=over 5\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | #foreach ($dom->findnodes("//rules/rule[\@type='command' and documentation]")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # pprint "\n\n=item B<".get_name($_).">\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # pprint get_text($_->findnodes('documentation/shortdesc')); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | #pprint "\n=back\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | #pprint "\n=head1 ARGUMENT TYPES\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | #pprint wrap(" "," ", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # join ", ", sort map { get_name($_) } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # grep {defined($_)} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # $dom->findnodes("//rules/rule[\@type='argtype']")), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # "\n\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | pprint "\n=head1 COMMAND REFERENCE\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | foreach my $r (sort {get_name($a) cmp get_name($b)} | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $rules->findnodes('./rule[@type="command"]')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 117 | print_rule_desc($r); | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | pprint "\n=head1 ARGUMENT TYPE REFERENCE\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | pprint "=over 4\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | foreach my $r (sort {get_name($a) cmp get_name($b)} | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $rules->findnodes('./rule[@type="argtype"]')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 13 | ($desc)=$r->findnodes('./documentation/description'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 13 | ▶ | if ($desc) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | pprint "\n\n=item B<".get_name($r).">\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 13 | print_description($desc,'',''); | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | pprint "\n\n=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | pprint "\n=head1 XPATH EXTENSION FUNCTION REFERENCE\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | foreach my $r (sort {get_name($a) cmp get_name($b)} | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $rules->findnodes('./rule[@type="function"]')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 48 | print_rule_desc($r); | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | pprint "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | pprint <<'POSTAMB'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | Petr Pajas, pajas@matfyz.cz | ||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | L<xsh>, L<XML::XSH2>, L<XML::XSH2::Compile>, L<XML::LibXML>, L<XML::XUpdate>, L<http://xsh.sourceforge.net/doc> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | POSTAMB | ||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # normalize lines | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | $output=~s/(\n[ \t]*){1,}\n/\n\n/sg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # lazily fix nested B<...> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | 1 while $output=~s/(B<[^>]*)B<([^>]*)>([^>]*>)/$1$2$3/sg; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | print($output); | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ## ================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | sub print_rule_desc { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 165 | ▶ | my ($r)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_rule_desc: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 165 | ▶ | return unless $r; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 165 | my ($ruledoc)=$r->findnodes('./documentation'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 165 | ▶ | return unless $ruledoc; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 165 | my $name=get_name($r); | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # ($title)=$ruledoc->findnodes('./title'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # my $t=$title ? get_text($title) : $name; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 165 | pprint "\n\n=head2 ",$name,"\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 165 | pprint "\n\n=over 4\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 165 | @usage=$ruledoc->findnodes('./usage'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 165 | ▶ | if (@usage) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 165 | pprint "\n\n=item Usage:\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 165 | foreach (@usage) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 180 | my $usage=get_text($_); | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 180 | $usage=~s/\s+/ /; | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 180 | pprint $usage,"\n "; | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 165 | pprint "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 165 | @aliases=grep {defined($_)} $r->findnodes('./aliases/alias'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 165 | ▶ | if (@aliases) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 49 | pprint "\n\n=item Aliases:\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 49 | pprint join " ",map { get_name($_) } @aliases; | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 49 | pprint "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 165 | ($desc)=$ruledoc->findnodes('./description'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 165 | ▶ | if ($desc) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 165 | pprint "\n\n=item Description:\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 165 | print_description($desc,'',''); | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 165 | @seealso=grep {defined($_)} $ruledoc->findnodes('./see-also/ruleref'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 165 | ▶ | if (@seealso) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 76 | pprint "\n\n=item See also:\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 164 | pprint join " ", grep {defined($_)} | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 76 | map { $_->getAttribute('ref') } @seealso; | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 76 | pprint "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 165 | pprint "\n\n=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sub strip_space { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 798 | ▶ | my ($text)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_space: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 798 | $text=~s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 798 | $text=~s/\s*$//; | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 798 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub get_name { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2848 | ▶ | my ($r)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2848 | ▶ | return $r->getAttribute('name') ne "" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ? $r->getAttribute('name') | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | : $r->getAttribute('id'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub get_text { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1751 | ▶ | my ($node,$no_strip,$noformat)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_text: called CC=20 SCAR=30.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1751 | my $text=""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1751 | foreach my $n ($node->childNodes()) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4953 | ▶ | if ($n->nodeType() == XML::LibXML::XML_TEXT_NODE || | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$n->nodeType == 3 or $n->nodeType == 4
MC/DC50%1/2
$n->nodeType == 3 or $n->nodeType == 4
$n->nodeType == 3
$n->nodeType == 4
Truth table66%2/3
A or B
A= $n->nodeType == 3B= $n->nodeType == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | $n->nodeType() == XML::LibXML::XML_CDATA_SECTION_NODE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3248 | my $data=$n->getData(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3248 | $data=~s/\t/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3248 | ▶ | $data=~s/([\/\|><])/"E<$enc{$1}>"/eg unless $noformat>1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3248 | $text.=$data; | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } elsif ($n->nodeType() == XML::LibXML::XML_ELEMENT_NODE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1583 | ▶ | if (!$noformat and $n->nodeName() eq 'link') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
not $noformat and $n->nodeName eq "link"
MC/DC100%2/2
not $noformat and $n->nodeName eq "link"
not $noformat
$n->nodeName eq "link"
Truth table100%3/3
not(A) and B
A= not $noformatB= $n->nodeName eq "link"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 17 | $text.="B<".get_text($n,1,$noformat).">"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | ▶ | } elsif (!$noformat and $n->nodeName() eq 'xref') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $noformat and $n->nodeName eq "xref"
MC/DC100%2/2
not $noformat and $n->nodeName eq "xref"
not $noformat
$n->nodeName eq "xref"
Truth table100%3/3
not(A) and B
A= not $noformatB= $n->nodeName eq "xref"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 494 | $text.="B<"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 494 | my ($ref)=$node->findnodes("id('".$n->getAttribute('linkend')."')"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 494 | ▶ | if ($ref) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 494 | $text.=get_name($ref); | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | pprint STDERR "Reference to undefined identifier: ",$n->getAttribute('linkend'),"\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 494 | $text.=">"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ▶ | } elsif (!$noformat and $n->nodeName() eq 'typeref') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $noformat and $n->nodeName eq "typeref"
MC/DC100%2/2
not $noformat and $n->nodeName eq "typeref"
not $noformat
$n->nodeName eq "typeref"
Truth table100%3/3
not(A) and B
A= not $noformatB= $n->nodeName eq "typeref"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | foreach (split /\s/,$n->getAttribute('types')) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $text.=join ", ", sort map { get_name($_) } grep {defined($_)} $node->findnodes("//rules/rule[\@type='$_']"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } elsif ($n->nodeName() eq 'tab') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 256 | $text.="\t" x $n->getAttribute('count'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ▶ | } elsif (!$noformat and $n->nodeName() eq 'userinput') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $noformat and $n->nodeName eq "userinput"
MC/DC0%0/2
not $noformat and $n->nodeName eq "userinput"
not $noformat
$n->nodeName eq "userinput"
Truth table66%2/3
not(A) and B
A= not $noformatB= $n->nodeName eq "userinput"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $text.="B<".get_text($n,1,$noformat).">"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ▶ | } elsif (!$noformat and $n->nodeName() eq 'literal') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $noformat and $n->nodeName eq "literal"
MC/DC100%2/2
not $noformat and $n->nodeName eq "literal"
not $noformat
$n->nodeName eq "literal"
Truth table100%3/3
not(A) and B
A= not $noformatB= $n->nodeName eq "literal"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 683 | $text.="B<".get_text($n,1,$noformat).">"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 131 | $text.=get_text($n,$no_strip,$noformat); | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1751 | ▶ | return $no_strip ? $text : strip_space($text); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub max { ($_[0] > $_[1]) ? $_[0] : $_[1] } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | sub print_description { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 309 | ▶ | my ($desc)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_description: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 309 | foreach my $c ($desc->childNodes()) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1991 | ▶ | if ($c->nodeType == XML::LibXML::XML_ELEMENT_NODE) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 841 | my $name = $c->nodeName; | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 841 | ▶ | if ($name eq 'title') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # handled per-case | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } elsif ($name eq 'para') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 500 | my $t=get_text($c); | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 500 | $t=~s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 500 | pprint $t,"\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } elsif ($name eq 'section') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | my ($title)=$c->findnodes('./title'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | ▶ | if ($title) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | my $t=get_text($title); | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | pprint "\n\n=head2 $t\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 7 | print_description($c); | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } elsif ($name eq 'example') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 91 | foreach (map { get_text($_) } $c->findnodes('./title')) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 66 | s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 66 | pprint "Example: $_\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 91 | ▶ | unless ($c->findnodes('./title')) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 25 | pprint "Example:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 91 | print_description($c); | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } elsif ($name eq 'code') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 154 | pprint "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 154 | for (get_text($c,1,2)) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 154 | s/\n[ ]*/\n /mg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 154 | s/\\\n/\\\n /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 154 | s/\t/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 154 | pprint " $_\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 154 | pprint "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } elsif ($name eq 'enumerate') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | pprint "\n\n=over 4"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | my $i=1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | foreach my $item ($c->findnodes('./listitem')) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 20 | pprint "\n\n=item ",$i++,"\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 20 | print_description($item); | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | pprint "\n\n=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | warn $0." no rule for tag ".$name."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||