#include <sys/local.h>
#include <sys/param.h>
#include <sys/ino.h>
#include <sys/inode.h>
#include <sys/filsys.h>
#include "saio.h"
#include "dfltboot.h"

char line[100];
extern int verbose;
int copy = 1;

int *
main(bootaddr)
int *bootaddr;
{
	register int i;
	register int *top;
	extern char last[];

	for (;;) {
#ifdef UCB_NKB
		printf(last);
#else  UCB_NKB
		printf("\nBoot\n");
#endif UCB_NKB
		for (;;) {
			printf(": ");
			gets(line);
			if (line[0] == '\0') {
				strcpy (line, bootdev);
				strcat (line, unixname);
				printf ("%s\n", line);
			}
			else if (index (line, '(') == NULL) {
				char svline[100];
				strcpy (svline, line);
				strcpy (line, bootdev);
				strcat (line, svline);
				printf ("%s\n", line);
			}
			if (line[0] == '!')
				docmds ();
			else if ((i = open(line,0)) >= 0)
				break;
		}
		vprint ("copy ", line, 0);
		if (copy && (top = copyunix(i, bootaddr)) != 0)
			return(top);
		close(i);
	}
}

docmds ()
{
	for (;;) {
		printf("@ ");
		gets(line);
		if (!strcmp ("exit", line))
			break;
		else if (!strcmp ("copy", line))
			copy = 1;
		else if (!strcmp ("nocopy", line))
			copy = 0;
		else if (!strcmp ("verbose", line))
			verbose = 1;
		else if (!strcmp ("noverbose", line))
			verbose = 0;
		else if (!strcmp ("set", line)) {
			printf ("verbose: %s\ncopy: %s\n",
				verbose ? "YES" : "NO",
				copy ? "YES" : "NO");
		}
		else
			printf ("choices are:\n\
exit - back to normal boot\n\
nocopy - don't copy unix\n\
copy - copy unix (default)\n\
verbose\n\
noverbose - (default)\n\
");
	}
	return;
}
