Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!rochester!cornell!batcomputer!hsgj From: hsgj@batcomputer.UUCP Newsgroups: comp.sys.amiga Subject: ASSIGN: solution Message-ID: <131@batcomputer.tn.cornell.edu> Date: Sat, 7-Feb-87 19:16:50 EST Article-I.D.: batcompu.131 Posted: Sat Feb 7 19:16:50 1987 Date-Received: Mon, 9-Feb-87 02:07:42 EST Organization: Theory Center, Cornell U., Ithaca NY Lines: 107 Keywords: ASSIGN, Avoiding DOS Insert-Disk Requester If you remember, I had a problem where I needed to know whether a name was ASSIGNed before I used it. Mike Meyer suggested checking the data structure Assign uses. Following this advice, I was able to do just what I wanted. Anyways, since the solution was prompted by a net suggestion, I thought I'd share it: Included is Assigned() and a test program main(). The way to use this from a program is like this: ... if (Assigned("HELP") != AS_UNKNOWN) /* Read help file from the help disk or directory */ show_help_file("HELP:helpfile"); else /* Read help file from the current directory */ show_help_file("helpfile"); ... The sample main() just lets you test it from the keyboard. Note that it is highly case-sensitive. In other words, df0 is unknown, but DF0 is a drive. Note also that you should NOT add a colon: to the name to be searched. -- Dan Green (ps: beware of .signature at eof) ------------------------------ cut here ------------------------- #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; } } } ------------------------------ cut here ------------------------- -- Dan Green -- ARPA: hsgj%vax2.ccs.cornell.edu@cu-arpa.cs.cornell.edu UUCP: ihnp4!cornell!batcomputer!hsgj BITNET: hsgj@cornella