/* ============ Path analysis ================= */
/* Not used with the XFS						*/
/* -------------------------------------------- */
int 	path_cat (int mode)
{
	char	path[MAX_PATH], *string, *fs;
	int		i;
	
	if(tmp_path[0] == '\\')
	{
		strcpy ( &path[2], tmp_path );
		path[0] = Ndrive;
		path[1] = ':';
	}
	else
		strcpy ( path, tmp_path );
	string = strrchr(path, '\\');
	if(string)
		*string = '\0';
	switch(mode)
	{
		case	1:
			string = strrchr (path, '\\');
			if(string)
				*string = 0L;
			i = strlen (path);
			strcat (path, "\\");
			path[i+1] = 0;
			break;
		case	2:
			i = strlen (path);
			strcat (path, "\\");
			path[i+1] = 0;
			break;
		case	3:
			i = strlen (path);
			strcat (path, "\\");
			path[i+1] = 0;
			strcat (path, PathStr);
			strcpy (PathStr, path);
			i = 0;	fs = PathStr;
			while ((fs = strchr (fs, '\\')) > NULL)
			{
				string = fs;
				fs++;
				if (++i == 3)
					break;
			}
			string --;
			if (i >= 3 && *string == 'X')
				return 3;
			else if (i <= 2)
			{
				#ifdef	DEBUG
			 		wmess (PathStr);
				#endif
				string = strrchr (PathStr, '\\');
				if (string && *(long *)(string+1) == '*.*\0')
				{
					if (i == 2)
			 			return 2;
			 		else
						return 1;
				}
				else
					return (0);
			}
			else
				return (0);
	}
	string  = strrchr (PathStr, '\\');
	if (string)
		strcat (path, &string[1]);
	else
		strcat (path, PathStr);
	strcpy (PathStr, path);
	return 3;
}

int 	lookup_host (char *name)
{
	int 	i = MAXHOSTS, len;
	
	while (--i)
	{
		len = strlen (host_arr[i].name);
		if (len && !strncmp (host_arr[i].name, name, len))
			return (i);
	}
	return (0);
}

int		val_path (void)
{
	char	*path = PathStr, *es, *fs, *ptr, *host;
	int 	i, rl;
	
	if (path[1] == ':')
	{
		es = strrchr (path, '\\');
		if (es)
		{
			strcpy (lext, es+1);
			
			fs = strchr (path, '\\');
			rl = es - fs;
			if (rl != 0)					/* we have more	*/
			{
				host = strchr (fs+1, '\\');
				if (host && host < es)		/* we have host	*/
				{
					ptr = strchr (host+1, '\\');
					if (ptr )	/* we have drive */
					{
						if ((cur_id = lookup_host (++fs)) > 0 && host [2] == 'X')
							return 3;
						else
							return 0;
					}
					else
						return (0);
				}
				else
				{
					if ((cur_id = lookup_host (&path[3])) > 0)
					return (2);
				}
			}
			else
			{
				if (*path == Ndrive)
					return (1);
				else
					return(0);
			}
		}
	}
	else
	{
		switch (path[0])
		{
			case '.':
				if (path[1] == '.')
					return (path_cat (1));
				if (path[1] == '\\')
					return (path_cat (2));
			case '\\':
				return (path_cat (3));
			case '*':
				if (path[1] == '.')
					return (path_cat (3));
			default:
				return (0);
		}
	}
	return 0;
}
/*	----------------------------------------------------
 * End of functions not needed for XFS
 ---------------------------------------------------- */
