shithub: pprolog

ref: d5ce41f05bc322fa2fb4d0eee66080b3b3004853
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();

	if(parsetestfile){
		int fd = open(parsetestfile, OREAD);
		if(fd < 0)
			exits("open");
		Term *prog = parse(fd);
		Term *clause;
		for(clause = prog; clause != nil; clause = clause->next)
			print("%S.\n", prettyprint(clause));

		Term *goal;
		for(goal = initgoals; goal != nil; goal = goal->next)
			evalquery(prog, goal);
	}

	exits(nil);
}

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