Add support for MY_POTA_REF and MY_SIG #1
|
@ -39,18 +39,18 @@ use Pod::Usage;
|
||||||
|
|
||||||
my $input_file = "";
|
my $input_file = "";
|
||||||
my $output_file = "";
|
my $output_file = "";
|
||||||
my $my_ref = "";
|
my $my_refs = "";
|
||||||
my $output_template = "";
|
my $output_template = "";
|
||||||
my $force_output = 0;
|
my $force_output = 0;
|
||||||
|
|
||||||
GetOptions (
|
GetOptions (
|
||||||
"i|input=s" => \$input_file,
|
"i|input=s" => \$input_file,
|
||||||
"o|output=s" => \$output_file,
|
"o|output=s" => \$output_file,
|
||||||
"r|reference=s" => \$my_ref,
|
"r|reference=s" => \$my_refs,
|
||||||
"f|force" => \$force_output,
|
|
||||||
"t|template=s" => \$output_template,
|
"t|template=s" => \$output_template,
|
||||||
|
"f|force" => \$force_output,
|
||||||
"h|help" => sub {pod2usage(-verbose => 2)}
|
"h|help" => sub {pod2usage(-verbose => 2)}
|
||||||
) or die("Error in command line arguments\n");
|
) or die("Error in command line arguments");
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
|
||||||
|
@ -95,11 +95,11 @@ program will stop. Using B<-f> will overwrite output files.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
if (($my_ref ne "") && ($output_template eq "")) {
|
if (($my_refs ne "") && ($output_template eq "")) {
|
||||||
die "-t is mandatory for -r";
|
die "-t is mandatory for -r";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($output_template ne "") && ($my_ref eq "")) {
|
if (($output_template ne "") && ($my_refs eq "")) {
|
||||||
die "-r is mandatory for -t";
|
die "-r is mandatory for -t";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,17 +118,17 @@ if (($input_file eq "-") || ($input_file eq "")) {
|
||||||
open($FH_IN, '<', $input_file) or die "$input_file: $!";
|
open($FH_IN, '<', $input_file) or die "$input_file: $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
my @output_filenames;
|
my %filenames_ref = ();
|
||||||
|
|
||||||
if ($my_ref ne "") {
|
if ($my_refs ne "") {
|
||||||
foreach (split(/,/, $my_ref)) {
|
foreach (split(/,/, $my_refs)) {
|
||||||
push(@output_filenames, $output_template =~ s/REF/$_/r);
|
$filenames_ref{$output_template =~ s/REF/$_/r} = $_;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
push(@output_filenames, $output_file);
|
$filenames_ref{$output_file} = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $output_filename (@output_filenames) {
|
foreach my $output_filename (keys %filenames_ref) {
|
||||||
seek $FH_IN, 0, 0;
|
seek $FH_IN, 0, 0;
|
||||||
|
|
||||||
my $FH_OUT;
|
my $FH_OUT;
|
||||||
|
@ -158,21 +158,35 @@ foreach my $output_filename (@output_filenames) {
|
||||||
push @entry, $_;
|
push @entry, $_;
|
||||||
if (m/<EOR>\s+$/i) {
|
if (m/<EOR>\s+$/i) {
|
||||||
# entry complete
|
# entry complete
|
||||||
|
|
||||||
|
# maybe add MY_SIG
|
||||||
|
my $my_ref = $filenames_ref{$output_filename};
|
||||||
|
if ($my_ref ne "") {
|
||||||
|
my $last = pop(@entry);
|
||||||
|
push(@entry, "<MY_SIG:4>POTA\r\n");
|
||||||
|
push(@entry, "<MY_SIG_INFO:" . length($my_ref) . ">" . $my_ref . "\r\n");
|
||||||
|
push(@entry, $last);
|
||||||
|
}
|
||||||
|
|
||||||
|
# print whole entry
|
||||||
if (scalar(@pota_refs) > 0) {
|
if (scalar(@pota_refs) > 0) {
|
||||||
|
# maybe print entry multiple times
|
||||||
# add sig_info to each pota reference
|
# add sig_info to each pota reference
|
||||||
foreach my $ref (@pota_refs) {
|
foreach my $ref (@pota_refs) {
|
||||||
# print all except last
|
# print all except last
|
||||||
print @entry[0 .. $#entry - 1];
|
print @entry[0 .. $#entry - 1];
|
||||||
# insert POTA SIG
|
# insert POTA SIG
|
||||||
print "<SIG:4>POTA\n";
|
print "<SIG:4>POTA\r\n";
|
||||||
print "<SIG_INFO:" . length($ref) . ">" . $ref . "\n";
|
print "<SIG_INFO:" . length($ref) . ">" . $ref . "\r\n";
|
||||||
# print last
|
# print last
|
||||||
print $entry[-1];
|
print $entry[-1];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# no park reference in this entry
|
# no park reference in this entry
|
||||||
|
# print entry only once
|
||||||
print @entry;
|
print @entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
# clear entry and pota refs for next entry
|
# clear entry and pota refs for next entry
|
||||||
@entry = ();
|
@entry = ();
|
||||||
@pota_refs = ();
|
@pota_refs = ();
|
||||||
|
@ -183,6 +197,13 @@ foreach my $output_filename (@output_filenames) {
|
||||||
# fill pota_refs with references
|
# fill pota_refs with references
|
||||||
@pota_refs = split(/,/, $val);
|
@pota_refs = split(/,/, $val);
|
||||||
chomp @pota_refs;
|
chomp @pota_refs;
|
||||||
|
} elsif (m/^<MY_SIG(_INFO)?:/) {
|
||||||
|
if ($force_output) {
|
||||||
|
# remove MY_SIG and MY_SIG_INFO
|
||||||
|
pop(@entry);
|
||||||
|
} else {
|
||||||
|
die "MY_SIG exists. Overwrite with --force";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close($FH_OUT);
|
close($FH_OUT);
|
||||||
|
|
Loading…
Reference in a new issue