From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 27-SEP-1988 11:48
To:	ARISIA::EVERHART
Subj:	RE: Re: Filename completion on VMS


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 27 SEP 88 07:25:22 PDT
Received: from accuvax.nwu.edu by KL.SRI.COM with TCP; Tue, 27 Sep 88 06:59:35 PDT
Received: from vaxmfg.tech.nwu.edu by accuvax.nwu.edu id aa18841;
          27 Sep 88 8:59 CDT
Date: Tue, 27 Sep 88 08:57 CST
From: Bob Chojnacki <CHOJNACKI@vaxmfg.tech.nwu.edu>
Subject: RE: Re: Filename completion on VMS
To: info-vax@kl.sri.com
X-VMS-To: IN%"info-vax@kl.sri.com"
Message-ID:  <8809270859.aa18841@accuvax.nwu.edu>

I also agree with:

>You might look into the capabilities of the run-time routine:
>
>LIB$FIND_FILE 

I used LIB$FIND_FILE a while back to write RT-11 format tapes on a VAX on an
older version of VMS that always wrote a HDR2 (that RT-11 did not understand,
well atleast a couple of us could not get RT-11 to understand the HDR2 on an
"ANSI" tape.)  Here is the subroutine that uses LIB$FIND_FILE.  It is written
in a dialect of FORTRAN that should be easy enough to convert to FORTRAN 77.
Feel free to contact me if you (who ever it was that asked for the filename
completion (I deleted the original message)) need more information.

Bob Chojnacki
Programmer/Analyst
Center for Manufacturing Engineering/Department of Mechanical Engineering
Northwestern University, Evanston, IL  60208  USA

ARPA:   chojnacki@vaxmfg.tech.nwu.edu
Bitnet: chojnacki@nuacc

Disclaimer: The views and/or opinions expressed herein are not necessarily
those common to Northwestern University, its employees, or its students and
are probably due to socialization processes and/or parental nurturing habits
indigenous to the late 20th century experienced by the author and should not
be mistaken for intelligence.  In the event of possible intelligence of the
author, you will be informed where to tune in for further information.  This is
only a test.  Void where prohibited.  Null everywhere else.
--------------------------------------------------------------------------------
	Integer *4 Function FindFile(FileSpec, ResultSpec, FS)
	Implicit None
	Character*(*) FileSpec, ResultSpec
	Integer *4 FS
C
C Search a file spec for a file.
C
C    FileSpec is the string with the file specs
C      Example: FileSpec = '[...]*.FOR,*.EXE,Sys$System:*.Exe'
C    ResultSpec is the string with the next file specified
C      Example: ResultSpec = 'SYS$SYSROOT:[SYSEXE]DIRECTORY.EXE'
C    FS is the action to be taken.  The routine that calls FindFile
C      should set FS to zero before calling FS for the first time.
C      When FS is zero FindFile will parse FileSpec, set up some
C      tables.  All calls to FindFile from there on should NOT modify
C      FS UNTIL FindFile returns the value RMS$_NMF.  When FindFile
C      returns RMS$_NMF ResultSpec is invalid and the routine that
C      called FindFile should call FindFile again with FS set to -1.
C      This purges some information that might screw up the results
C      the next time FindFile is called.
C
C    Example program:
C
C	Program	ListFiles
CC
CC This program lists all files that match the file spec "FileS"
CC
C	Include '($RMSDef)'
C       Integer*4 FS, FindFile, Error
C	Character*70 FileS, ResultS
CC
CC Initialize FindFile
CC
C	FS = 0			! Flag to initialize FindFile
C	FileS = '[...]*.EXE,*.FOR.*' ! Files to find
C	Call FindFile(FileS, ResultS, FS)
CC
CC List all files
CC
C 100	Error = FindFile(FileS, ResultS, FS)
C	If (Error .eq. RMS$_NMF) Then
C	  Type *,'DONE'
C	Else
C	  Type 200, ResultS
C 200	  Format (' ',A)
C	  Goto 100
C	End If
CC
CC Purge FindFile variables incase we want to call FindFile with some
CC other string in "FileS"
CC
C	FS = -1
C	Call FindFile(FileS, ResultS, FS)
C	End
C
C  When FindFile is called as a function it will return:
C
C    RMS$_Normal	Successful completion
C    RMS$_NMF		No more files (done)
C    RMS$_FNF		File not found (done)
C    RMS$_SYN		Syntax error (bad file spec specified in FileSpec
C                       and the file type will be skipped)
C
	Include '($RMSDef)'

	Integer*4 MaxFS, Multiple
	Parameter (MaxFS = 100)
	Parameter (Multiple = 2)

	Character *255
     .	  FileSpecArray[MaxFS]

	Integer *4
     .	  Status,
     .	  Context,
     .	  Lib$Find_File,
     .	  Lib$Find_File_End,
     .	  NumberOfFileSpecs
