home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / ClassFree / CFsampleclass / class_lib.c next >
C/C++ Source or Header  |  1998-05-19  |  2KB  |  117 lines

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