X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcreate_prefix.pl;h=f1a0b554856f132be04df0a5b653f621ff6a440e;hb=refs%2Fheads%2Fmulticonnect;hp=1923bc3e8357d8be54f5c0304bb3225ab942a63a;hpb=14fa5913c9b5be9f55ef741236aaafbe516f64fe;p=spider.git diff --git a/perl/create_prefix.pl b/perl/create_prefix.pl index 1923bc3e..f1a0b554 100755 --- a/perl/create_prefix.pl +++ b/perl/create_prefix.pl @@ -1,4 +1,4 @@ -#!/bin/env perl +#!/usr/bin/env perl # a program to create a prefix file from a wpxloc.raw file # # Copyright (c) - Dirk Koopman G1TLH @@ -6,20 +6,26 @@ # # -require 5.004; +use 5.10.1; # search local then perl directories BEGIN { # root of directory tree for this system $root = "/spider"; $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'}; - + + mkdir "$root/local_data", 02777 unless -d "$root/local_data"; + unshift @INC, "$root/perl"; # this IS the right way round! unshift @INC, "$root/local"; } use DXVars; +use SysVar; + use Data::Dumper; +use DXUtil; + use strict; my %loc = (); # the location unique hash @@ -28,10 +34,26 @@ my %locn = (); # the inverse of the above my %pre = (); # the prefix hash my %pren = (); # the inverse -# open the input file -my $ifn = $ARGV[0] if $ARGV[0]; -$ifn = "$main::data/wpxloc.raw" if !$ifn; -open (IN, $ifn) or die "can't open $ifn ($!)"; +my $prefix; +my $system; + +if (@ARGV && $ARGV[0] =~ /^-?-?syst?e?m?$/) { + $prefix = $main::data; + ++$system; + shift; + say "create_prefix.pl: creating SYSTEM prefix files"; +} else { + $prefix = $main::local_data; + say "create_prefix.pl: creating LOCAL prefix files"; +} + +my $ifn; + +$ifn = $system ? "$main::data/wpxloc.raw" : "$prefix/wpxloc.raw"; +unless (open (IN, $ifn)) { + $ifn = "$main::data/wpxloc.raw"; + open(IN, $ifn) or die "can't open $ifn ($!)"; +} # first pass, find all the 'master' location records while () { @@ -91,10 +113,17 @@ close(IN); #print Data::Dumper->Dump([\%pre, \%locn], [qw(pre locn)]); # now open the cty.dat file if it is there +my $r; +$ifn = $system ? "$main::data/cty.dat" : "$prefix/cty.dat"; +unless ($r = open (IN, $ifn)) { + $ifn = "$main::data/cty.dat"; + $r = open(IN, $ifn); +} + my @f; my @a; $line = 0; -if (open(IN, "$main::data/cty.dat")) { +if ($r) { my $state = 0; while () { $line++; @@ -125,7 +154,7 @@ if (open(IN, "$main::data/cty.dat")) { close IN; -open(OUT, ">$main::data/prefix_data.pl") or die "Can't open $main::data/prefix_data.pl ($!)"; +open(OUT, ">$prefix/prefix_data.pl") or die "Can't open $prefix/prefix_data.pl ($!)"; print OUT "\%pre = (\n"; foreach my $k (sort keys %pre) {