untermud/DOC/
untermud/DOC/U/
untermud/DOC/U/U-examples/
untermud/DOC/internals/
untermud/DOC/wizard/
untermud/MISC/
untermud/MISC/dbchk/
untermud/RWHO/
untermud/RWHO/rwhod/
#include    "config.h"
#include    "mud.h"
#include    "u.h"
#include    "y.tab.h"
#include    "sbuf.h"

int ub_ladd (char *who, char *aswho, int ac, Nod * av[], Nod * retnode)
{
  char *lp;
  int x;

  if (av[0]->rv.t != STR && av[0]->rv.t != OID && av[0]->rv.t != NUM)
    lp = "";
  else
    lp = eval_caststr (av[0]);

  for (x = 1; x < ac; x++) {
    if (av[x]->rv.t != STR && av[x]->rv.t != OID && av[x]->rv.t != NUM)
      continue;

    /* making a temp copy is necessary. :( */
    lp = tmpstr (lstadd (lp, eval_caststr (av[x]), (int *) 0));
    if (lp == (char *) 0)
      return (UERR_FATAL);
  }
  retnode->rv.cv = lp;
  retnode->rv.t = STR;
  return (UERR_NONE);
}




int ub_ldel (char *who, char *aswho, int ac, Nod * av[], Nod * retnode)
{
  char *l;
  int x;

  if (av[0]->rv.t != STR && av[0]->rv.t != OID && av[0]->rv.t != NUM)
    l = "";
  else
    l = eval_caststr (av[0]);

  for (x = 1; x < ac; x++) {
    if (av[x]->rv.t != STR && av[x]->rv.t != OID && av[x]->rv.t != NUM)
      continue;

    /* making a temp copy is necessary. :( */
    l = tmpstr (lstdel (l, eval_caststr (av[x]), (int *) 0));
    if (l == (char *) 0)
      return (UERR_FATAL);
  }

  /* empty list? */
  if (l == (char *) 0 || l[0] == '\n' || (l[0] == ';' && l[1] == '\0')) {
    retnode->rv.iv = UERR_NONE;
    retnode->rv.t = VNULL;
  } else {
    retnode->rv.cv = l;
    retnode->rv.t = STR;
  }
  return (UERR_NONE);
}




int ub_llok (char *who, char *aswho, int ac, Nod * av[], Nod * retnode)
{
  if (av[0]->rv.t != STR && av[0]->rv.t != OID && av[0]->rv.t != NUM) {
    retnode->rv.iv = 0;
    retnode->rv.t = NUM;
    return (UERR_NONE);
  }
  if (av[1]->rv.t != STR && av[1]->rv.t != OID && av[1]->rv.t != NUM) {
    retnode->rv.iv = 0;
    retnode->rv.t = NUM;
    return (UERR_NONE);
  }
  retnode->rv.iv = lstlook (eval_caststr (av[0]), eval_caststr (av[1]));
  retnode->rv.t = NUM;
  return (UERR_NONE);
}




int ub_lcnt (char *who, char *aswho, int ac, Nod * av[], Nod * retnode)
{
  if (av[0]->rv.t != STR && av[0]->rv.t != OID && av[0]->rv.t != NUM) {
    retnode->rv.iv = 0;
    retnode->rv.t = NUM;
    return (UERR_NONE);
  }
  retnode->rv.iv = lstcnt (eval_caststr (av[0]));
  retnode->rv.t = NUM;
  return (UERR_NONE);
}




int ub_litem (char *who, char *aswho, int ac, Nod * av[], Nod * retnode)
{
  Sbuf sb;
  int cnt;
  int ele;
  char *lp;

  if (av[0]->rv.t != STR && av[0]->rv.t != OID && av[0]->rv.t != NUM)
    return (UERR_BADOID);
  if (av[1]->rv.t != STR && av[1]->rv.t != OID && av[1]->rv.t != NUM)
    return (UERR_BADPARM);

  lp = eval_caststr (av[0]);
  cnt = lstcnt (lp);
  /* out of range */
  ele = eval_castint (av[1]);
  if (ele < 1 || ele > cnt)
    return (UERR_BADOID);

  sbuf_initstatic (&sb);
  while (ele > 0) {
    if ((lp = lstnextsbuf (lp, &sb)) == (char *) 0)
      return (UERR_BADOID);
    ele--;
  }
  retnode->rv.cv = tmpstr (sbuf_buf (&sb));
  retnode->rv.t = OID;
  sbuf_freestatic (&sb);
  return (UERR_NONE);
}