[go: up one dir, main page]

Menu

[897c37]: / mlib / lib / filename.lpc  Maximize  Restore  History

Download this file

82 lines (71 with data), 1.5 kB

inherit "RO/Servers";

array Wizards;

reset(arg)
{
array temp;
int i;
	if (!arg)
	{
	/* work out the list of wizards */
		Wizards = [ ];	
		temp = "std/wiz_list"->query_wiz_list();
		for (i = 0; i < sizeof(temp); i ++)		
			if (stringp(temp[i]))
				Wizards += [ capitalize(temp[i]) ];
	}
}

query_wizards() { return Wizards; }

string
find_wizard(string wiz)
{
int i;
	if (capitalize(wiz) != wiz)
		return wiz;
	i = 0;
	while (i  < sizeof(Wizards) )
	{
		if (wiz == Wizards[i][..sizeof(wiz)-1])
			return (lower_case(Wizards[i]));
		i ++;
	}
	return wiz;
}

string contract(string filename)
{
	if (filename[0..7] == "players/")
		return "~"+filename[8..];
	return filename;
}

string compute_path(str,pwd)
{
array exploded, stack = [ ];
int i;

    if (!stringp(str)) 
	return pwd [..sizeof(pwd)-2]; /* Strip of the last slash */
    str = STRINGS-> strip_whitespace(str);
	if (str[0] != '/' && str[0] != '~') str = pwd + str;

    exploded = explode(str, "/");
    if (!pointerp(exploded)) return "";

    for (i=0;i < sizeof(exploded);i++) 
    {
	if (exploded[i] == ".." && sizeof(stack) > 0)  
	{
	    stack = stack[..sizeof(stack)-2];
	}
	else if (exploded[i] == "~") 
	{
	    throw "You cant use a ~ in your path, you dont have a home directory.\n";
	    return 0;
	}
	else if (exploded[i][..0] == "~") 
	{
	    stack = ["players", exploded[i][1..] ] ;
	}
	else if (exploded[i] != ".") 
  	{
	    stack += [ exploded[i] ];
	}
    }
    if (!sizeof(stack)) return ""; 
    return implode(stack, "/");
}