home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / ClassFree_src.lha / ClassFree_src / CFgroupgclass / class_lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-02  |  2.2 KB  |  111 lines

  1. /* Library replacement routines */
  2.  
  3. #include <exec/libraries.h>
  4. #include <proto/exec.h>
  5. #include <intuition/classes.h>
  6. #include <dos/dos.h>
  7. #include "class.h"
  8.  
  9. #pragma libbase classbase  /* So StormCs linker knows the libbase size.. */
  10.  
  11. extern struct ExecBase *SysBase;
  12. struct Library *IntuitionBase;
  13. #ifdef DEBUG
  14.  #include "debug_protos.h"
  15.  APTR console;
  16. #endif
  17.  
  18. BPTR LibExpunge();
  19. BOOL openlibs(void);
  20. void closelibs(void);
  21.  
  22. struct classbase *LibInit(
  23.         register __d0 struct classbase *base,
  24.         register __a0 BPTR seglist,
  25.         register __a6 APTR sysbase)
  26. {
  27.   base->seglist = seglist;
  28.   SysBase = sysbase;
  29.   if(openlibs()) return(base);
  30.   return(NULL);
  31. }
  32.  
  33. struct Library *LibOpen(register __a6 struct classbase *base)
  34. {
  35.   if(!(base->library.lib_OpenCnt)) initclass(base);
  36.   base->library.lib_Flags &= ~LIBF_DELEXP;
  37.   base->library.lib_OpenCnt++;
  38.   return((struct Library *)base);
  39. }
  40.  
  41. BPTR LibClose(register __a6 struct classbase *base)
  42. {
  43.   base->library.lib_OpenCnt--;
  44.   if(!base->library.lib_OpenCnt)
  45.     if(base->library.lib_Flags&LIBF_DELEXP) return(LibExpunge());
  46.   return(NULL);
  47. }
  48.  
  49. BPTR LibExpunge(register __a6 struct classbase *base)
  50. {
  51.   BPTR result;
  52.   UBYTE *libmem;
  53.   LONG libsize;
  54.  
  55.   if(base->library.lib_OpenCnt)
  56.   {
  57.     base->library.lib_Flags |= LIBF_DELEXP;
  58.     return(NULL)
  59.   }
  60.   else
  61.   {
  62.     result = base->seglist;
  63.     Remove((struct Node *)base);
  64.     closelibs();
  65.     removeclass(base);
  66.     libmem = (UBYTE *)base;
  67.     libsize = base->library.lib_NegSize;
  68.     libmem -= libsize;
  69.     libsize += base->library.lib_PosSize;
  70.     FreeMem(libmem,libsize);
  71.     return(result);
  72.   }
  73. }
  74.  
  75. ULONG LibNull(void)
  76. {
  77.   return(NULL);
  78. }
  79.  
  80. BOOL openlibs(void)
  81. {
  82.   IntuitionBase = OpenLibrary("intuition.library",37);
  83. #ifdef DEBUG
  84.   console = DLopencon();
  85. #endif
  86.   if(IntuitionBase) return(TRUE);
  87.   closelibs();
  88.   return(FALSE);
  89. }
  90.  
  91. void closelibs(void)
  92. {
  93. #ifdef DEBUG
  94.   DLclosecon(console);
  95. #endif
  96.   CloseLibrary(IntuitionBase);
  97. }
  98.  
  99. /* This function converts register-parameter hook calling
  100.  * convention into standard C conventions.
  101.  */
  102. ULONG hookEntry(
  103.     register __a0 struct Hook *h,
  104.     register __a2 VOID *o,
  105.     register __a1 VOID *msg)
  106. {
  107.     return ((*h->h_SubEntry)(h, o, msg));
  108. }
  109.  
  110.  
  111.