# vim:sw=4:et:ts=8:tw=72
# bugdb.pl - Functions for processing a database of talkback reports.
# L. David Baron, 2001-08-18

use 5.004;
use strict;
use Getopt::Long;

sub read_database($$) {
    my ($dbfile, $db) = @_;
    if (open(DBFILE, "<$dbfile")) {
        while (<DBFILE>) {
            chop;
            my ($bbid, $builddate, $stacksig, $realsig, $platform) = split /,/;
            $db->{$bbid} = {
                builddate => $builddate,
                stacksig => $stacksig,
                realsig => $realsig,
                platform => $platform
                };
        }
        close(DBFILE);
    } else {
        print "Creating new database $dbfile.\n"; # we do it later
    }
}

sub write_database($$) {
    my ($dbfile, $db) = @_;
    open(DBFILE, ">$dbfile");
    my $bbid;
    my $val;
    while (($bbid, $val) = each(%{$db})) {
        print DBFILE join(",", ($bbid,
                                $val->{builddate},
                                $val->{stacksig},
                                $val->{realsig},
                                $val->{platform})) . "\n";
    }
    close(DBFILE);
}

return 1;
