home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / c / CLib37x.lha / c_lib / source / lib_source / StartUp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  4.2 KB  |  189 lines

  1. /*
  2. **      $VER: StartUp.c 37.5 (24.1.97)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10.  
  11. #define __USE_SYSBASE      // ignored by MAXON
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <exec/libraries.h>
  16. #include <exec/execbase.h>
  17. #include <exec/resident.h>
  18. #include <exec/initializers.h>
  19.  
  20.  
  21. #ifdef __MAXON__
  22. #include <pragma/exec_lib.h>
  23. #include <linkerfunc.h>
  24. #else
  25. #include <proto/exec.h>    // all other compilers
  26. #endif
  27. #include "compiler.h"
  28.  
  29. #include "/include/example/examplebase.h"
  30. #include "samplefuncs.h"
  31.  
  32. extern ULONG __saveds __stdargs L_OpenLibs(void);
  33. extern void  __saveds __stdargs L_CloseLibs(void);
  34.  
  35. struct ExampleBase * __saveds __asm InitLib( register __a6 struct ExecBase *sysbase,
  36.                     register __a0 struct SegList       *seglist,
  37.                     register __d0 struct ExampleBase *exb);
  38. struct ExampleBase * __saveds __asm OpenLib( register __a6 struct ExampleBase *ExampleBase);
  39. struct SegList * __saveds __asm CloseLib( register __a6 struct ExampleBase *ExampleBase);
  40. struct SegList * __saveds __asm ExpungeLib( register __a6 struct ExampleBase *exb);
  41. ULONG __saveds __asm ExtFuncLib(void);
  42.  
  43. LONG __saveds __asm LibStart(void)
  44. {
  45.  return(-1);
  46. }
  47.  
  48. extern APTR FuncTab [];
  49. extern struct MyDataInit DataTab;
  50.  
  51. struct InitTable                       /* do not change */
  52. {
  53.  ULONG              LibBaseSize;
  54.  APTR              *FunctionTable;
  55.  struct MyDataInit *DataTable;
  56.  APTR               InitLibTable;
  57. } InitTab =
  58. {
  59.  sizeof(struct ExampleBase),
  60.  &FuncTab[0],
  61.  &DataTab,
  62.  InitLib
  63. };
  64.  
  65. APTR FuncTab [] =                      
  66. {
  67.  OpenLib,
  68.  CloseLib,
  69.  ExpungeLib,
  70.  ExtFuncLib,
  71.  
  72.  EXF_TestRequest,  /* add your own functions here */
  73.  
  74.  (APTR) ((LONG)-1)
  75. };
  76.  
  77.  
  78. extern struct ExampleBase *ExampleBase;
  79.  
  80. struct ExampleBase * __saveds __asm InitLib( register __a6 struct ExecBase      *sysbase,
  81.                     register __a0 struct SegList       *seglist,
  82.                     register __d0 struct ExampleBase *exb)
  83. {
  84.  ExampleBase = exb;
  85.  
  86.  ExampleBase->exb_SysBase = sysbase;
  87.  ExampleBase->exb_SegList = seglist;
  88.  
  89.  if(L_OpenLibs()) return(ExampleBase);
  90.  
  91.  L_CloseLibs();
  92.  
  93.  return(NULL);
  94. }
  95.  
  96. struct ExampleBase * __saveds __asm OpenLib( register __a6 struct ExampleBase *ExampleBase)
  97. {
  98.  #ifdef __MAXON__
  99.  GetBaseReg();
  100.  InitModules();
  101.  #endif
  102.  
  103.  ExampleBase->exb_LibNode.lib_OpenCnt++;
  104.  
  105.  ExampleBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  106.  
  107.  return(ExampleBase);
  108. }
  109.  
  110. struct SegList * __saveds __asm CloseLib( register __a6 struct ExampleBase *ExampleBase)
  111. {
  112.  ExampleBase->exb_LibNode.lib_OpenCnt--;
  113.  
  114.  if(!ExampleBase->exb_LibNode.lib_OpenCnt)
  115.   {
  116.    if(ExampleBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
  117.     {
  118.      return( ExpungeLib(ExampleBase) );
  119.     }
  120.   }
  121.  
  122.  return(NULL);
  123. }
  124.  
  125. struct SegList * __saveds __asm ExpungeLib( register __a6 struct ExampleBase *exb)
  126. {
  127.  struct ExampleBase *ExampleBase = exb;
  128.  struct SegList       *seglist;
  129.  
  130.  if(!ExampleBase->exb_LibNode.lib_OpenCnt)
  131.   {
  132.    ULONG negsize, possize, fullsize;
  133.    UBYTE *negptr = (UBYTE *) ExampleBase;
  134.  
  135.    seglist = ExampleBase->exb_SegList;
  136.  
  137.    Remove((struct Node *)ExampleBase);
  138.  
  139.    L_CloseLibs();
  140.  
  141.    negsize  = ExampleBase->exb_LibNode.lib_NegSize;
  142.    possize  = ExampleBase->exb_LibNode.lib_PosSize;
  143.    fullsize = negsize + possize;
  144.    negptr  -= negsize;
  145.  
  146.    FreeMem(negptr, fullsize);
  147.  
  148.    #ifdef __MAXON__
  149.    CleanupModules();
  150.    #endif
  151.  
  152.    return(seglist);
  153.   }
  154.   
  155.  ExampleBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  156.  
  157.  return(NULL);
  158. }
  159.  
  160. ULONG __saveds __asm ExtFuncLib(void)
  161. {
  162.  return(NULL);
  163. }
  164.  
  165. struct ExampleBase *ExampleBase = NULL;
  166.  
  167.  
  168. #ifdef __SASC
  169.  
  170. ULONG XCEXIT       = NULL;  /* these symbols may be referenced by    */
  171. ULONG _XCEXIT      = NULL;  /* some functions of sc.lib, but should  */
  172. ULONG ONBREAK      = NULL;  /* never be used inside a shared library */
  173. ULONG _ONBREAK     = NULL;
  174. ULONG base         = NULL;
  175. ULONG _base        = NULL;
  176. ULONG ProgramName  = NULL;
  177. ULONG _ProgramName = NULL;
  178. ULONG StackPtr     = NULL;
  179. ULONG _StackPtr    = NULL;
  180. ULONG oserr        = NULL;
  181. ULONG _oserr       = NULL;
  182. ULONG OSERR        = NULL;
  183. ULONG _OSERR       = NULL;
  184.  
  185. void __regargs __chkabort(void) { }  /* a shared library cannot be    */
  186. void __regargs _CXBRK(void)     { }  /* CTRL-C aborted when doing I/O */
  187.  
  188. #endif /* __SASC */
  189.