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

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