[DGD] More info on expand()

Shevek shevek at btinternet.com
Tue Dec 18 20:14:18 CET 2001


Had another look at expand() and managed to clean my code up quite 
considerably.
This may come in handy for someone, somewhere, so I thought I'd leave it 
here in case anyone else has a similar problem.

In:
Path to filename from current directory, or just filename if it's in 
current directory.
Eg System/initd.c if in ~/. initd.c if in ~/System.

Out:
Nil if a directory/file doesn't exist/access denied/wildcards used.
Full path to file if not a directory/exists/access allowed/single filename.

/*
  * NAME:	single_file_path()
  * DATE:	18/12/01, Shevek.
  * DESCRIPTION:	Returns the full path to an existing file, nil if there is 
an error
  */
static string single_file_path(string str){
	    mixed *info;
		info = expand(str, 1, TRUE);
		if (info[4] == 1) {
			if (sizeof(info[0]) != 1) {
				return nil;
			}
			if (info[1][0]==-2){
				message(str + ": Is a directory.\n");
				return nil;
			}
     	}	
		else {
			message("Error: Use single filenames only.\n");
			return nil;
     	}
		str = info[0][0];
	return str;
}

Requires:
message() : return message to user.
expand() from /kernel/lib/wiztool plus whatever expand needs.

Hope that helps someone out.

Cheers,
	Shevek


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



More information about the DGD mailing list