/*****************************************************************************
 *
 * FILE : interface.c - modul supporting user-program-UNIX communication
 *
 * programmer - Pawel Cholewinski, POT943, CS570
 *
 * date 09/23/92 , modified 04/16/93
 * modified 19 Apr 1999 by Neil Moore <neil@cs.uky.edu>
 * modified 20 Aug 1999 by Neil Moore <neil@cs.uky.edu>
 * modified  5 Sep 1999 by Neil Moore <neil@cs.uky.edu>
 *
 * Part of sderes.  See COPYRIGHT for copyright information.
 *
 *****************************************************************************/

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "proto.h"
#include "global.h"
#include "default.h"
#include "token.h"

void clearmemory(void);
/*
 * ========================================================================
 * loadtheory : load new input theory to working memory space of current
 *		context
 * ========================================================================
 */
int loadtheory(filename)
   char* filename;
{
	int success;
	char znak[MAXFILENAME];
	
	if (strlen(filename)+5 > MAXFILENAME) {
		if(verbosity > 0)
			fprintf(stderr,"filename too long\n");
		return -1;
	}
	strcpy(znak, filename);
	strcat(znak,".dt");
	finp = fopen(znak, "r");
	if (finp==NULL) {
		if(verbosity > 0)
			fprintf(stderr, "cannot open %s: %s\n", znak, strerror(errno));
		return -1;
	}
	clearmemory();
	success = getdata();
	SetProverStructures(w,conc,dttable,wno,dno,deffacts,dffno,&n_cppcalls,defatomlex);
	if (success!=1) {
		return -1;
		strcpy(znak,"  ");
	}
	strcpy(def_znak,znak);
	return 0;
}

   
/*
 * ========================================================================
 * clearmemory: clear working memory of current context
 * ========================================================================
 */
void clearmemory()
{
   int i;
   struct symbolbox *sbx, *delbx;

   wno = dno = wbegin = wend = dbegin = dend = -1;
   dffno = ff = 0;
   for (i = 0; i< MAXDSIZE; i++) ad[i] = 0;
   for (i = 0; i< 2*MAXDSIZE; i++) deffacts[i] = -1;
   for (i = 0; i< HASHSIZE; i++) {
      sbx = defhashtable[i];
      defhashtable[i] = NULL;
      while ((delbx = sbx) != NULL) {
         sbx = sbx->next;
         free((char*)(delbx->id));
         free((char*)delbx);
      }
   }
}

