home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / ClassFree_src.lha / ClassFree_src / CFpumbuttonclass / class_lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-02  |  2.9 KB  |  130 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. struct Library *UtilityBase;
  14. struct Library *GfxBase;
  15. struct Library *textibase;
  16. struct Library *glyphibase;
  17. struct Library *buttonbase;
  18. #ifdef DEBUG
  19.  #include "debug_protos.h"
  20.  APTR console;
  21. #endif
  22.  
  23. BPTR LibExpunge();
  24. BOOL openlibs(void);
  25. void closelibs(void);
  26.  
  27. struct classbase *LibInit(
  28.     register __d0 struct classbase *base,
  29.     register __a0 BPTR seglist,
  30.     register __a6 APTR sysbase)
  31. {
  32.   base->seglist = seglist;
  33.   SysBase = sysbase;
  34.   if(openlibs()) return(base);
  35.   return(NULL);
  36. }
  37.  
  38. struct Library *LibOpen(register __a6 struct classbase *base)
  39. {
  40.   if(!(base->library.lib_OpenCnt)) initclass(base);
  41.   base->library.lib_Flags &= ~LIBF_DELEXP;
  42.   base->library.lib_OpenCnt++;
  43.   return((struct Library *)base);
  44. }
  45.  
  46. BPTR LibClose(register __a6 struct classbase *base)
  47. {
  48.   base->library.lib_OpenCnt--;
  49.   if(!base->library.lib_OpenCnt)
  50.     if(base->library.lib_Flags&LIBF_DELEXP) return(LibExpunge());
  51.   return(NULL);
  52. }
  53.  
  54. BPTR LibExpunge(register __a6 struct classbase *base)
  55. {
  56.   BPTR result;
  57.   UBYTE *libmem;
  58.   LONG libsize;
  59.  
  60.   if(base->library.lib_OpenCnt)
  61.   {
  62.     base->library.lib_Flags |= LIBF_DELEXP;
  63.     return(NULL)
  64.   }
  65.   else
  66.   {
  67.     result = base->seglist;
  68.     Remove((struct Node *)base);
  69.     closelibs();
  70.     removeclass(base);
  71.     libmem = (UBYTE *)base;
  72.     libsize = base->library.lib_NegSize;
  73.     libmem -= libsize;
  74.     libsize += base->library.lib_PosSize;
  75.     FreeMem(libmem,libsize);
  76.     return(result);
  77.   }
  78. }
  79.  
  80. ULONG LibNull(void)
  81. {
  82.   return(NULL);
  83. }
  84.  
  85. BOOL openlibs(void)
  86. {
  87.   IntuitionBase = OpenLibrary("intuition.library",37);
  88.   UtilityBase = OpenLibrary("utility.library",37);
  89.   GfxBase = OpenLibrary("graphics.library",37);
  90.   textibase = OpenLibrary("CFtext.image",NULL);
  91.   if(!textibase) textibase = OpenLibrary("Images/CFtext.image",NULL);
  92.   glyphibase = OpenLibrary("CFglyph.image",NULL);
  93.   if(!glyphibase) glyphibase = OpenLibrary("Images/CFglyph.image",NULL);
  94.   buttonbase = OpenLibrary("CFbutton.gadget",NULL);
  95.   if(!buttonbase) buttonbase = OpenLibrary("Gadgets/CFbutton.gadget",NULL);
  96. #ifdef DEBUG
  97.   console = DLopencon();
  98. #endif
  99.   if(IntuitionBase&&UtilityBase&&GfxBase&&
  100.       textibase&&glyphibase&&buttonbase) return(TRUE);
  101.   closelibs();
  102.   return(FALSE);
  103. }
  104.  
  105. void closelibs(void)
  106. {
  107. #ifdef DEBUG
  108.   DLclosecon(console);
  109. #endif
  110.   CloseLibrary(buttonbase);
  111.   CloseLibrary(glyphibase);
  112.   CloseLibrary(textibase);
  113.   CloseLibrary(GfxBase);
  114.   CloseLibrary(UtilityBase);
  115.   CloseLibrary(IntuitionBase);
  116. }
  117.  
  118. /* This function converts register-parameter hook calling
  119.  * convention into standard C conventions.
  120.  */
  121. ULONG hookEntry(
  122.     register __a0 struct Hook *h,
  123.     register __a2 VOID *o,
  124.     register __a1 VOID *msg)
  125. {
  126.     return ((*h->h_SubEntry)(h, o, msg));
  127. }
  128.  
  129.  
  130.