From:	SMTP%"carl@SOL1.GPS.CALTECH.EDU"  6-JUN-1994 10:14:30.79
To:	EVERHART
CC:	
Subj:	Re: Is xxx.dir a directory ?

From: carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick)
X-Newsgroups: comp.os.vms
Subject: Re: Is xxx.dir a directory ?
Date: 2 Jun 1994 01:39:52 GMT
Organization: HST Wide Field/Planetary Camera
Lines: 95
Distribution: world
Message-Id: <2sjd98$s0k@gap.cco.caltech.edu>
Reply-To: carl@SOL1.GPS.CALTECH.EDU
Nntp-Posting-Host: sol1.gps.caltech.edu
To: Info-VAX@CRVAX.SRI.COM
X-Gateway-Source-Info: USENET

In article <2sj3u0$s0k@gap.cco.caltech.edu>, carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick) writes:
=The following program works even if the file has been
=opened by someone else for exclusive access.  I think I may finally have gotten
=the hang of using the ACP/QIO interface :-).  The strategy is:
=	1)  Use the RMS SYS$PARSE service to get the DID of the file and to
=	    parse the file name, type, and version;
=	2)  Use the IO$_ACCESS ACP function to retrieve the user
=	    characteristics field for the file;
=	3)  Check to see whether the directory characteristic bit is set.
=The program also serves as a simple demonstration of how to use the ACP/QIO
=interface.  I hope somebody finds it useful.

It was pointed out to me by Pat Rankin that the program I posted wouldn't work
properly with searchlists unless the file in question existed in the first
directory in the searchlist, and that using the RMS SYS$SEARCH function to get
the filename would overcome that problem.  So here's a somewhat more robust
version of the program.  Since I'm now using SYS$SEARCH, I get a valid FID for
the file before calling SYS$QIOW, so I no longer have to parse the file name,
type, and version for input as P5 in the call to SYS$QIOW:

#include fchdef
#include iodef
#include fibdef
#include ssdef
#include rms
#include descrip
#include atrdef
long stat;
#define ckstat(x) if(((stat = x) & 7) != 1) SYS$EXIT(stat)

main(int nargs, char **args)
{	struct FAB my_fab;
	struct NAM my_nam;
	struct fibdef my_fib;
	unsigned long uchar = 0,  i;
	char esa[255], rsa[255];
	struct
	{	unsigned long count, address; }
	fibdsc;
	$DESCRIPTOR(devnam, "");

	unsigned short chan, iosb[4];
	struct atrdef my_atr[] =
	{	{	ATR$S_UCHAR, ATR$C_UCHAR, &uchar },
		{	0, 0, 0 }
	};
	if (nargs != 2)
	{	puts("Usage:  isadir filename");
		SYS$EXIT(SS$_INSFARG);
	}
	my_fab = cc$rms_fab;
	my_fab.fab$l_fna = *++args;
	my_fab.fab$b_fns = strlen(*args);
	my_fab.fab$b_fac = 0;
	my_fab.fab$b_shr = FAB$M_UPI;
	my_fab.fab$l_nam = &my_nam;
	my_nam = cc$rms_nam;
	my_nam.nam$b_ess = 255;
	my_nam.nam$l_esa = esa;
	my_nam.nam$b_rss = 255;
	my_nam.nam$l_rsa = rsa;
	ckstat(SYS$PARSE(&my_fab));
	ckstat(SYS$SEARCH(&my_fab));
	devnam.dsc$w_length = my_nam.nam$t_dvi[0];
	devnam.dsc$a_pointer = my_nam.nam$t_dvi + 1;
	for(i = 0; i < sizeof(my_fib); ++i)
		*(((char *) &my_fib) + i) = 0;
	my_fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NOTRUNC |
		FIB$M_PRSRV_ATR | FIB$M_NOLOCK | FIB$M_NORECORD;
	for(i = 0; i < 3; ++i)
	{	my_fib.fib$r_fid_overlay.fib$w_fid[i] = my_nam.nam$w_fid[i];
		my_fib.fib$r_did_overlay.fib$w_did[i] = my_nam.nam$w_did[i];
	}
	my_fib.fib$r_nmctl_overlay.fib$w_nmctl = FIB$M_FINDFID;
	fibdsc.count = ((char *) &my_fib.fib$r_exctl_overlay) -
		((char *) &my_fib);
	fibdsc.address = &my_fib;
	ckstat(SYS$ASSIGN(&devnam, &chan, 0, 0));
	ckstat(SYS$QIOW(0, chan, IO$_ACCESS, iosb, 0, 0,
		&fibdsc, 0, 0, 0, &my_atr, 0));
	ckstat(iosb[0]);
	SYS$QIOW(0, chan, IO$_DEACCESS, iosb, 0, 0, &fibdsc, 0, 0, 0,
		&0, 0);
	if((uchar & FCH$M_DIRECTORY) == 0)
		SYS$EXIT(SS$_BADIRECTORY);
	SYS$EXIT(1);
}
--------------------------------------------------------------------------------
Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL

Disclaimer:  Hey, I understand VAXen and VMS.  That's what I get paid for.  My
understanding of astronomy is purely at the amateur level (or below).  So
unless what I'm saying is directly related to VAX/VMS, don't hold me or my
organization responsible for it.  If it IS related to VAX/VMS, you can try to
hold me responsible for it, but my organization had nothing to do with it.

