/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * Assignment: 3
 * File: main.c
 * Author: Ray Ortigas (rayo@dgp.toronto.edu)
 * Contains: Small program demonstrating functionality of A3 code.
 */

#include <stdio.h>
#include "dictionary.h"

void recDictionaryPrint(const BSTNodePtr x) {
	if (x != NULL) {
		recDictionaryPrint(x->left);
		{
			int i = 0;
			StringPtr word = (StringPtr)(x->key);
			ListPtr definitions = (ListPtr)(x->value);
			printf("%s\n", stringToCString(word));
			for (i = 0; i != listSize(definitions); i++) {
				printf("\t%s\n", stringToCString((StringPtr)listGet(definitions, i)));
			}
		}
		recDictionaryPrint(x->right);
	}
}

void dictionaryPrint(const DictionaryPtr d) {
	recDictionaryPrint(d->entries->root);
}
					 
int main(void) {
	DictionaryPtr d = dictionaryInit();

	{
		dictionaryPut(d, stringInit("verisimilitude"),
			stringInit("the quality or state of being verisimilar"));
		dictionaryPut(d, stringInit("mellifluous"), 
			stringInit("having a smooth, rich flow"));
		dictionaryPut(d, stringInit("sack"), 
			stringInit("a usually rectangular-shaped bag"));
		dictionaryPut(d, stringInit("sack"), 
			stringInit("to dismiss especially summarily"));
		dictionaryPut(d, stringInit("clandestine"), 
			stringInit("marked by, held in, or conducted with secrecy"));
		dictionaryPut(d, stringInit("infinitesimal"), 
			stringInit("taking on values arbitrarily close to but greater than zero"));
		dictionaryPut(d, stringInit("infinitesimal"), 
			stringInit("immeasurably or incalculably small"));
		dictionaryPut(d, stringInit("jabberwocky"),
			stringInit("meaningless speech or writing"));
		dictionaryPut(d, stringInit("quizzical"), 
			stringInit("comically quaint"));
		dictionaryPut(d, stringInit("quizzical"), 
			stringInit("mildly teasing or mocking"));
		dictionaryPut(d, stringInit("quizzical"), 
			stringInit("expressive of puzzlement, curiosity, or disbelief"));
	}

	{
		dictionaryPrint(d);
		printf("--\n");
	}

	{
		ListPtr definitions = dictionaryGetDefinitions(d, stringInit("quizzical"));
		printf("quizzical\n");
		if (definitions != NULL) {
			int i;
			for (i = 0; i != listSize(definitions); i++) {
				printf("\t%s\n", stringToCString((StringPtr)listGet(definitions, i)));
			}
		}
		else {
			printf("\tno definitions!\n");
		}
	}

	{
		ListPtr definitions = dictionaryGetDefinitions(d, stringInit("guppy"));
		printf("guppy\n");
		if (definitions != NULL) {
			int i;
			for (i = 0; i != listSize(definitions); i++) {
				printf("\t%s\n", stringToCString((StringPtr)listGet(definitions, i)));
			}
		}
		else {
			printf("\tno definitions!\n");
		}
	}

	return 0;
}
