#include "stdio.h"
#include "exec/types.h"
#include "libraries/dosextens.h"

#define	AS_DEVICE	0
#define	AS_DIR		1
#define	AS_DRIVE	2
#define	AS_UNKNOWN	3

int	Assigned(searchname)
char	*searchname;
{
	struct	DosLibrary	*DosLibrary;
	struct	RootNode	*RootNode;
	struct	DosInfo		*DosInfo;
	struct	DeviceList	*DevInfo;
	char	name[256];
	char	*astr;
	BSTR	bstr;
	long	type;
	int	i,rc;

	DosLibrary = (struct DosLibrary *)OpenLibrary("dos.library",0);
	RootNode = (struct RootNode *)DosLibrary->dl_Root;
	DosInfo = (struct DosInfo *)BADDR(RootNode->rn_Info);
	DevInfo = (struct DeviceList *)BADDR(DosInfo->di_DevInfo);

	rc = AS_UNKNOWN;
	while (DevInfo != NULL) {
		type = DevInfo->dl_Type;
		bstr = (BSTR)DevInfo->dl_Name;
		astr = (char *)BADDR(bstr);
		for (i = 0; i < astr[0]; i++)
			name[i] = astr[i+1];
		name[i] = '\0';
		if (strcmp(name,searchname) == 0) {
			rc = type;
			DevInfo = NULL;
		}
		else
			DevInfo = (struct DeviceList *)BADDR(DevInfo->dl_Next);
	}
	CloseLibrary(DosLibrary);
	return(rc);
}

main()
{
	char	cmd[80];

	printf("*** This program is Case Sensitive! ***\n");
	printf("*** Do not append a colon: to the searchname ***\n\n");

	for (;;) {
		printf("Enter search name or QUIT: ");
		scanf("%s",cmd);
		if (strcmp(cmd,"QUIT") == 0)
			return(0);
		switch ( Assigned(cmd) ) {
			case AS_DEVICE:
				printf("%s is a device\n",cmd);
				break;
			case AS_DIR:
				printf("%s is an assigned directory\n",cmd);
				break;
			case AS_DRIVE:
				printf("%s is a mounted drive\n",cmd);
				break;
			case AS_UNKNOWN:
				printf("%s is unknown\n",cmd);
				break;
			default:
				printf("%s is not defined???\n",cmd);
				break;
		}
	}
}


