#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <sgtty.h>

#define	TTY	"/dev/tty"	/* Change to /dev/tty for unix */

openfiles(argv,disk_file,disk_file2)

char *argv[];
FILE **disk_file,**disk_file2;

{
     *disk_file  = fopen(argv[1],"r+b");
     *disk_file2 = fopen(argv[2],"w+b");
     if (*disk_file == NULL) 
	   {
  	   printf("Error on opening file %s.\n",argv[1]);
	   exit(1);
	   }
     if (*disk_file2 == NULL) 
	   {
  	   printf("Error on opening file %s.\n",argv[2]);
	   exit(1);
	   }
}


char *getkey()
{
	struct sgttyb ttyb,ttysav;
	register char *cp,c;
	FILE *tty;
	static char pbuf[256];
	int (*signal())(),(*sig)();

	if ((tty = fdopen(open(TTY, 2), "r")) == NULL)
		tty = stdin;
	else
		setbuf(tty, (char *)NULL);
	sig = signal(SIGINT, SIG_IGN);
	ioctl(fileno(tty), TIOCGETP, &ttyb);
	ioctl(fileno(tty), TIOCGETP, &ttysav);
	ttyb.sg_flags |= RAW;
	ttyb.sg_flags &= ~ECHO;
	ioctl(fileno(tty), TIOCSETP, &ttyb);
	fflush(stdout);
	cp = pbuf;
	for (;;) {
		c = getc(tty);
		if(c == '\r' || c == '\n' || c == EOF)
			break;
		if (cp < &pbuf[127])
			*cp++ = c;
	}
	*cp = '\0';
	fprintf(stdout,"\r\n");
	fflush(stdout);
	ioctl(fileno(tty), TIOCSETP, &ttysav);
	signal(SIGINT, sig);
	if (tty != stdin)
		fclose(tty);
	return(pbuf);
}
