add logging of PC92A ip addresses
[spider.git] / perl / spot2csv.pl
1 #!/usr/bin/perl -w
2 #
3 # convert a DXSpider Spot file to csv format
4 #
5 # usage: spot2csv.pl <filename> ...
6 #
7 # Copyright (c) 2001 Dirk Koopman G1TLH
8 #
9 #
10
11 # make sure that modules are searched in the order local then perl
12 use strict;
13
14 BEGIN {
15         # root of directory tree for this system
16         use vars qw($root $is_win);
17         $root = "/spider"; 
18         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
19         
20         unshift @INC, "$root/perl";     # this IS the right way round!
21         unshift @INC, "$root/local";
22
23         $is_win = ($^O =~ /^MS/ || $^O =~ /^OS-2/) ? 1 : 0; # is it Windows?
24 }
25
26 use DXUtil;
27
28 die "usage: spot2csv.pl <filename> ....\n" unless @ARGV;
29
30 my $crnl = $is_win ? "\015\012" : "\012";
31
32 for (@ARGV) {
33         unless (open IN, $_) {
34                 print STDERR "cannot open $_ $!\n";
35                 next;
36         }
37         while (<IN>) {
38                 chomp;
39                 s/([\%\"\'\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
40                 my @spot =  split '\^';
41                 my $date = unpad cldate($spot[2]);
42                 my $time = unpad ztime($spot[2], 1);
43                 print "$spot[0]\t\"$spot[1]\"\t\"$date\"\t$time\t";
44                 print $spot[3] ? "\"$spot[3]\"\t" : "\t";
45                 print "\"$spot[4]\"\t$spot[5]\t$spot[6]\t\"$spot[7]\"$crnl";
46         }
47         close IN;
48 }
49
50
51
52