[DGD] kernel lib wiztool->expand()

Shevek shevek at btinternet.com
Sat Dec 15 02:13:13 CET 2001


Here's some background.
I have this copy of the kernel lib wiztool in ~/System/obj. It acts exactly 
the same as the usual kernel lib wiztool (Inheriting LIB_WIZTOOL). However 
I altered it to inherit MY_WIZTOOL as well. This is handy because I can use 
all the LIB_WIZTOOL functions when making my own wiz commands.

Ok, now the problem.
What does expand() return, and am I even using it right? I know for a fact 
it expands a filename into a full path, but I see that it can also do some 
access checking. Here's the code I'm using right now, it does exactly what 
it's meant to, but seems a little clunky. What I'd like is to know what 
expand() returns when it finds bad access or no file to reduce this a little.

static void cmd_more(object user, string cmd, string str){
	string file;
     mixed *info;

     info = expand(str, 0, TRUE);
     if (info[4] == 1) {
	if (sizeof(info[0]) == 1) {
	    str = info[0][0];
	    info = file_info(str);
	    if (!info) {
		message(str + ": No such file or directory.\n");
		return;
	    } else if (info[0] < 0) {
		message(str + ": Is a directory\n");
		return;
	    } else {
		if (!access(owner, str, READ_ACCESS)) {
			message(str + ": Access denied.\n");
			return;
		}
		message("Reading: " + str + "\n");
	    }
	}
     } else {
	message("Usage: " + cmd + " <directory>\n");
	return;
     }

[...] Some 'more' code [...]
}

It all works so this isn't a major deal, but if anyone's got any idea how 
to reduce it then I'd really appreciate the advice.

Couple of minor questions to go along with that.
1) What is Ecru? I know it's a user, but why?
2) What's a decent way of adding a specific character from one string into 
another without first throwing it into another string.
Eg str1="wibble"
      str2="niblick"
      str1=str2[0] gives str1 + the ascii code for n

What I'm actually trying to do is something like this:
filename=SOME_DIR + "/" + (First char of str) + "/" + str + ".pwd";
where str=someone's name for the purposes of seperating files into 
directories based on first letter of name. Ie all the people starting with 
'A' into ~/System/data/A.

Cheers,
	Shevek

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list