home *** CD-ROM | disk | FTP | other *** search
/ fxPAINT 1.0 / fxPAINT 1.0.iso / developers / plugins / exampleplugin / lib_source / startup.c < prev   
Encoding:
C/C++ Source or Header  |  1999-08-09  |  9.6 KB  |  313 lines

  1. /*
  2. **      $VER: StartUp.c 1.00 (9.8.1999)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1999 Felix Schwarz
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  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.  
  19.  
  20. #ifdef __MAXON__
  21. #include <pragma/exec_lib.h>
  22. #include <linkerfunc.h>
  23. #else
  24. #include <proto/exec.h>    // all other compilers
  25. #endif
  26.  
  27. #include "compiler.h"
  28. #include "base.h"
  29.  
  30. #include "PluginFuncs.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 GNUCREG(a6),
  36.                     register __a0 struct SegList *seglist GNUCREG(a0),
  37.                     register __d0 struct ExampleBase *exb GNUCREG(d0));
  38. struct ExampleBase * __saveds ASM OpenLib( register __a6 struct ExampleBase *ExampleBase GNUCREG(a6));
  39. APTR __saveds ASM CloseLib( register __a6 struct ExampleBase *ExampleBase GNUCREG(a6));
  40. APTR __saveds ASM ExpungeLib( register __a6 struct ExampleBase *exb GNUCREG(a6));
  41. ULONG ASM ExtFuncLib(void);
  42.  
  43.  
  44. /* ----------------------------------------------------------------------------------------
  45.    ! LibStart:
  46.    !
  47.    ! If someone tries to start a library as an executable, it must return (LONG) -1
  48.    ! as result. That's what we are doing here.
  49.    ---------------------------------------------------------------------------------------- */
  50.  
  51. LONG ASM LibStart(void)
  52. {
  53.  return(-1);
  54. }
  55.  
  56.  
  57. /* ----------------------------------------------------------------------------------------
  58.    ! Function and Data Tables:
  59.    !
  60.    ! The function and data tables have been placed here for traditional reasons.
  61.    ! Placing the RomTag structure before (-> LibInit.c) would also be a good idea,
  62.    ! but it depends on whether you would like to keep the "version" stuff separately.
  63.    ---------------------------------------------------------------------------------------- */
  64.  
  65. extern APTR FuncTab [];
  66. extern struct MyDataInit DataTab; /* instead you may place ROMTag + Datatab directly, here */
  67.                                   /* (see LibInit.c). This may fix "Installer" version     */
  68.                                   /* checking problems, too.                               */
  69.  
  70. struct InitTable                       /* do not change */
  71. {
  72.  ULONG              LibBaseSize;
  73.  APTR              *FunctionTable;
  74.  struct MyDataInit *DataTable;
  75.  APTR               InitLibTable;
  76. } InitTab =
  77. {
  78.  sizeof(struct ExampleBase),
  79.  &FuncTab[0],
  80.  &DataTab,
  81.  InitLib
  82. };
  83.  
  84. APTR FuncTab [] =
  85. {
  86.  OpenLib,
  87.  CloseLib,
  88.  ExpungeLib,
  89.  ExtFuncLib,
  90.  
  91.  FXPlug_Info,
  92.  FXPlug_FreeInfo,
  93.  FXPlug_InitPlugin,
  94.  FXPlug_ClosePlugin,
  95.  FXPlug_Filter,
  96.  FXPlug_OpenFilterGUI,
  97.  FXPlug_HandleFilterGUI,
  98.  FXPlug_CloseFilterGUI,
  99.  FXPlug_Identify_Image,
  100.  FXPlug_Load_Image,
  101.  FXPlug_Save_Image,
  102.  FXPlug_Handle_Ports,
  103.  FXPlug_Bye,
  104.  FXPlug_Launch,
  105.  FXPlug_rendergfx_rp,
  106.  FXPlug_PluginSetRegister,
  107.  
  108.  (APTR) ((LONG)-1)
  109. };
  110.  
  111.  
  112. extern struct ExampleBase *ExampleBase;
  113.  
  114. /* ----------------------------------------------------------------------------------------
  115.    ! InitLib:
  116.    !
  117.    ! This one is single-threaded by the Ramlib process. Theoretically you can do, what 
  118.    ! you like here, since you have full exclusive control over all the library code and data.
  119.    ! But due to some bugs in Ramlib V37-40, you can easily cause a deadlock when opening
  120.    ! certain libraries here (which open other libraries, that open other libraries, that...)
  121.    !
  122.    ---------------------------------------------------------------------------------------- */
  123.  
  124. struct ExampleBase * __saveds ASM InitLib( register __a6 struct ExecBase      *sysbase GNUCREG(a6),
  125.                     register __a0 struct SegList *seglist GNUCREG(a0),
  126.                     register __d0 struct ExampleBase *exb GNUCREG(d0))
  127. {
  128.  ExampleBase = exb;
  129.  
  130.  ExampleBase->exb_SysBase = sysbase;
  131.  ExampleBase->exb_SegList = seglist;
  132.  
  133.  if(L_OpenLibs()) return(ExampleBase);
  134.  
  135.  L_CloseLibs();
  136.  
  137.   {
  138.    ULONG negsize, possize, fullsize;
  139.    UBYTE *negptr = (UBYTE *) ExampleBase;
  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.  
  153.  return(NULL);
  154. }
  155.  
  156. /* ----------------------------------------------------------------------------------------
  157.    ! OpenLib:
  158.    !
  159.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  160.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  161.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  162.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  163.    ! function.
  164.    !
  165.    ! Currently you only can bypass this restriction by supplying your own semaphore
  166.    ! mechanism.
  167.    ---------------------------------------------------------------------------------------- */
  168.  
  169. struct ExampleBase * __saveds ASM OpenLib( register __a6 struct ExampleBase *ExampleBase GNUCREG(a6))
  170. {
  171.  #ifdef __MAXON__
  172.  GetBaseReg();
  173.  InitModules();
  174.  #endif
  175.  
  176.  ExampleBase->exb_LibNode.lib_OpenCnt++;
  177.  
  178.  ExampleBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  179.  
  180.  return(ExampleBase);
  181. }
  182.  
  183. /* ----------------------------------------------------------------------------------------
  184.    ! CloseLib:
  185.    !
  186.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  187.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  188.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  189.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  190.    ! function.
  191.    !
  192.    ! Currently you only can bypass this restriction by supplying your own semaphore
  193.    ! mechanism.
  194.    ---------------------------------------------------------------------------------------- */
  195.  
  196. APTR __saveds ASM CloseLib( register __a6 struct ExampleBase *ExampleBase GNUCREG(a6))
  197. {
  198.  ExampleBase->exb_LibNode.lib_OpenCnt--;
  199.  
  200.  if(!ExampleBase->exb_LibNode.lib_OpenCnt)
  201.   {
  202.    if(ExampleBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
  203.     {
  204.      return( ExpungeLib(ExampleBase) );
  205.     }
  206.   }
  207.  
  208.  return(NULL);
  209. }
  210.  
  211. /* ----------------------------------------------------------------------------------------
  212.    ! ExpungeLib:
  213.    !
  214.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  215.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  216.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  217.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  218.    ! function.
  219.    !
  220.    ! Currently you only could bypass this restriction by supplying your own semaphore
  221.    ! mechanism - but since expunging can't be done twice, one should avoid it here.
  222.    ---------------------------------------------------------------------------------------- */
  223.  
  224. APTR __saveds ASM ExpungeLib( register __a6 struct ExampleBase *exb GNUCREG(a6))
  225. {
  226.  struct ExampleBase *ExampleBase = exb;
  227.  struct SegList *seglist;
  228.  
  229.  if(!ExampleBase->exb_LibNode.lib_OpenCnt)
  230.   {
  231.    ULONG negsize, possize, fullsize;
  232.    UBYTE *negptr = (UBYTE *) ExampleBase;
  233.  
  234.    seglist = ExampleBase->exb_SegList;
  235.  
  236.    Remove((struct Node *)ExampleBase);
  237.  
  238.    L_CloseLibs();
  239.  
  240.    negsize  = ExampleBase->exb_LibNode.lib_NegSize;
  241.    possize  = ExampleBase->exb_LibNode.lib_PosSize;
  242.    fullsize = negsize + possize;
  243.    negptr  -= negsize;
  244.  
  245.    FreeMem(negptr, fullsize);
  246.  
  247.    #ifdef __MAXON__
  248.    CleanupModules();
  249.    #endif
  250.  
  251.    return(seglist);
  252.   }
  253.  
  254.  ExampleBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  255.  
  256.  return(NULL);
  257. }
  258.  
  259. /* ----------------------------------------------------------------------------------------
  260.    ! ExtFunct:
  261.    !
  262.    ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a Wait() call
  263.    ! would break this Forbid/Permit(), you are not allowed to start any operations that
  264.    ! may cause a Wait() during their processing. It's possible, that future OS versions
  265.    ! won't turn the multi-tasking off, but instead use semaphore protection for this
  266.    ! function.
  267.    !
  268.    ! Currently you only can bypass this restriction by supplying your own semaphore
  269.    ! mechanism - but since this function currently is unused, you should not touch
  270.    ! it, either.
  271.    ---------------------------------------------------------------------------------------- */
  272.  
  273. ULONG ASM ExtFuncLib(void)
  274. {
  275.  return(NULL);
  276. }
  277.  
  278. struct ExampleBase *ExampleBase = NULL;
  279.  
  280.  
  281. /* ----------------------------------------------------------------------------------------
  282.    ! __SASC stuff:
  283.    !
  284.    ! This is only for SAS/C - its intention is to turn off internal CTRL-C handling
  285.    ! for standard C function and to avoid calls to exit() et al.
  286.    ---------------------------------------------------------------------------------------- */
  287.  
  288. #ifdef __SASC
  289.  
  290. #ifdef ARK_OLD_STDIO_FIX
  291.  
  292. ULONG XCEXIT       = NULL; /* these symbols may be referenced by    */
  293. ULONG _XCEXIT      = NULL; /* some functions of sc.lib, but should  */
  294. ULONG ONBREAK      = NULL; /* never be used inside a shared library */
  295. ULONG _ONBREAK     = NULL;
  296. ULONG base         = NULL;
  297. ULONG _base        = NULL;
  298. ULONG ProgramName  = NULL;
  299. ULONG _ProgramName = NULL;
  300. ULONG StackPtr     = NULL;
  301. ULONG _StackPtr    = NULL;
  302. ULONG oserr        = NULL;
  303. ULONG _oserr       = NULL;
  304. ULONG OSERR        = NULL;
  305. ULONG _OSERR       = NULL;
  306.  
  307. #endif /* ARK_OLD_STDIO_FIX */
  308.  
  309. void __regargs __chkabort(void) { }  /* a shared library cannot be    */
  310. void __regargs _CXBRK(void)     { }  /* CTRL-C aborted when doing I/O */
  311.  
  312. #endif /* __SASC */
  313.