shithub: pprolog

ref: 85adea62d7e8eee9d0e3525d572325db4e58d21a
dir: /main.c/

View raw version
#include <u.h>
#include <libc.h>

#include "dat.h"
#include "fns.h"

void usage(void);

void
main(int argc, char *argv[])
{
	char *parsetestfile = nil;

	ARGBEGIN{
	case 'd':
		debug = 1;
		break;
	case 'f':
		parsetestfile = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND

	if(argc != 0)
		usage();

	int fd = open("./stdlib.pl", OREAD);
	if(fd < 0){
		print("Can't open ./stdlib.pl\n");
		exits("open");
	}
	Term *database = parse(fd, 0);
	close(fd);

	if(parsetestfile){
		int fd = open(parsetestfile, OREAD);
		if(fd < 0)
			exits("open");
		Term *clauses = parse(fd, 0);
		database = appendterm(database, clauses);

		Term *goal;
		for(goal = initgoals; goal != nil; goal = goal->next){
			Binding *bindings = nil;
			Choicepoint *choicestack = nil;
			evalquery(database, goal, &bindings, &choicestack);
		}
	}

	repl(database);

	exits(nil);
}

void
usage(void)
{
	fprint(2, "Usage: pprolog [-d]\n");
	exits("Usage");
}