# include	<stdio.h>
# include	"sptree.h"
SPTREE *tree;
char	lbuf[256];
# define	TRUE	1
# define	FALSE	0
main(argc, argv)
char	**argv;
{	extern char *chk_alloc();
	int	i = 1;
	SPBLK *q;
	int	lookup = FALSE;
	char	buf[20];
	
	tree = spinit();
	if (argv[1][0] == '-') {
		if (argv[1][1] == 'l') {
			lookup = TRUE;
			i++;
			}
		}
	if (argv[1][0] >= '0' && argv[1][1] <= '9') {
		for (i = 0; i < atoi(argv[1]); i++) {
			sprintf(buf, "%05d", i);
			new(buf);
			}
		}
	else {
		for (; i < argc; i++)
			new(argv[i]);
		}
	while (1) {
		ptree(tree);
		printf(lookup ? "Lookup ? " : "Delete ? ");
		fflush(stdout);
		gets(lbuf);
		if (lbuf[strlen(lbuf)-1] == '\n')
			lbuf[strlen(lbuf)-1] = NULL;
		if (lbuf[0] == NULL)
			exit(1);
		q = splookup(lbuf, tree);
		if (q == NULL) {
			printf("Entry not found.\n");
			continue;
			}
		if (!lookup) {
			printf("Before deletion\n");
			ptree(tree);
			fflush(stdout);
			spdeq(q, tree);
			}
		}
}
new(str)
char	*str;
{
	SPBLK *q = (SPBLK *) chk_alloc(sizeof (SPBLK) + 32);
	char *s = (char *) (q + 1);
	strcpy(s, str);
	q->key = s;

	spenq(q, tree);
}