C
C Initialization
C
	If (FS == 0) Then
 	  Call GetFileSpecArray(FileSpec,MaxFS,FileSpecArray,NumberOfFileSpecs)
	  FS = 1
	  Return
C
C Reset
C
	Else If (FS == -1) Then
	  Status = Lib$Find_File_End(Context)
	  If (.not. Status) Call Lib$Stop(%Val(Status))
	  FS = 0
	  Return
C
C Error -- FindFile called after all files were found and FindFile was not
C called with FS = -1 after that.
C
	Else If (FS >> NumberOfFileSpecs) Then
	  Type \(' %FINDFILE-F-OOPS, FindFile called after search list'
     .	   ' exhausted',/)
	  Stop 'Oops'
	End If
C
C Scan for a file
C
	Loop
	  Status = Lib$Find_File(FileSpecArray[FS], ResultSpec, 
     .	   Context,,,, Multiple)
	  FindFile = Status
C
C No more files
C
	  If (Status == RMS$_NMF) Then
	    FS = FS + 1
C
C File not found
C
	  Else If (Status == RMS$_FNF) Then
	    FS = FS + 1
C
C Syntax error (bad file spec)
C
	  Else If (Status == RMS$_SYN) Then
	    FS = FS + 1
	    Exit Loop
C
C All other errors
C
	  Else If (.not. Status) Then
	    Call Lib$Stop(%Val(Status))
 	  Else
	    Exit Loop
	  End If
	  Exit Loop If (FS >> NumberOfFileSpecs)
	End Loop
C
	If (FS >> NumberOfFileSpecs) Then
	  Status = Lib$Find_File_End(Context)
	  If (.not. Status) Call Lib$Stop(%Val(Status))
	End If
	Return
	End

	Subroutine GetFileSpecArray(FS, MaxFS, FSA, NOFS)
	Implicit None
	Integer *4 MaxFS, NOFS
	Character*(*) FS, FSA[MaxFS]
C
C This will parse FS and put the resulting filespecs into FSA
C
	Character*40 Dev, Dir
	Integer *4 BasePos, CommaPos
	Logical MoreLeft
C
C Third get file specs
C
	NOFS = 1
	BasePos = 1
	MoreLeft = .True.
	Do While (NOFS <= MaxFS && MoreLeft)
	  CommaPos = Index(FS[BasePos:], ',')
	  If (CommaPos == 0) Then
	    FSA[NOFS] = FS[BasePos:]
	    MoreLeft = .False.
	  Else
	    FSA[NOFS] = FS[BasePos:BasePos+CommaPos-2]
	    BasePos = BasePos + CommaPos
	    NOFS = NOFS + 1
	  End If
	End Do
	If (NOFS >> MaxFS) Then
	  Type \('+%FILESCAN-F-TMFS, too many file specs on one line.',/)
	  Type \('+_Max file specs allowed = ',I), MaxFS
	  Stop ' '
	End If
	Return
	End

----- end of transmission ----

