/*
 * umssupliblib.c  Part of the umssupport.library
 *
 * Open librarys and allocate memory used in umssupport.library.
 * This module has to be linked first to .library!
 *
 * initial code '96 by chr@quack.westfalen.de
 *
 */

// includes: ------------------------------------------------------------------
# include "umssuplibinternal.h"
# include "include/libraries/umssuplib.h"

// globals: ------------------------------------------------------------------
struct DosLibrary *DOSBase;
struct ExecBase *SysBase;
struct Library *UMSBase;

int err;
char *umserr;

/* ------------------------------------------------------------------------ */
int __saveds __asm
__UserLibInit (register __a6 struct MyLibrary *libbase)
{
  SysBase = *(struct ExecBase **) 4L;
  if (!(DOSBase = (struct DosLibrary *) OpenLibrary ("dos.library", 37L))) {
    return (RETURN_FAIL);
    }

  if (!(UMSBase = OpenLibrary ("ums.library", 11L)))
    return (RETURN_FAIL);


#ifdef  MWDEBUG
   MWInit(NULL, MWF_SERIAL, NULL); /* send via debug.lib (enforcer) */
   MWReport("Begin of main()", MWR_FULL);  /* Generate a memory usage report */
#endif

  umserr = malloc(256);
  if (!umserr)
     return(RETURN_FAIL);

  strcpy(umserr,"\0");

  err=0;

  return (RETURN_OK);
}


/* ------------------------------------------------------------------------ */
void __saveds __asm
__UserLibCleanup (register __a6 struct MyLibrary *libbase)
{
  if (umserr)
    free(umserr);

#ifdef  MWDEBUG
   MWReport("At end of main()", MWR_FULL);  /* Generate a memory usage report */
#endif

  if (UMSBase)
    CloseLibrary (UMSBase);

  if (DOSBase)
    CloseLibrary ((struct Library *) DOSBase);
}
