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/
/*
 * present.c
 *
 * The present efuns
 *
 * (C) Frank Schmidt, Jesus@NorseMUD
 *
 */


#ifdef MUDOS_PRESENT

static varargs object present(mixed str, object ob) {
  object *obs, res;
  int i, num;

  /* check our sfun-emulation of present first */
  if (res=this_object()->sfun_present(str, ob))
    return res;

  /* default to this_object() */
  if (!objectp(ob)) {
    object res, env;
    if (!(res=present(str, this_object())))
      if (env=environment(this_object()))
	return present(str, env);
    /* return result */
    return res;
  }

  if (objectp(str))
    /* easy check */
    return (environment(str) == ob) ? str : 0;

  /* check if we have a number at end of our string */
  if ((i = strsrch(str, " ", -1)) != -1) {
    /* get the number if any */
    string s;
    s = str[i..];
    str = str[..i-1];
    if (strlen(s))
      num = (int)s;
  }

  if (strlen(str)) {
    obs = all_inventory(ob);
    for (i=::sizeof(obs); --i >=0; ) {
      if (call_other(obs[i], __ID_FUNC, str) && (--num <= 0)) {
	/* found it! */
	return obs[i];
      }
    }
  }
  return 0;
}

#endif


#ifdef MUDOS_ALL_PRESENT

/* return array of all matching <id> in <env> */
static varargs object *all_present(string id, object env) {
  if (!env) env = this_object();
  return GLOBAL->filter_all_present(id, env);
}

#endif