From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 23-JUN-1989 14:52
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: parsing file specifications

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Thu, 22 JUN 89 10:16:05 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Thu, 22 Jun 89 10:16:04 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.37)
	id AA01104; Thu, 22 Jun 89 10:02:34 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 22 Jun 89 13:31:26 GMT
From: ecsvax!uncw!session@mcnc.org  (Zack Sessions)
Organization: Math/Computer Science Department
Subject: Re: parsing file specifications
Message-Id: <417@uncw.UUCP>
References: <614@cullsj.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <614@cullsj.UUCP> brad@cullsj.UUCP (Brad Might) writes:
>
>	Is there a system service, rms function, or lib$ function equivalent
>to the lexical f$parse to break a file spec into its components ?
>

As promised here is a VAX C program which illustrates the $filescan system
service. First is the fscndef.h file. I have mine in SYS$LIBRARY. If you're
not the System Manager, leave it in your default directory and change the

#include <fscndef.h>

to

#include "fscndef.h"

---------fscndef.h--------

/*
	fscndef.h

	author	Zack Sessions
*/

#define	FSCN$M_NODE	1
#define	FSCN$M_DEVICE	2
#define	FSCN$M_ROOT	4
#define	FSCN$M_DIRECTORY	8
#define	FSCN$M_NAME	16
#define	FSCN$M_TYPE	32
#define	FSCN$M_VERSION	64
#define	FSCN$S_FLDFLAGS	1
#define	FSCN$V_NODE	0
#define	FSCN$V_DEVICE	1
#define	FSCN$V_ROOT	2
#define	FSCN$V_DIRECTORY	3
#define	FSCN$V_NAME	4
#define	FSCN$V_TYPE	5
#define	FSCN$V_VERSION	6
#define	FSCN$_FILESPEC	1
#define	FSCN$_NODE	2
#define	FSCN$_DEVICE	3
#define	FSCN$_ROOT	4
#define	FSCN$_DIRECTORY	5
#define	FSCN$_NAME	6
#define	FSCN$_TYPE	7
#define	FSCN$_VERSION	8             
#define	FSCN$S_ITEM_LEN	8
#define	FSCN$S_FSCNDEF	8
#define	FSCN$W_LENGTH	0
#define	FSCN$W_ITEM_CODE	2
#define	FSCN$L_ADDR	4

--------filescan.c--------
{
#include <stdio.h>
#include <ssdef.h>
#include <descrip.h>
#include <fscndef.h>

struct fscn_def {
	struct fscn_elem {
		short		fs_len;
		short		fs_code;
		char		*fs_name;
	} fscn[8];
	int	end_list;
} fscnlist;

 char	descr[8][15] = {"",
			"Node Name",
			"Device Name",
			"Root Directory",
			"Directory Name",
			"File Name",
			"File Type",
			"Version Number"
	};

main()
{
	int	i;
	long	fscn_ret;
	char	source[255];
	char	dest[255];
	struct dsc$descriptor_s d_source;
	strcpy(source,"HYDRA::HSC000$DUA0:[SYS0.SYSCOMMON.][SYSEXE]EDT.EXE;12");
	d_source.dsc$w_length = strlen(source);
	d_source.dsc$b_dtype = DSC$K_DTYPE_T;
	d_source.dsc$b_class = DSC$K_CLASS_S;
	d_source.dsc$a_pointer = source;

	fscnlist.end_list = 0;
	fscnlist.fscn[0].fs_code = FSCN$_FILESPEC;
	fscnlist.fscn[1].fs_code = FSCN$_NODE;
	fscnlist.fscn[2].fs_code = FSCN$_DEVICE;
	fscnlist.fscn[3].fs_code = FSCN$_ROOT;
	fscnlist.fscn[4].fs_code = FSCN$_DIRECTORY;
	fscnlist.fscn[5].fs_code = FSCN$_NAME;
	fscnlist.fscn[6].fs_code = FSCN$_TYPE;
	fscnlist.fscn[7].fs_code = FSCN$_VERSION;

	fscn_ret = sys$filescan (&d_source,&fscnlist,0);
	if(fscn_ret!=SS$_NORMAL)
		sys$exit(fscn_ret);
	for(i=1; i<9; ++i)
		if (fscnlist.fscn[i].fs_len>0) {
			strncpy(dest,fscnlist.fscn[i].fs_name,fscnlist.fscn[i].fs_len);
			dest[fscnlist.fscn[i].fs_len] = '\0';
			printf("%s is %s\n",descr[i],dest);
		}
}


Zack Sessions                          | Utilizing the computing facilities
General Electric                       | at the University of North Carolina 
Nuclear Fuels & Component Manufacturing| at Wilmington 
Wilmington, NC                         |

"If it ain't broke, then don't fix it!"

