#! /usr/local/bin/perl

#
# Copyright (c) 1990 The Ohio State University.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that: (1) source distributions retain this entire copyright
# notice and comment, and (2) distributions including binaries display
# the following acknowledgement:  ``This product includes software
# developed by The Ohio State University and its contributors''
# in the documentation or other materials provided with the distribution
# and in all advertising materials mentioning features or use of this
# software. Neither the name of the University nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

#
# No, I don't remember exactly what this does.  I think it was used for 
# testing the database packing/unpacking routines.
#

do 'yagrip.pl' || 
    die "Can't do yagrip.pl";

do 'backup.defs' ||
    die "Can't do backup.defs";

do "backuplib.perl" ||
    die sprintf("Can't do %s", "backuplib.perl");

do "backuplib.perl";

$dbname = "foo";
$lockname = "/tmp/bar";

local(%replace, %add, %result);

$| = 0;

main_loop:
  while (1) {
    printf(">");

    $_ = <>;
    chop;
    @cmd = split;
    %replace = ();
    %add = ();

    if ($cmd[0] eq "update") {
	if ($#cmd != 3) {
		printf("huh?\n");
		next main_loop;
	}

	$replace{$cmd[2]} = $cmd[3];
	if (&update_db($dbname, $lockname, $cmd[1], "test", 
		       $DB_UPDATE, *replace, *add, *result) != 0) {
		printf("failed\n");
		next main_loop;
	}
    } elsif ($cmd[0] eq "add") {
	if ($#cmd != 3) {
		printf("huh?\n");
		next main_loop;
	}

	$add{$cmd[2]} = $cmd[3];
	if (&update_db($dbname, $lockname, $cmd[1], "test", 
		       $DB_UPDATE, *replace, *add, *result) != 0) {
		printf("failed\n");
		next main_loop;
	}
    } elsif ($cmd[0] eq "create") {
	if ($#cmd != 3) {
		printf("huh?\n");
		next main_loop;
	}

	$replace{$cmd[2]} = $cmd[3];
	if (&update_db($dbname, $lockname, $cmd[1], "test", 
		       $DB_CREATE, *replace, *add, *result) != 0) {
		printf("failed\n");
		next main_loop;
	}
    } elsif ($cmd[0] eq "print") {
	if ($#cmd != 1) {
		printf("huh?\n");
		next main_loop;
	}

	if (&update_db($dbname, $lockname, $cmd[1], "test", 
		       $DB_READ, *replace, *add, *result) != 0) {
		printf("failed\n");
		next main_loop;
	}

	foreach $key (keys %result) {
		printf("key %s\t%s\n",
			$key,
			$result{$key});
	}
    } elsif ($cmd[0] eq "quit") {
	exit;
    } else {
	printf("huh?\n");
    }
}


