#include "common/extern.h"

LONG
error_req (STRPTR buttons, STRPTR fmt,...)
{
  return (MUI_RequestA (oa->App, NULL, 0,
                        NULL, buttons, fmt, (ULONG *) (&fmt) + 1));
};

void
FreeUrlNode (struct URLNode *nd)
{
  if (nd)
    {
      if (nd->url)
        FreeVecPooled (gd.gd_pool, nd->url);

      if (nd->title)
        FreeVecPooled (gd.gd_pool, nd->title);

      if (nd->name)
        FreeVecPooled (gd.gd_pool, nd->name);

      if (nd->password)
        FreeVecPooled (gd.gd_pool, nd->password);

      if (nd->type)
        FreeVecPooled (gd.gd_pool, nd->type);

      if (nd->etag)
        FreeVecPooled (gd.gd_pool, nd->etag);

      FreeSPooled (gd.gd_pool, nd, sizeof (struct URLNode));
      nd = NULL;
    }
}


STRPTR
newstrcpy (APTR pool, STRPTR str)
{
  STRPTR tmp;

  if (str)
    {
      int size = strlen (str);

      if (size)
        if ((tmp = (STRPTR) AllocVecPooled (pool, ++size)))
          {
            strncpy (tmp, str, size);
            return (tmp);
          }
    }

  return (NULL);
}


struct URLNode *newurlnodecopy(struct URLNode *old)
{
  struct URLNode *nd = NULL;

    if ((nd = (struct URLNode *) AllocSPooled (gd.gd_pool, sizeof (struct URLNode))))
      {
        memcpy (nd, old, sizeof (struct URLNode));

      if (old->url)
         nd->url = newstrcpy (gd.gd_pool, nd->url);

      if (old->title)
         nd->title = newstrcpy (gd.gd_pool, nd->title);

      if (old->name)
         nd->name = newstrcpy (gd.gd_pool, nd->name);

      if (old->password)
         nd->password = newstrcpy (gd.gd_pool, nd->password);

      if (old->type)
         nd->type = newstrcpy (gd.gd_pool, nd->type);

      if (old->etag)
         nd->etag = newstrcpy (gd.gd_pool, nd->etag);
      }

  return (nd);
};



int
s_strlen (char *str)
{
  if (str)
    return (strlen (str));
  else
    return (NULL);
}

LONG
xget (Object * obj, ULONG attribute)
{
  LONG x;
  get (obj, attribute, &x);
  return (x);
}

ULONG
DoSuperNew (struct IClass * cl, Object * obj, ULONG tag1,...)
{
  return (DoSuperMethod (cl, obj, OM_NEW, &tag1, NULL));
}

