+if (@ARGV) {
+ $main::userfn = shift @ARGV;
+ print "user filename now $userfn\n";
+}
+
+DXUser->del_file($main::userfn);
+DXUser->init($main::userfn, 1);
+%u = ();
+my $count = 0;
+my $err = 0;
+while (<DATA>) {
+ chomp;
+ my @f = split /\t/;
+ my $ref = asc_decode($f[1]);
+ if ($ref) {
+ $ref->put();
+ $count++;
+ } else {
+ print "# Error: $f[0]\t$f[1]\n";
+ $err++
+ }
+}
+DXUser->sync; DXUser->finish;
+print "There are $count user records and $err errors\n";
+};
+ print $fh "__DATA__\n";
+
+ if ($v4) {
+ my $sth = $dbh->prepare(q{select call,data from user}) or confess($dbh->errstr);
+ my $rv = $sth->execute;
+ if ($rv) {
+ while (my @row = $sth->fetchrow_array) {
+ my $call = shift @row;
+ my $data = shift @row;
+ if (!is_callsign($call) || $call =~ /^0/) {
+ LogDbg('DXCommand', "Export Error1: $call\t$data");
+ _delete($call);
+ ++$err;
+ next;
+ }
+ my $ref = bless decode_json($data), __PACKAGE__;
+ my $t = $ref->{lastin} || 0;
+ if ($ref->{sort} eq 'U' && !$ref->{priv} && $main::systime > $t + $tooold) {
+ unless ($ref->{lat} && $ref->{long} || $ref->{qth} || $ref->{qra}) {
+ LogDbg('DXCommand', "$ref->{call} deleted, too old");
+ _delete($call);
+ $del++;
+ next;
+ }
+ }
+
+ # only store users that are reasonably active or have useful information
+ print $fh "$call\t" . $ref->asc_encode($basic_info_only) . "\n";
+ ++$count;
+ }
+ } else {
+ dbg(carp($dbh->errstr));
+ }
+ } else {
+ my $key = 0;
+ my $val = undef;
+ my $action;
+ for ($action = DB_File::R_FIRST(); !$dbm->seq($key, $val, $action); $action = DB_File::R_NEXT()) {
+ if (!is_callsign($key) || $key =~ /^0/) {
+ my $eval = $val;
+ my $ekey = $key;
+ $eval =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
+ $ekey =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
+ LogDbg('DXCommand', "Export Error1: $ekey\t$eval");
+ eval {$dbm->del($key)};
+ dbg(carp("Export Error1: $ekey\t$eval\n$@")) if $@;
+ ++$err;
+ next;
+ }
+ my $ref = decode($val);
+ if ($ref) {
+ my $t = $ref->{lastin} || 0;
+ if ($ref->{sort} eq 'U' && !$ref->{priv} && $main::systime > $t + $tooold) {
+ unless ($ref->{lat} && $ref->{long} || $ref->{qth} || $ref->{qra}) {
+ eval {$dbm->del($key)};
+ dbg(carp("Export Error2: $key\t$val\n$@")) if $@;
+ LogDbg('DXCommand', "$ref->{call} deleted, too old");
+ $del++;
+ next;
+ }
+ }
+ # only store users that are reasonably active or have useful information
+ print $fh "$key\t" . $ref->asc_encode($basic_info_only) . "\n";
+ ++$count;
+ } else {
+ LogDbg('DXCommand', "Export Error3: $key\t$val");
+ eval {$dbm->del($key)};
+ dbg(carp("Export Error3: $key\t$val\n$@")) if $@;
+ ++$err;
+ }
+ }
+ }
+ $fh->close;
+ }
+ return "$count Users $del Deleted $err Errors ('sh/log Export' for details)";