2 # Gtk Handler for Debug Files
15 @ISA = qw(Gtk::Window);
21 my $regexp = shift || '';
22 my $nolines = shift || 1;
24 my $self = new Gtk::Window;
26 $self->set_default_size(400, 400);
27 $self->set_transient_for($parent) if $parent;
28 $self->signal_connect('destroy', sub {$self->destroy} );
29 $self->signal_connect('delete_event', sub {$self->destroy; return undef;});
30 $self->set_title("Debug Output - $regexp");
31 $self->border_width(0);
34 my $box1 = new Gtk::VBox(0, 0);
38 my $swin = new Gtk::ScrolledWindow(undef, undef);
39 $swin->set_policy('automatic', 'automatic');
40 $box1->pack_start($swin, 1, 1, 0);
43 my $button = new Gtk::Button('close');
44 $button->signal_connect('clicked', sub {$self->destroy});
45 $box1->pack_end($button, 0, 1, 0);
48 my $clist = new_with_titles Gtk::CList('Time', 'Data');
52 $self->{fp} = DXLog::new('debug', 'dat', 'd');
54 my @today = Julian::unixtoj(time);
55 my $fh = $self->{fh} = $self->{fp}->open(@today);
57 $self->{regexp} = $regexp if $regexp;
58 $self->{nolines} = $nolines;
59 $self->{clist} = $clist;
61 $self->{id} = Gtk::Gdk->input_add($fh->fileno, ['read'], sub {$self->handleinp(@_); 1;}, $fh);
71 Gtk::Gdk->input_remove($self->{id});
72 delete $self->{clist};
77 my ($self, $socket, $fd, $flags) = @_;
79 my $offset = exists $self->{rbuf} ? length $self->{rbuf} : 0;
80 my $l = sysread($socket, $self->{rbuf}, 1024, $offset);
83 while ($self->{rbuf} =~ s/^([^\015\012]*)\015?\012//) {
85 if ($self->{regexp}) {
86 push @{$self->{prev}}, $line;
87 shift @{$self->{prev}} while @{$self->{prev}} > $self->{nolines};
88 if ($line =~ m{$self->{regexp}}oi) {
89 $self->printit(@{$self->{prev}});
90 @{$self->{prev}} = [];
93 $self->printit($line);
104 my $clist = $self->{clist};
107 $line =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
108 my @line = split /\^/, $line, 2;
110 my ($sec,$min,$hour) = gmtime((defined $t) ? $t : time);
111 my $buf = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
112 $clist->append($buf, @line);