file_name.c~

MudOSa4DGD/mudlib/dgd/lib/sys/efun/file_name.c~ · 1.5 KB

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * 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;
  switch (typeof(file)) {
  case T_OBJECT:
    file = object_name(file);
    break;
  case T_STRING:
    /* get rid of any .c ending */
    if (strlen(file) > 2 && file[strlen(file)-2..] == ".c")
      file = file[0..strlen(file)-3];
    break;
  default:
    file = object_name(this_object());
    break;
  }
  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;
  switch (typeof(file)) {
  case T_OBJECT:
    file = object_name(file);
    break;
  case T_STRING:
    break;
  default:
    file = object_name(this_object());
    break;
  }
  if ((i=strsrch(file, "/", -1)) >= 0)
    return file[..i];
  return "/";
}


/* get basename of file */
static varargs string base_name(mixed file) {
  int i;
  switch (typeof(file)) {
  case T_OBJECT:
    file = object_name(file);
    break;
  case T_STRING:
    break;
  default:
    file = object_name(this_object());
    break;
  }
  if ((i=strsrch(file, "/", -1)) >= 0) {
    if (i < strlen(file)-1)
      return file[i+1..];
    else
      return "";
  }
  return file;
}

Site Stats

Snippets: 1791
Codebases: 571