/*********************************************************************/
/* FSEL.C                                                            */
/*                                                                   */
/*    What follows next is the function for the file selector! The   */
/* specifier (line *.*), path, and default filename are passed,      */
/* and the function returns the fullname (path+filename), the  new   */
/* path selected, and the filename selected.                         */
/*********************************************************************/
#include <osbind.h>
#include <strings.h>

/****************/
/* ~select_file */
/*              ******************************************************/
/* Pass the wildcard (*.EXT), the path, and the default filename,    */
/* and this routine will get the file from the user and format it    */
/* into a full path/filename.ext!                                    */
/*********************************************************************/
select_file(wildcard, path, filename, fullname)
	char *wildcard, *path, *filename, *fullname;
{
	int		butn, x, len;
	char	tmp_path[80];
	
	if ( strlen(path) == 0 )
		current_path(path);
	strcpy(tmp_path, path);
	strcat(tmp_path, wildcard);
	fsel_input(tmp_path, filename, &butn);
	len = strlen(tmp_path);
	for (x = len; x >= 0; x--)
		if (tmp_path[x] == '\\' || tmp_path[x] == ':')
			break;
	if (x == -1) 
	{
		path[0] = 0;
		return(0);
	} else
	{
		tmp_path[x + 1] = 0;
		strcpy(path,tmp_path);
	}
	if ( !strlen(filename) )								/* no filename, cancel!		*/
		return(0);
	if (butn)																/* was ok selected?				*/
	{
		strcpy(fullname, tmp_path);
		strcat(fullname, filename);
		return(1);														/* return success					*/
	} else return(0);
}

/*****************/
/* ~current_path */
/*               *****************************************************/
/* Get the current path, and return it in the string passed by ptr.  */
/*********************************************************************/
current_path(returned_path)
	char *returned_path;
{
	int  cur_drv = Dgetdrv();

	returned_path[0] = cur_drv + 'A';
	returned_path[1] = ':';
	Dgetpath(&returned_path[2], 0);
	if (strlen(returned_path) > 3)
		strcat(returned_path, "\\");
	else
		returned_path[2] = '\0';
}
