/******************************************************************************

	ZSWild()

	This function searches for the next wildcard file specification.  It
is called when the user executes an "EN$" or ":EN$" command.  If the user
executes an "ENfilename$" command,  the ZPWild function is called,  not this
function.

	This function returns

		1. SUCCESS if the filespec buffer has a new file name
		2. FAILURE if the search failed somehow other than FILENF
		3. FILENF if no more occurrences of the wildcard exist

*****************************************************************************/

#include "ZPort.h"		/* define portability identifiers */
#include "DefTeco.h"		/* define general identifiers */
#include "DefError.h"		/* define identifiers for error messages */




#ifdef UNKNOWN
DEFAULT ZSWild()			/* search for next wildcard filespec */
{
	puts("Terminating in function ZSWild.\n");
	exit(1);
}
#endif




#ifdef vax11c
#include nam		/* define RMS name block structures */
#include fab		/* define RMS file access block structures */
#include rmsdef		/* define RMS return status identifiers */
#include ssdef		/* define system service return identifiers */
#include "DefChars.h"	/* define identifiers for characters */

VOID	lib$stop();	/* terminate image with stack dump */
int	sys$putmsg();	/* VAX/VMS "put message" system service */
int	sys$search();	/* RMS SEARCH service */
VOID	ZDspCh();	/* display a character on the terminal */

EXTERN	struct	message_vector msgvec;
EXTERN	struct	NAM WNam;	/* wildcard file RMS name block */
EXTERN	struct	FAB WFab;	/* wildcard RMS file access block */
EXTERN	char	FBfBeg[];	/* beginning of file specification buffer */
EXTERN	char	*FBfPtr;	/* pointer into file specification buffer */


DEFAULT ZSWild()			/* search for next wildcard filespec */
{
	int	status;

#if DEBUGGING
DbgInd+=2;if(DbgLvl>=1){DbgMsg();DbgDBf("ZSWild: called.\015\012");DbgROf();}
#endif

	status = sys$search(&WFab);		/* search for file */
	if ((status == RMS$_FNF) ||		/* if file not found or */
	    (status == RMS$_NMF))		/* no more files */
#if DEBUGGING
{if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZSWild: returning FILENF.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FILENF);
#if DEBUGGING
}
#endif
	if (status != RMS$_NORMAL)
		{
		msgvec.msgcod = status;
		msgvec.rmsstv = WFab.fab$l_stv;
		status = sys$putmsg(	&msgvec,/* message vector */
					0,	/* action routine */
					0);	/* facility name */
		if (status != SS$_NORMAL)
			lib$stop(status);
		ZDspCh(LINEFD);
#if DEBUGGING
if(DbgLvl>=1)
{DbgMsg();DbgDBf("ZSWild: returning FAILURE.\015\012");DbgROf();}DbgInd-=2;
#endif
		return(FAILURE);
		}

	FBfPtr = FBfBeg + WNam.nam$b_rsl;	/* resultant name length */
#if DEBUGGING
if(DbgLvl>=1){DbgMsg();DbgDBf("ZSWild: returning SUCCESS, FBf = \"");
TypBuf(FBfBeg,FBfPtr);DbgDBf("\"\015\012");DbgROf();}DbgInd-=2;
#endif
	return(SUCCESS);
}
#endif



#ifdef XENIX
DEFAULT ZSWild()			/* search for next wildcard filespec */
{
	return(ExeNYI());
}
#endif
