+
+#
+# print some items from the log backwards in time
+#
+# This command outputs a list of n lines starting from line $from to $to
+#
+sub search
+{
+ my $from = shift;
+ my $to = shift;
+ my $date = $fp->unixtoj(shift);
+ my $pattern = shift;
+ my $search;
+ my @out;
+ my $eval;
+ my $count;
+
+ $search = 1;
+ $eval = qq(
+ my \$c;
+ my \$ref;
+ for (\$c = \$#in; \$c >= 0; \$c--) {
+ \$ref = \$in[\$c];
+ if ($search) {
+ \$count++;
+ next if \$count < \$from;
+ push \@out, \$ref;
+ last if \$count >= \$to; # stop after n
+ }
+ }
+ );
+
+ $fp->close; # close any open files
+
+ my $fh = $fp->open($date);
+ for ($count = 0; $count < $to; ) {
+ my @in = ();
+ if ($fh) {
+ while (<$fh>) {
+ chomp;
+ push @in, [ split '\^' ] if length > 2;
+ }
+ eval $eval; # do the search on this file
+ return ("Geomag search error", $@) if $@;
+ last if $count >= $to; # stop after n
+ }
+ $fh = $fp->openprev(); # get the next file
+ last if !$fh;
+ }
+
+ return @out;
+}
+
+#
+# the standard log printing interpreting routine.
+#
+# every line that is printed should call this routine to be actually visualised
+#
+# Don't really know whether this is the correct place to put this stuff, but where
+# else is correct?
+#
+# I get a reference to an array of items
+#
+sub print_item
+{
+ my $r = shift;
+ my @ref = @$r;
+ my $d = cldate($ref[1]);
+ my ($t) = (gmtime($ref[1]))[2];
+
+ return sprintf("$d %02d %5d %3d %3d %-37s <%s>", $t, $ref[2], $ref[3], $ref[4], $ref[5], $ref[0]);
+}
+
+#
+# read in this month's data
+#
+sub readfile
+{
+ my $date = $fp->unixtoj(shift);
+ my $fh = $fp->open($date);
+ my @spots = ();
+ my @in;
+
+ if ($fh) {
+ while (<$fh>) {
+ chomp;
+ push @in, [ split '\^' ] if length > 2;
+ }
+ }
+ return @in;
+}
+
+# enter the spot for dup checking and return true if it is already a dup
+sub dup
+{
+ my ($d, $sfi, $k, $a, $text) = @_;
+
+ # dump if too old
+ return 2 if $d < $main::systime - $dupage;
+
+ my $dupkey = "W$d|$sfi|$k|$a";
+ return DXDupe::check($dupkey, $main::systime+$dupage);
+}
+
+sub listdups
+{
+ return DXDupe::listdups('W', $dupage, @_);
+}