/*
* file_name.c
*
* filename of an object
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
/* get the filename, with #<instance number> if clone */
static varargs string file_name(object ob) {
return ::object_name(ob ? ob : this_object());
}
/* get filename without the instance number */
static varargs string source_file_name(mixed file) {
int i;
if (file) {
switch (typeof(file)) {
case T_OBJECT:
file = object_name(file);
break;
case T_STRING:
#ifdef DEFAULT_SRC_EXTENSION
/* get rid of any .c ending */
if (strlen(file) > 2 && file[strlen(file)-2..] == DEFAULT_SRC_EXTENSION)
file = file[0..strlen(file)-3];
#endif
break;
default:
error("Bad type of argument 1 to source_file_name().");
break;
}
}
else
file = object_name(this_object());
if ((i=strsrch(file, "#", -1)) > 0)
return file[..i-1];
return file;
}
/* find directory of a file */
static varargs string directory_name(mixed file) {
int i;
if (file) {
switch (typeof(file)) {
case T_OBJECT:
file = object_name(file);
break;
case T_STRING:
break;
default:
error("Bad type of argument 1 to directory_name().");
break;
}
}
else
file = object_name(this_object());
if ((i=strsrch(file, "/", -1)) >= 0)
return file[..i];
return "/";
}
/* get basename of file */
static varargs string base_name(mixed file) {
int i;
if (file) {
switch (typeof(file)) {
case T_OBJECT:
file = source_file_name(file);
break;
case T_STRING:
break;
default:
error("Bad type of argument 1 to base_name().");
break;
}
}
else
file = source_file_name();
if ((i=strsrch(file, "/", -1)) >= 0) {
if (i < strlen(file)-1)
return file[i+1..];
else
return "";
}
return file;
}