summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2008-11-29 01:42:50 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2008-11-29 01:42:50 -0800
commit96862c18193fafe16178e2987f23edc14e112d6d (patch)
treee28cb5f5dcf060c73e3c652df689d1e403d09b69 /PatchIndexer.pm
parentIndex handling tool. (diff)
downloadmysql-extras-96862c18193fafe16178e2987f23edc14e112d6d.tar.gz
mysql-extras-96862c18193fafe16178e2987f23edc14e112d6d.tar.bz2
mysql-extras-96862c18193fafe16178e2987f23edc14e112d6d.zip
Split out common part of tools.
Diffstat (limited to 'PatchIndexer.pm')
-rw-r--r--PatchIndexer.pm111
1 files changed, 111 insertions, 0 deletions
diff --git a/PatchIndexer.pm b/PatchIndexer.pm
new file mode 100644
index 0000000..3d5f3e3
--- /dev/null
+++ b/PatchIndexer.pm
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+package PatchIndexer;
+#use Data::Dumper;
+use Clone qw(clone);
+use warnings;
+use strict;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
+require Exporter;
+@ISA = qw(Exporter AutoLoader);
+@EXPORT = qw( parseIndex printIndex );
+
+sub parseIndex {
+ my $fh = shift;
+ our (@data, $patch, @ver, @pn, $desc, $comment);
+ while(my $i = <$fh>) {
+ #print "DATA: $i";
+ if(0) {
+ # These lines exists for patching only
+ #
+ #
+ } elsif($i =~ /^\s*$/) {
+ # Ignore whitespace
+ #print "White: $i";
+ getEntry();
+ storeEntry() if(length($patch));
+ #cleanEntry();
+ } elsif($i =~ /^\@patch\s+(\S+)\s+$/) {
+ cleanEntry();
+ $patch = $1;
+ chomp $patch;
+ } elsif($i =~ /^\@ver\s+(\S+)\s+to\s+(\S+)\s+$/) {
+ my $min = $1;
+ my $max = $2;
+ chomp $min;
+ chomp $max;
+ #print "Pushing ver $1 $2\n";
+ push @ver, [$1,$2];
+ } elsif($i =~ /^\@pn\s+(\S+)\s+$/) {
+ my $mypn = $1;
+ chomp $mypn;
+ push @pn, $mypn;
+ } elsif($i =~ /^\@\@\s+(.*)\s+$/) {
+ # Do not chomp comments
+ $desc .= $1."\n";
+ } elsif($i =~ /^#\s+(.*)\s+$/) {
+ # Do not chomp comments
+ $comment .= $1."\n";
+ } else {
+ print "Bad! $i\n";
+ }
+ }
+ storeEntry() if(length($patch));
+ return @data;
+
+ sub getEntry {
+ my %entry;
+ $entry{patch} = $patch;
+ $entry{ver} = \@ver;
+ $entry{pn} = \@pn;
+ chomp $desc;
+ $entry{desc} = $desc if (length($desc) > 0);
+ chomp $comment;
+ $entry{comment} = $comment if (length($comment) > 0);
+ #print Dumper(\%entry);
+ return %entry;
+ }
+ sub storeEntry {
+ my %entry = getEntry();
+ my $entry = clone(\%entry);
+ #print Dumper(\%entry);
+ push @data, $entry;
+ cleanEntry();
+ }
+ sub cleanEntry {
+ $patch = '';
+ @ver = ();
+ @pn = ();
+ $desc = '';
+ $comment = '';
+ }
+}
+
+sub printIndex {
+ $_ = shift;
+ my @index = @{ $_ };
+ my $os = '';
+ foreach my $i (@index) {
+ #print Dumper($i);
+ $os .= sprintf "\@patch %s\n", $i->{patch};
+ foreach $_ ( @{ $i->{ver} } ) {
+ my @v = @$_;
+ $os .= sprintf "\@ver %s to %s\n", $v[0], $v[1];
+ }
+ foreach my $pn ( @{ $i->{pn} } ) {
+ $os .= sprintf "\@pn %s\n", $pn;
+ }
+ if($i->{desc}) {
+ my $desc = $i->{desc};
+ $desc =~ s/^/@@ /gm;
+ $os .= $desc."\n";
+ }
+ if($i->{comment}) {
+ my $comment = $i->{comment};
+ $comment =~ s/^/# /gm;
+ $os .= $comment."\n";
+ }
+ $os .= "\n";
+ }
+ return $os;
+}