#include <stdio.h>
#include <string.h>
#include <pwd.h>

#ifdef	MSDOS

#include <dos.h>
#include "vn.h"

#define K_F1	+59
#define K_F2	+60
#define K_F3	+61
#define K_F4	+62
#define K_F5	+63
#define K_F6	+64
#define K_F7	+65
#define K_F8	+66
#define K_F9	+67
#define K_F10	+68
#define K_SF1	+84
#define K_SF2	+85
#define K_SF3	+86
#define K_SF4	+87
#define K_SF5	+88
#define K_SF6	+89
#define K_SF7	+90
#define K_SF8	+91
#define K_SF9	+92
#define K_SF10	+93
#define K_CF1	+94
#define K_CF2	+95
#define K_CF3	+96
#define K_CF4	+97
#define K_CF5	+98
#define K_CF6	+99
#define K_CF7	+100
#define K_CF8	+101
#define K_CF9	+102
#define K_CF10	+103
#define K_AF1	+104
#define K_AF2	+105
#define K_AF3	+106
#define K_AF4	+107
#define K_AF5	+108
#define K_AF6	+109
#define K_AF7	+110
#define K_AF8	+111
#define K_AF9	+112
#define K_AF10	+113
#define K_LEFT	+75
#define K_RIGHT	+77
#define K_UP	+72
#define K_DOWN	+80
#define K_PGUP	+73
#define K_PGDN	+81
#define K_HOME	+71
#define K_END	+79
#define K_CPGUP	+132
#define K_CPGDN	+118
#define K_CHOME	+119
#define K_CEND	+117
#define K_CLEFT	+115
#define K_CRIGHT +116
#define K_INS	+82
#define K_DEL	+83

struct passwd *
getpwuid (uid)
int	uid;
{
	static struct passwd passwd;

	passwd.pw_dir = "f:\\home";
	passwd.pw_name = "User";

	return (&passwd);
}

struct passwd *
getpwnam (name)
char	*name;
{
	static struct passwd passwd;
	static char	pw_name[20];

	passwd.pw_dir = "f:\\home";
	passwd.pw_name = pw_name;
	strncpy (pw_name, name, sizeof (pw_name));

	return (&passwd);
}

int
getuid ()
{
	return (0);
}

int
link (from, to)
char	*from, *to;
{
	char	command[128];

	strcpy (command, "copy ");
	strcat (command, from);
	strcat (command, " ");
	strcat (command, to);
	strcat (command, " >nul \n");

	return (system (command));
}

int
getraw ()
{
	int	c;

	while (!(c = getch ()))	{	/* no funnies... */
		switch (c = getch ()) {
		case K_UP:
			c = UP;
			break;
		case K_DOWN:
			c = DOWN;
			break;
		case K_PGDN:
			c = FORWARD;
			break;
		case K_PGUP:
			c = BACK;
			break;
		default:
			continue;	/* ignore */
		}
		break;
	}
	return (c);
}

#undef	chdir

static char abc[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int
doschdir (dir)
char	*dir;
{
	int	a, b;
	char	*p;

	if (dir[1] == ':') {
		if ((p = index (abc, toupper (dir[0]))) == NULL ||
		    *p == '\0')
			return (1);
		a = p - abc;
		_dos_setdrive (a, &b);
		_dos_getdrive (&b);
		if (a != b)
			return (1);
		dir += 2;
	}
	return (chdir (dir));
}

#endif
