From 0ebec3bb20384edb15518fb6f718f66217bb44e4 Mon Sep 17 00:00:00 2001 From: dm5wk Date: Wed, 25 Sep 2024 18:24:29 +0200 Subject: [PATCH] set MY_SIG and MY_SIG_INFO --- adif-pota2sig.pl | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/adif-pota2sig.pl b/adif-pota2sig.pl index 641ecdb..7505094 100755 --- a/adif-pota2sig.pl +++ b/adif-pota2sig.pl @@ -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/\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, "POTA\r\n"); + push(@entry, "" . $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 "POTA\n"; - print "" . $ref . "\n"; + print "POTA\r\n"; + print "" . $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/^