MudOSa4DGD/
MudOSa4DGD/bin/
MudOSa4DGD/data/
MudOSa4DGD/doc/
MudOSa4DGD/doc/driver/
MudOSa4DGD/doc/efun/bitstrings/
MudOSa4DGD/doc/efun/command/
MudOSa4DGD/doc/efun/communication/
MudOSa4DGD/doc/efun/heart_beat/
MudOSa4DGD/doc/efun/interactive/
MudOSa4DGD/doc/efun/inventory/
MudOSa4DGD/doc/efun/living/
MudOSa4DGD/doc/efun/mappings/
MudOSa4DGD/doc/efun/strings/
MudOSa4DGD/doc/efun/uid/
MudOSa4DGD/doc/funs/
MudOSa4DGD/doc/language/
MudOSa4DGD/mudlib/dgd/doc/
MudOSa4DGD/mudlib/dgd/lib/include/dgd/
MudOSa4DGD/mudlib/dgd/lib/std/
MudOSa4DGD/mudlib/dgd/lib/sys/
MudOSa4DGD/mudlib/dgd/log/
MudOSa4DGD/mudlib/log/
MudOSa4DGD/mudlib/std/include/
MudOSa4DGD/mudlib/std/obj/
/*
 * 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;
}