Add support for MY_POTA_REF and MY_SIG #1

Merged
dm5wk merged 3 commits from feature_my_ref into main 2024-09-26 11:34:41 +02:00
Showing only changes of commit 0ebec3bb20 - Show all commits

View file

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