home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / iffparse / iffparse_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-04  |  5.7 KB  |  227 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: iffparse_init.c,v 1.3 1997/02/04 14:08:53 digulla Exp $
  4.  
  5.     Desc: IFFParse initialization code.
  6.     Lang: English.
  7. */
  8. #include <stddef.h>
  9. #include <exec/types.h>
  10. #include <exec/resident.h>
  11. #include <proto/exec.h>
  12. #include <aros/libcall.h>
  13. #include <workbench/icon.h>
  14. #include <utility/utility.h>
  15. #include "initstruct.h"
  16. #include "iffparse_intern.h"
  17. #include <aros/debug.h>
  18.  
  19. struct inittable;
  20. extern const char name[];
  21. extern const char version[];
  22. extern const APTR inittabl[4];
  23. extern void *const IFFParse_functable[];
  24. extern const struct inittable datatable;
  25. extern struct IFFParseBase_intern *AROS_SLIB_ENTRY(init,IFFParse)();
  26. extern struct IFFParseBase_intern *AROS_SLIB_ENTRY(open,IFFParse)();
  27. extern BPTR AROS_SLIB_ENTRY(close,IFFParse)();
  28. extern BPTR AROS_SLIB_ENTRY(expunge,IFFParse)();
  29. extern int AROS_SLIB_ENTRY(null,IFFParse)();
  30. extern const char IFFParse_end;
  31.  
  32. int entry(void)
  33. {
  34.     /* If the library was executed by accident return error code. */
  35.     return -1;
  36. }
  37.  
  38. const struct Resident resident=
  39. {
  40.     RTC_MATCHWORD,
  41.     (struct Resident *)&resident,
  42.     (APTR)&IFFParse_end,
  43.     RTF_AUTOINIT,
  44.     1,
  45.     NT_LIBRARY,
  46.     0,
  47.     (char *)name,
  48.     (char *)&version[6],
  49.     (ULONG *)inittabl
  50. };
  51.  
  52. const char name[]=ICONNAME;
  53.  
  54. const char version[]="$VER: icon 1.0 (28.3.96)\n\015";
  55.  
  56. const APTR inittabl[4]=
  57. {
  58.     (APTR)sizeof(struct IFFParseBase_intern),
  59.     (APTR)IFFParse_functable,
  60.     (APTR)&datatable,
  61.     &AROS_SLIB_ENTRY(init,IFFParse)
  62. };
  63.  
  64. struct inittable
  65. {
  66.     S_CPYO(1,1,B);
  67.     S_CPYO(2,1,L);
  68.     S_CPYO(3,1,B);
  69.     S_CPYO(4,1,W);
  70.     S_CPYO(5,1,W);
  71.     S_CPYO(6,1,L);
  72.     S_END (IFFParse_end);
  73. };
  74.  
  75. #define O(n) offsetof(struct IFFParseBase_intern,n)
  76.  
  77. const struct inittable datatable=
  78. {
  79.     { { I_CPYO(1,B,O(library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  80.     { { I_CPYO(1,L,O(library.lib_Node.ln_Name)), { (IPTR)name } } },
  81.     { { I_CPYO(1,B,O(library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  82.     { { I_CPYO(1,W,O(library.lib_Version     )), { 1 } } },
  83.     { { I_CPYO(1,W,O(library.lib_Revision    )), { 0 } } },
  84.     { { I_CPYO(1,L,O(library.lib_IdString    )), { (IPTR)&version[6] } } },
  85.   I_END ()
  86. };
  87.  
  88. #define EasyHook(hook, func)  \
  89.     IFFParseBase->hook.h_Entry = HookEntry; \
  90.     IFFParseBase->hook.h_SubEntry = (IPTR(*)())func; \
  91.     IFFParseBase->hook.h_Data = IFFParseBase
  92.  
  93. #undef O
  94. #undef SysBase
  95.  
  96. AROS_LH2(struct IFFParseBase_intern *, init,
  97.  AROS_LHA(struct IFFParseBase_intern *, IFFParseBase, D0),
  98.  AROS_LHA(BPTR,               segList,   A0),
  99.      struct ExecBase *, SysBase, 0, IFFParse)
  100. {
  101.     AROS_LIBFUNC_INIT
  102.     /* This function is single-threaded by exec by calling Forbid. */
  103.  
  104.     /* Store arguments */
  105.     IFFParseBase->sysbase=SysBase;
  106.     IFFParseBase->seglist=segList;
  107.  
  108.     EasyHook(stophook,             StopFunc           );
  109.     EasyHook(prophook,             PropFunc           );
  110.     EasyHook(collectionhook,       CollectionFunc     );
  111.     EasyHook(doshook,              DOSStreamHandler   );
  112.     EasyHook(cliphook,             ClipStreamHandler  );
  113.     EasyHook(bufhook,              BufStreamHandler   );
  114.     EasyHook(collectionpurgehook,  CollectionPurgeFunc);
  115.     EasyHook(proppurgehook,        PropPurgeFunc      );
  116.  
  117.     /* You would return NULL here if the init failed. */
  118.     return IFFParseBase;
  119.     AROS_LIBFUNC_EXIT
  120. }
  121.  
  122. /* Use This from now on */
  123. #define SysBase IFFParseBase->sysbase
  124.  
  125. AROS_LH1(struct IFFParseBase_intern *, open,
  126.  AROS_LHA(ULONG, version, D0),
  127.      struct IFFParseBase_intern *, IFFParseBase, 1, IFFParse)
  128. {
  129.     AROS_LIBFUNC_INIT
  130.     /*
  131.     This function is single-threaded by exec by calling Forbid.
  132.     If you break the Forbid() another task may enter this function
  133.     at the same time. Take care.
  134.     */
  135.  
  136.     /* Keep compiler happy */
  137.     version=0;
  138.  
  139.     if (!DOSBase)
  140.     DOSBase = OpenLibrary (DOSNAME, 39);
  141.  
  142.     if (!DOSBase)
  143.     return NULL;
  144.  
  145.     if (!UtilityBase)
  146.     UtilityBase = OpenLibrary (UTILITYNAME, 39);
  147.  
  148.     if (!UtilityBase)
  149.     return NULL;
  150.  
  151.     /* I have one more opener. */
  152.     IFFParseBase->library.lib_OpenCnt++;
  153.     IFFParseBase->library.lib_Flags&=~LIBF_DELEXP;
  154.  
  155.     /* You would return NULL if the open failed. */
  156.     return IFFParseBase;
  157.     AROS_LIBFUNC_EXIT
  158. }
  159.  
  160. AROS_LH0(BPTR, close, struct IFFParseBase_intern *, IFFParseBase, 2, IFFParse)
  161. {
  162.     AROS_LIBFUNC_INIT
  163.     /*
  164.     This function is single-threaded by exec by calling Forbid.
  165.     If you break the Forbid() another task may enter this function
  166.     at the same time. Take care.
  167.     */
  168.  
  169.     /* I have one fewer opener. */
  170.     if(!--IFFParseBase->library.lib_OpenCnt)
  171.     {
  172.     if (DOSBase)
  173.         CloseLibrary (DOSBase);
  174.  
  175.     if (UtilityBase)
  176.         CloseLibrary (UtilityBase);
  177.  
  178.     /* Delayed expunge pending? */
  179.     if(IFFParseBase->library.lib_Flags&LIBF_DELEXP)
  180.         /* Then expunge the library */
  181.         return expunge();
  182.     }
  183.     return 0;
  184.     AROS_LIBFUNC_EXIT
  185. }
  186.  
  187. AROS_LH0(BPTR, expunge, struct IFFParseBase_intern *, IFFParseBase, 3, IFFParse)
  188. {
  189.     AROS_LIBFUNC_INIT
  190.  
  191.     BPTR ret;
  192.     /*
  193.     This function is single-threaded by exec by calling Forbid.
  194.     Never break the Forbid() or strange things might happen.
  195.     */
  196.  
  197.     /* Test for openers. */
  198.     if(IFFParseBase->library.lib_OpenCnt)
  199.     {
  200.     /* Set the delayed expunge flag and return. */
  201.     IFFParseBase->library.lib_Flags|=LIBF_DELEXP;
  202.     return 0;
  203.     }
  204.  
  205.     /* Get rid of the library. Remove it from the list. */
  206.     Remove(&IFFParseBase->library.lib_Node);
  207.  
  208.     /* Get returncode here - FreeMem() will destroy the field. */
  209.     ret=IFFParseBase->seglist;
  210.  
  211.     /* Free the memory. */
  212.     FreeMem((char *)IFFParseBase-IFFParseBase->library.lib_NegSize,
  213.     IFFParseBase->library.lib_NegSize+IFFParseBase->library.lib_PosSize);
  214.  
  215.     return ret;
  216.     AROS_LIBFUNC_EXIT
  217. }
  218.  
  219. AROS_LH0I(int, null, struct IFFParseBase_intern *, IFFParseBase, 4, IFFParse)
  220. {
  221.     AROS_LIBFUNC_INIT
  222.     return 0;
  223.     AROS_LIBFUNC_EXIT
  224. }
  225.  
  226.  
  227.