93 lines
1.6 KiB
Perl
93 lines
1.6 KiB
Perl
#! /usr/bin/env perl
|
|
|
|
use v5.10.1;
|
|
use strict;
|
|
use warnings;
|
|
use Getopt::Long;
|
|
use Pod::Usage;
|
|
use XML::LibXML;
|
|
|
|
use lib "../";
|
|
|
|
use ACU::Defense;
|
|
|
|
# Parse arguments
|
|
my $input; my $output;
|
|
my $help; my $man;
|
|
GetOptions ("output|O=s" => \$output,
|
|
"help|h|?" => \$help,
|
|
"man" => \$man,
|
|
"" => \$input)
|
|
or pod2usage(2);
|
|
pod2usage(1) if $help;
|
|
pod2usage(-exitval => 0, -verbose => 2) if $man;
|
|
|
|
# Open defense XML file
|
|
my $xmlin;
|
|
if (defined $input || $#ARGV == -1) {
|
|
$xmlin = *STDIN;
|
|
}
|
|
else {
|
|
open $xmlin, "<", $ARGV[0] or die $!;
|
|
}
|
|
|
|
binmode $xmlin;
|
|
|
|
my $str;
|
|
$str .= $_ while(<$xmlin>);
|
|
|
|
my $defense = Defense->new($str);
|
|
close $xmlin unless $xmlin eq *STDIN;
|
|
|
|
$defense->genIds;
|
|
|
|
# Save defense XML file
|
|
my $xmlout;
|
|
if (defined $output) {
|
|
open $xmlout, '>', $output;
|
|
binmode $xmlout;
|
|
}
|
|
else {
|
|
$xmlout = *STDOUT;
|
|
}
|
|
print {$xmlout} $defense->toString();
|
|
close $xmlout unless $xmlout eq *STDOUT;
|
|
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
prepare_xml.pl - Prepare defense XML by adding id to groups, questions and answers
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
prepare_xml.pl [options] [file]
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Parse the XML file given (or stdin if no file is given) and add id to groups, questions and answers that have any or duplicate id.
|
|
|
|
Options:
|
|
-output=file.xml save prepared XML to this location
|
|
-help brief help message
|
|
-man full documentation
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over 8
|
|
|
|
=item B<-output=file.xml>
|
|
|
|
Save the prepared XML to a file instead of printing it on standard output.
|
|
|
|
=item B<-help>
|
|
|
|
Print a brief help message and exits.
|
|
|
|
=item B<-man>
|
|
|
|
Prints the manual page and exits.
|
|
|
|
=back
|
|
|
|
=cut
|