| 43 |
exit 0; |
exit 0; |
| 44 |
} |
} |
| 45 |
|
|
| 46 |
die "Must specify release for which to generate example." if ! $opt_r; |
die "Must specify release for which to generate example.\n" if ! $opt_r; |
| 47 |
|
|
| 48 |
my $xmlfile = shift; |
my $xmlfile = shift; |
| 49 |
die "Must specify XML file to parse!" if ! $xmlfile; |
die "Must specify XML file to parse!\n" if ! $xmlfile; |
| 50 |
die "Specified XML file \"$xmlfile\" not found." if ! -f $xmlfile; |
die "Specified XML file \"$xmlfile\" not found.\n" if ! -f $xmlfile; |
| 51 |
|
|
| 52 |
my $arch = $opt_a ? "$opt_a" : "i386"; |
my $arch = $opt_a ? "$opt_a" : "i386"; |
| 53 |
my $release = $opt_r; |
my $release = $opt_r; |
| 62 |
# Start parsing the specified file |
# Start parsing the specified file |
| 63 |
$p->parse_file($xmlfile); |
$p->parse_file($xmlfile); |
| 64 |
|
|
| 65 |
|
# Replace entities in examples |
| 66 |
|
# FIXME: should maybe be extracted from entity definition |
| 67 |
|
sub replace_entities { |
| 68 |
|
my ($text) = @_; |
| 69 |
|
|
| 70 |
|
$text =~ s/&archive-mirror;/http.us.debian.org/; |
| 71 |
|
$text =~ s/&releasename;/$release/; |
| 72 |
|
|
| 73 |
|
# Any unrecognized entities? |
| 74 |
|
if ( $text =~ /&[^ ]+;/ ) { |
| 75 |
|
my ($ent) = $text =~ m/.*(&[^ ]+;).*/; |
| 76 |
|
die "Error: unrecognized entity '$ent'\n" |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
return $text; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
# Execute when start tag is encountered |
# Execute when start tag is encountered |
| 83 |
sub start_rtn { |
sub start_rtn { |
| 84 |
my ($tagname, $text, $attr) = @_; |
my ($tagname, $text, $attr) = @_; |
| 133 |
# Clean leading and trailing whitespace for titles |
# Clean leading and trailing whitespace for titles |
| 134 |
$text =~ s/^[[:space:]]*//; |
$text =~ s/^[[:space:]]*//; |
| 135 |
$text =~ s/[[:space:]]*$//; |
$text =~ s/[[:space:]]*$//; |
| 136 |
|
|
| 137 |
|
$text = replace_entities($text); |
| 138 |
$tagstatus{$titletag}{'title'} = $text; |
$tagstatus{$titletag}{'title'} = $text; |
| 139 |
$settitle = 0; |
$settitle = 0; |
| 140 |
} |
} |
| 155 |
$text =~ s/^[[:space:]]*//; |
$text =~ s/^[[:space:]]*//; |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
# Replace entities in examples |
$text = replace_entities($text); |
|
# FIXME: should maybe be extracted from entity definition |
|
|
$text =~ s/&archive-mirror;/http.us.debian.org/; |
|
|
|
|
| 159 |
print "$text"; |
print "$text"; |
| 160 |
|
|
| 161 |
$example{'first'} = 0; |
$example{'first'} = 0; |
| 174 |
my $ts = $tagstatus{$tagname}{'count'}; |
my $ts = $tagstatus{$tagname}{'count'}; |
| 175 |
$tagstatus{$tagname}{'count'} -= 1; |
$tagstatus{$tagname}{'count'} -= 1; |
| 176 |
print STDERR "$tagname $tagstatus{$tagname}{'count'}\n" if $opt_d; |
print STDERR "$tagname $tagstatus{$tagname}{'count'}\n" if $opt_d; |
| 177 |
die "Invalid XML file: negative count for tag <$tagname>!" if $tagstatus{$tagname}{'count'} < 0; |
die "Invalid XML file: negative count for tag <$tagname>!\n" if $tagstatus{$tagname}{'count'} < 0; |
| 178 |
|
|
| 179 |
if ( exists $ignore{'tag'} ) { |
if ( exists $ignore{'tag'} ) { |
| 180 |
if ( $ignore{'tag'} eq $tagname && $ignore{'depth'} == $ts ) { |
if ( $ignore{'tag'} eq $tagname && $ignore{'depth'} == $ts ) { |