+{
+ return dbgtrace(@_);
+}
+
+sub dbgprintring
+{
+ return unless $fp;
+ my $i = shift || 0;
+ my $count = @dbgring;
+ $i = @dbgring-$i if $i;
+ return 0 unless $i < $count; # do nothing if there is nothing to print
+
+ my $first;
+ my $l;
+ for ( ; $i < $count; ++$i) {
+ my ($t, $str) = split /\^/, $dbgring[$i], 2;
+ next unless $t;
+ my $lt = time;
+ unless ($first) {
+ $fp->writeunix($lt, "$lt^###");
+ $fp->writeunix($lt, "$lt^### RINGBUFFER START at line $i (zero base)");
+ $fp->writeunix($lt, "$lt^###");
+ $first = $t;
+ }
+ my $buf = sprintf "%02d:%02d:%02d", (gmtime($t))[2,1,0];
+ $fp->writeunix($lt, "$lt^RING: $buf^$str");
+ ++$l;
+ }
+ my $et = time;
+ $fp->writeunix($et, "$et^###");
+ $fp->writeunix($et, "$et^### RINGBUFFER END $l debug lines written");
+ $fp->writeunix($et, "$et^###");
+ return $l;
+}
+
+sub dbgclearring
+{
+ @dbgring = ();
+}
+
+# clean out old debug files, stop when you get a gap of more than a month
+sub dbgclean
+{
+ my $date = $fp->unixtoj($main::systime)->sub($keepdays+1);
+ my $i = 0;
+
+ while ($i < 31) {
+ my $fn = $fp->_genfn($date);
+ if (-e $fn) {
+ unlink $fn;
+ $i = 0;
+ }
+ else {
+ $i++;
+ }
+ $date = $date->sub(1);
+ }