#!/usr/bin/perl use strict; use warnings; use Tk; # # Create a main window. # my $mw = MainWindow->new; $mw->title("Kernel (ChangeLog) Viewer"); my $g_kernel = ""; # For example purposes, we'll use one word for each letter my @kernels = sort( glob( "Change*" ) ); # # Create Listbox and insert the list of kernels into it. # my $lb = $mw->Scrolled("Listbox", -scrollbars => "osoe", )->pack(-side => "left", -fill => "y"); $lb->insert("end", @kernels); $lb->bind( '<>' => sub { loadKernel( $lb->curselection ) } ); # # Top top which has the changelog # my $lbtop = $mw->Scrolled("Listbox", -scrollbars => "osoe", )->pack(-side => "top", -fill => "y", -fill => "x"); $lbtop->bind('<>' => sub { loadChangelogDetail( $lbtop->curselection ) ;} ); # # The text which holds the changelog entry. # my $textbox = $mw->Scrolled("Text")->pack( -side => "bottom", -fill => "y", -fill => "x" ); # # Run the mainloop # MainLoop; # # Called when a kernel is selected. # # Clear the textbox. # # Load the one-line-summary of the changelog in the top listbox. # sub loadKernel { my( $val ) = ( @_ ); my $kernel = $lb->get($val ); print "LOADING $kernel [index $val]\n"; $g_kernel = $kernel; $lbtop->delete(0, 'end'); $textbox->delete( "1.0", 'end' ); open( FILE, "<", $kernel ) or die "Failed to load file: $kernel - $!"; my $commit; my $author; my $date; my $first; while( my $line = ) { chomp( $line ); next if ( $line =~ /^$/ ); if ( $line =~ /^commit (.*)/ ) { $commit = $1; } elsif ( $line =~ /^Author: (.*)/ ) { $author = $1; } elsif ( $line =~ /^Date: (.*)/ ) { $date = $1; } else { if ( length($author ) && length($commit) && length($date) ) { if ( ! length($first ) ) { # print "Author: $author\n"; # print "Commit: $commit\n"; # print "Date: $date\n"; # print "\t$line\n"; $line =~ s/^\s+|\s+$//g; $lbtop->insert("end", $line ); $first = $line; $author = ""; $commit = ""; $date = ""; $first = ""; } } } } close( FILE ); } =begin doc Given a line like "KVM: foo" show all the text of that entry until the next commit. =end doc =cut sub loadChangelogDetail { my( $val ) = ( @_ ); # the changelog entry we wish to show my $change = $lbtop->get( $val ); my @lines = (); my $found = 0; open( FILE, "<", $g_kernel ); while( my $line = ) { chomp( $line ); my $header = $line; $header =~ s/^\s+|\s+$//g; if ( $header eq $change ) { $found = 1; } if ( $found ) { push( @lines, $line . "\n"); } if ( $line =~ /^$/ ) { $found = 0; } } close( FILE ); $textbox->delete( "1.0", "end" ); foreach my $line ( @lines ) { $textbox->insert("end", $line ); } }