#include <stdio.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include "moviedb.h"
#include "aka.h"
#include "titlelist.h"

/* allocate a new record */

TitleRec* newTitleRec(void) {
	TitleRec *trec;

	if ((trec = (TitleRec *) malloc(sizeof(TitleRec))) == NULL)
		XtError("out of memory");
	trec->title=NULL;
	trec->aname=NULL;
	trec->cname=NULL;
	trec->next=NULL;
	trec->aka=NULL;

	return trec;
	}



/* free list of titles */

void freeTitles(TitleRec *trec) {
	TitleRec *next;
	struct akaRec *aprev, *arec;

	while (trec != NULL) {
		next = trec->next;
		free(trec->title);
		free(trec->aname);
		free(trec->cname);

		/* free akas */
		aprev = NULL;
		for (arec=trec->aka; arec!=NULL; arec=arec->next) {
			free ((void*) aprev);
			free ((void*) arec->akaTitle);
			}

		free(trec);
		trec=next;
		}
	}


