home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / fish / disks / d1074.lha / Programs / C_dt / source / classbase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-11  |  3.1 KB  |  139 lines

  1. /*
  2. ** $PROJECT: c.datatype
  3. **
  4. ** $VER: classbase.c 39.1 (06.03.95)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1995
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 06.03.95 : 039.001 : initial
  16. */
  17.  
  18. #include "classbase.h"
  19.  
  20. LibCall Class *ENGINE (REGA6 struct ClassBase *cb)
  21. {
  22.    return(cb->cb_Class);
  23. }
  24.  
  25. LibCall struct Library *LibInit (REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct Library * sysbase)
  26. {
  27.    cb->cb_SegList = seglist;
  28.    cb->cb_SysBase = sysbase;
  29.    InitSemaphore (&cb->cb_Lock);
  30.  
  31.    DB(("c.datatype init !\n"));
  32.  
  33.    if(cb->cb_SysBase->lib_Version >= 39)
  34.    {
  35.       cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  36.       cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  37.       cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  38.       cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  39.    } else
  40.       cb = NULL;
  41.  
  42.   return((struct Library *) cb);
  43. }
  44.  
  45. LibCall LONG LibOpen (REGA6 struct ClassBase *cb)
  46. {
  47.    LONG retval = (LONG) cb;
  48.  
  49.    ObtainSemaphore (&cb->cb_Lock);
  50.  
  51.    /* Use an internal use counter */
  52.    cb->cb_Lib.lib_OpenCnt++;
  53.    cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  54.  
  55.    if(cb->cb_Lib.lib_OpenCnt == 1 && cb->cb_Class == NULL)
  56.    {
  57.       retval = (LONG) NULL;
  58.  
  59.       if((cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39)))
  60.          if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
  61.             if((cb->cb_SuperClassBase = OpenLibrary(SUPERCLASSDATATYPE,39)))
  62.                if((cb->cb_Class = initClass(cb)))
  63.                   retval = (LONG) cb;
  64.  
  65.       if(!retval)
  66.       {
  67.          if(cb->cb_IFFParseBase)
  68.          {
  69.             CloseLibrary(cb->cb_IFFParseBase);
  70.             cb->cb_IFFParseBase = NULL;
  71.          }
  72.  
  73.          if(cb->cb_DataTypesBase)
  74.          {
  75.             CloseLibrary(cb->cb_DataTypesBase);
  76.             cb->cb_DataTypesBase = NULL;
  77.          }
  78.  
  79.          if(cb->cb_SuperClassBase)
  80.          {
  81.             CloseLibrary(cb->cb_SuperClassBase);
  82.             cb->cb_SuperClassBase = NULL;
  83.          }
  84.  
  85.          cb->cb_Lib.lib_OpenCnt--;
  86.       }
  87.    }
  88.  
  89.    ReleaseSemaphore (&cb->cb_Lock);
  90.  
  91.    return (retval);
  92. }
  93.  
  94. LibCall LONG LibClose (REGA6 struct ClassBase *cb)
  95. {
  96.    LONG retval = NULL;
  97.  
  98.    ObtainSemaphore (&cb->cb_Lock);
  99.  
  100.    if (cb->cb_Lib.lib_OpenCnt)
  101.       cb->cb_Lib.lib_OpenCnt--;
  102.  
  103.    if((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  104.    {
  105.       if(FreeClass (cb->cb_Class))
  106.       {
  107.          cb->cb_Class = NULL;
  108.          CloseLibrary(cb->cb_SuperClassBase);
  109.          CloseLibrary(cb->cb_DataTypesBase);
  110.          CloseLibrary(cb->cb_IFFParseBase);
  111.       } else
  112.          cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  113.    }
  114.  
  115.    if(cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  116.        retval = LibExpunge (cb);
  117.  
  118.    ReleaseSemaphore (&cb->cb_Lock);
  119.  
  120.    return (retval);
  121. }
  122.  
  123. LibCall LONG LibExpunge(REGA6 struct ClassBase *cb)
  124. {
  125.    BPTR seg = cb->cb_SegList;
  126.  
  127.    Remove((struct Node *) cb);
  128.  
  129.    CloseLibrary(cb->cb_UtilityBase);
  130.    CloseLibrary(cb->cb_DOSBase);
  131.    CloseLibrary(cb->cb_GfxBase);
  132.    CloseLibrary(cb->cb_IntuitionBase);
  133.  
  134.    FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  135.  
  136.    return((LONG) seg);
  137. }
  138.  
  139.