#include <errors.h>
#include <graph.h>
#include <iostream.h>
#include <process.h>
#include <strings.h>
#include <zstrings.h>
#include <unix.h>
#include <signal.h>
#include <time.h>

void erase(void)
{
	/* Nothing to do */
	return;
}

void draw(void)
{
	setcolor(0xaaaa);

	/* Draw square to virtual screen */
	line(50, 50, 100, 150);

	/* Update physical screen */
	doupdate();
}

int main(void)
{
	int pid;
	struct timespec ts;
	struct window *win;

	pid = fork();

	/* Spawn a watchdog incase a segmentation fault occurs */
	if (pid < 0) {
		putz(2, "fork: ");
		put_line(2, strerror(-pid));
		return 1;
	}
	if (pid > 0) {
		waitpid(pid, NULL, 0);
		closegraph();
		return 0;
	}

	ts.tv_sec = 3;
	ts.tv_nsec = 0;

	if (initgraph(NULL) != 0)
		return 1;
	win = initwindow(1);
	if (win == NULL)
		return 1;
	setcurrentwindow(win);
	draw();
	nanosleep(&ts, NULL);
	closewindow(win);
	return 0;
}
