2 # The system variables - those indicated will need to be changed to suit your
3 # circumstances (and callsign)
5 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 @EXPORT = qw(dbginit dbgstore dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose confess croak cluck);
17 use vars qw(%dbglevel $fp);
26 # Avoid generating "subroutine redefined" warnings with the following
27 # hack (from CGI::Carp):
28 if (!defined $DB::VERSION) {
30 eval qq( sub confess {
31 \$SIG{__DIE__} = 'DEFAULT';
32 DXDebug::dbgstore(\$@, Carp::shortmess(\@_));
36 \$SIG{__DIE__} = 'DEFAULT';
37 DXDebug::dbgstore(\$@, Carp::longmess(\@_));
40 sub carp { DXDebug::dbgstore(Carp::shortmess(\@_)); }
41 sub cluck { DXDebug::dbgstore(Carp::longmess(\@_)); }
44 CORE::die(Carp::shortmess($@)) if $@;
46 eval qq( sub confess { die Carp::longmess(\@_); };
47 sub croak { die Carp::shortmess(\@_); };
48 sub cluck { warn Carp::longmess(\@_); };
49 sub carp { warn Carp::shortmess(\@_); };
60 my @l = split /\n/, $r;
62 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
63 print "$_\n" if defined \*STDOUT;
64 $fp->writeunix($t, "$t^$_");
71 # add sig{__DIE__} handling
72 if (!defined $DB::VERSION) {
73 $SIG{__WARN__} = sub { dbgstore($@, Carp::shortmess(@_)); };
74 $SIG{__DIE__} = sub { dbgstore($@, Carp::longmess(@_)); };
77 $fp = DXLog::new('debug', 'dat', 'd');
82 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
90 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
99 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
101 for (my $o = 0; $o < length $l; $o += 16) {
102 my $c = substr $l, $o, 16;
103 my $h = unpack "H*", $c;
104 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
105 my $left = 16 - length $c;
106 $h .= ' ' x (2 * $left) if $left > 0;
107 dbgstore($m . sprintf("%4d:", $o) . "$h $c");
108 $m = ' ' x (length $m);
118 foreach $entry (@_) {
119 $dbglevel{$entry} = 1;
127 foreach $entry (@_) {
128 delete $dbglevel{$entry};
134 return keys (%dbglevel);
140 return $dbglevel{$s};
145 return Carp::shortmess(@_);
150 return Carp::longmess(@_);