home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / example_c_dt / dt_source / libinit.c < prev    next >
C/C++ Source or Header  |  1997-06-29  |  5KB  |  153 lines

  1. /*
  2. **      $VER: LibInit.c 43.9 (29.6.97)
  3. **
  4. **      Library initializers and functions to be called by StartUp.c
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/libraries.h>
  15. #include <exec/execbase.h>
  16. #include <exec/resident.h>
  17. #include <exec/initializers.h>
  18. #include <datatypes/pictureclass.h>
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/intuition.h>
  22. #include <proto/datatypes.h>
  23.  
  24. #include <class/classbase.h>
  25. #include "libfuncs.h"
  26.  
  27.  
  28. ULONG __saveds __stdargs L_OpenLibs(void);
  29. void  __saveds __stdargs L_CloseLibs(void);
  30.  
  31. extern struct ClassBase *ClassBase;
  32.  
  33.  
  34. struct ExecBase      *SysBase        = NULL;
  35. struct DosLibrary    *DOSBase        = NULL;
  36. struct IntuitionBase *IntuitionBase  = NULL;
  37. struct GfxBase       *GfxBase        = NULL;
  38. struct Library       *UtilityBase    = NULL;
  39. struct Library       *DataTypesBase  = NULL;
  40. struct Library       *SuperClassBase = NULL;
  41. struct Library       *IFFParseBase   = NULL;
  42.  
  43.  
  44. #define VERSION  43
  45. #define REVISION 9
  46.  
  47. char __aligned ExLibName [] = "samplePNM.datatype";
  48. char __aligned ExLibID   [] = "samplePNM 43.9 (29.6.97)";
  49. char __aligned Copyright [] = "(C)opyright 1996-97 by Andreas R. Kleinert. All rights reserved.";
  50.  
  51. extern ULONG InitTab[];
  52.  
  53. extern APTR EndResident; /* below */
  54.  
  55. struct Resident __aligned ROMTag =
  56. {
  57.  RTC_MATCHWORD,
  58.  &ROMTag,
  59.  &EndResident,
  60.  RTF_AUTOINIT,
  61.  VERSION,
  62.  NT_LIBRARY,
  63.  0,
  64.  &ExLibName[0],
  65.  &ExLibID[0],
  66.  &InitTab[0]
  67. };
  68.  
  69. APTR EndResident;
  70.  
  71. struct MyDataInit                      /* do not change */
  72. {
  73.  UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  74.  UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  75.  UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  76.  UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  77.  UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  78.  UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  79.  ULONG ENDMARK;
  80. } DataTab =
  81. {
  82.  INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  83.  0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &ExLibName[0],
  84.  INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  85.  INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  86.  INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  87.  0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &ExLibID[0],
  88.  (ULONG) 0
  89. };
  90.  
  91.  /* Libraries not shareable between Processes or libraries messing
  92.     with RamLib (deadlock and crash) may not be opened here - open/close
  93.     these later locally and or maybe close them fromout L_CloseLibs()
  94.     when expunging !
  95.  
  96.     iffparse.library e.g. *should* not matter here, since our base class
  97.     (picture.datatype) will have opened it before
  98.  */
  99.  
  100. ULONG __saveds __stdargs L_OpenLibs(void)
  101. {
  102.  SysBase = (*((struct ExecBase **) 4));
  103.  
  104.  DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 39);
  105.  if(!DOSBase) return(FALSE);
  106.  
  107.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
  108.  if(!IntuitionBase) return(FALSE);
  109.  
  110.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
  111.  if(!GfxBase) return(FALSE);
  112.  
  113.  UtilityBase = (struct Library *) OpenLibrary("utility.library", 39);
  114.  if(!UtilityBase) return(FALSE);
  115.  
  116.  DataTypesBase = (struct Library *) OpenLibrary("datatypes.library", 39);
  117.  if(!DataTypesBase) return(FALSE);
  118.  
  119.  SuperClassBase = (struct Library *) OpenLibrary("datatypes/picture.datatype", 39);
  120.  if(!SuperClassBase) return(FALSE);
  121.  
  122.  IFFParseBase = (struct Library *) OpenLibrary("iffparse.library", 37);
  123.  if(!IFFParseBase) return(FALSE);
  124.  
  125.  
  126.  ClassBase->cb_SysBase        = (struct ExecBase      *) SysBase;
  127.  
  128.  ClassBase->cb_DOSBase        = (struct DosLibrary    *) DOSBase;
  129.  ClassBase->cb_IntuitionBase  = (struct IntuitionBase *) IntuitionBase;
  130.  ClassBase->cb_GfxBase        = (struct GfxBase       *) GfxBase;
  131.  ClassBase->cb_UtilityBase    = (struct Library       *) UtilityBase;
  132.  ClassBase->cb_DataTypesBase  = (struct Library       *) DataTypesBase;
  133.  ClassBase->cb_SuperClassBase = (struct Library       *) SuperClassBase;
  134.  ClassBase->cb_IFFParseBase   = (struct Library       *) IFFParseBase;
  135.  
  136.  if(ClassBase->cb_Class = initClass(ClassBase)) return(TRUE);
  137.  
  138.  return(FALSE);
  139. }
  140.  
  141. void __saveds __stdargs L_CloseLibs(void)
  142. {
  143.  if(ClassBase->cb_Class) FreeClass(ClassBase->cb_Class);
  144.  
  145.  if(IFFParseBase)   CloseLibrary((struct Library *) IFFParseBase);
  146.  if(SuperClassBase) CloseLibrary((struct Library *) SuperClassBase);
  147.  if(DataTypesBase)  CloseLibrary((struct Library *) DataTypesBase);
  148.  if(UtilityBase)    CloseLibrary((struct Library *) UtilityBase);
  149.  if(GfxBase)        CloseLibrary((struct Library *) GfxBase);
  150.  if(IntuitionBase)  CloseLibrary((struct Library *) IntuitionBase);
  151.  if(DOSBase)        CloseLibrary((struct Library *) DOSBase);
  152. }
  153.