#!/usr/bin/perl

use strict;
use warnings;

# ---------------------
# PatchSet 1 
# Date: 2002/07/23 07:41:30
# Author: hpa
# Branch: HEAD
# Tag: (none) 
# Log:
# Initial revision
# 
# Members: 
# 	klibc.cvsroot/snprintf.c:INITIAL->1.1 
# 	klibc.cvsroot/vsnprintf.c:INITIAL->1.1 
# 	klibc.cvsroot/klibc/Makefile:INITIAL->1.1 
# 	klibc.cvsroot/klibc/snprintf.c:INITIAL->1.1 
# 	klibc.cvsroot/klibc/vsnprintf.c:INITIAL->1.1 
# 
# --- /dev/null	2005-04-30 18:00:24.840397008 +0200
# +++ klibc/klibc.cvsroot/snprintf.c	2005-05-02 19:57:42.879913000 +0200
# @@ -0,0 +1,19 @@
# +/*


my $patch = $ARGV[0];

my $author_name = "";
my $author_mail = "";
my $author_date = "";
my $tag = "";
my @log = ();
my %files = ();

open (my $fd, $patch);
while (my $line = <$fd>) {
	if ($line =~ m/^Date: (.*)/) {
		$author_date = $1;
	} elsif ($line =~ m/^Author: (.*)/) {
		$author_name = $1;
	} elsif ($line =~ m/^Tag: (.*) /) {
		$tag = $1;
	} elsif ($line =~ m/^Log:/) {
		while (my $line = <$fd>) {
			if ($line =~ m/^Members: /) {
				last;
			}
			push @log, $line;
		}
	} elsif ($line =~ m/^(---|\+\+\+) ([^\t]*)/) {
		chomp($line);
		my $file = $2;
		$file =~ s/^klibc\///;
		if ($file ne "/dev/null") {
			$files{$file} = $file;
		}
	}
}
close $fd;

open $fd, "> $patch.files";
foreach my $file (sort keys %files) {
	print $fd "$file\n";
};
close $fd;

if ($tag ne "(none)") {
	open $fd, "> $patch.tag";
	print $fd $tag;
	close $fd;
}

open $fd, "> $patch.log";
print $fd (@log);
close $fd;

if ($author_name eq 'hpa') {
    $author_name = 'H. Peter Anvin';
    $author_mail = 'hpa@zytor.com';
} elsif ($author_name eq 'olh') {
    $author_name = 'Olaf Hering';
    $author_mail = 'olh@suse.de';
} elsif ($author_name eq 'rmk') {
    $author_name = 'Russell King';
    $author_mail = 'rmk@arm.linux.org.uk';
} elsif ($author_name eq 'bos') {
    $author_name = "Bryan O\'Sullivan";
    $author_mail = 'bos@serpentine.com';
} elsif ($author_name eq 'gregkh') {
    $author_name = 'Greg Kroah-Hartman';
    $author_mail = 'greg@kroah.com';
} else {
    die "$0: don\'t know who $author_name is\n";
}

if ($author_mail eq "") {
	$author_mail = "none";
}

open $fd, "> $patch.author";
print $fd "export AUTHOR_NAME=\"$author_name\"\n";
print $fd "export AUTHOR_EMAIL=\"$author_mail\"\n";
print $fd "export AUTHOR_DATE=\"$author_date\"\n";
close $fd;

print "$patch $author_name \[$author_date\]\n";
