+ $line++;
+ next if /^\s*#/;
+ next if /^\s*$/;
+ my $l = $_;
+ chomp;
+ my @f = split /:\s+|;/;
+ my $p = uc $f[4];
+ my $ref = $pre{$p};
+ if ($ref) {
+ # split up the alias string
+ my @alias = split /=/, $f[5];
+ my $a;
+ foreach $a (@alias) {
+ next if $a eq $p; # ignore if we have it already
+ my $nref = $pre{$a};
+ $pre{$a} = $ref if !$nref; # copy the original ref if new
+ }
+ } else {
+ print "line $line: unknown prefix '$p' on $l in rsgb.cty\n";
+ }
+}
+
+open(OUT, ">$main::data/prefix_data.pl") or die "Can't open $main::data/prefix_data.pl ($!)";
+
+print OUT "\%pre = (\n";
+foreach my $k (sort keys %pre) {
+ my $ans = printpre($k);
+ print OUT " '$k' => '$ans',\n";
+}
+print OUT ");\n\n";
+
+print OUT "\n\%prefix_loc = (\n";
+foreach my $l (sort {$a <=> $b} keys %locn) {
+ print OUT " $l => bless( {";
+ my ($name, $dxcc, $itu, $cq, $utcoff, $latd, $latm, $lats, $latl, $longd, $longm, $longs, $longl) = split /\s+/, $locn{$l};
+
+ $longd += ($longm/60);
+ $longd = 0-$longd if (uc $longl) eq 'W';
+ $latd += ($latm/60);
+ $latd = 0-$latd if (uc $latl) eq 'S';
+ print OUT " name => '$name',";
+ print OUT " dxcc => $dxcc,";
+ print OUT " itu => $itu,";
+ print OUT " cq => $cq,";
+ print OUT " utcoff => $utcoff,";
+ print OUT " lat => $latd,";
+ print OUT " long => $longd";
+ print OUT " }, 'Prefix'),\n";
+}
+print OUT ");\n\n";
+
+close(OUT);
+
+sub addpre
+{
+ my ($p, $ent) = @_;
+ my $ref = $pre{$p};
+ $ref = $pre{$p} = [] if !$ref;
+ push @{$ref}, $ent;;
+}
+
+sub printpre
+{
+ my $p = shift;
+ my $ref = $pre{$p};
+ my $out;
+ my $r;
+
+ foreach $r (@{$ref}) {
+ $out .= "$r,";
+ }
+ chop $out;
+ return $out;
+}
+
+sub addloc
+{
+ my $locstr = shift;
+ $locstr =~ s/\'/\\'/g;
+ my $loc = $loc{$locstr} = $nextloc++;
+ $locn{$loc} = $locstr;
+ return $loc;