home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 545b.lha / RexxHS / aztec / libsup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-07  |  3.5 KB  |  132 lines

  1. /*
  2.  * libsup.c -- Support routines for setting up an ARexx function
  3.  *             library, based on the libsup.c file included with Aztec C.
  4.  *
  5.  *  The changes that have beed made to this file are actually quite minor,
  6.  *  though we've renamed MyLibBase to ARLibBase...
  7.  */
  8.  
  9. #include "arexx.h"
  10. #include "arexxsyslib.h"
  11. #include "rexxhs.h"
  12. #include <exec/resident.h>
  13.  
  14. extern void myInit( void ); /* if you change this name, change libstart.asm */
  15.  
  16. LONG ARLibOpen( void );
  17. LONG ARLibClose( void );
  18. LONG ARLibExpunge( void );
  19.  
  20. #pragma amicall( ARLibBase, 0x06, ARLibOpen() )
  21. #pragma amicall( ARLibBase, 0x0c, ARLibClose() )
  22. #pragma amicall( ARLibBase, 0x12, ARLibExpunge() )
  23.  
  24. /* library initialization table, used for AUTOINIT libraries */
  25.  
  26. struct InitTable {
  27.     unsigned long   it_DataSize;          /* library data space size */
  28.     void          **it_FuncTable;         /* table of entry points */
  29.     void           *it_DataInit;          /* table of data initializers */
  30.     void          (*it_InitFunc)( void ); /* initialization function to run */
  31. };
  32.  
  33. void *LibFuncTab[] = {
  34.     ARLibOpen,
  35.     ARLibClose,
  36.     ARLibExpunge,
  37.     NULL,
  38.         Dispatch, /* <==== Our dispatch routine */
  39.     (void *) -1L
  40. };
  41.  
  42. struct InitTable myInitTab =  {
  43.     sizeof( struct ARLibBase ),
  44.     LibFuncTab,
  45.     0,                        /* will initialize my data in funkymain()    */
  46.     myInit
  47. };
  48.  
  49. #define MYREVISION    1    /* would be nice to auto-increment this        */
  50.  
  51. char myname[] = "rexxhs.library";
  52. char myid[]   = "RexxHostSupport 1.0 (July 15/91)\r\n";
  53.  
  54. extern struct Resident myRomTag;
  55.  
  56. /*
  57.  * _main -- Called from myInit when the library is first loaded into memory.
  58.  */
  59.  
  60. LONG _main( struct ARLibBase *ARLibBase, ULONG seglist )
  61.   {
  62.     ARLibBase->ml_SegList = seglist;
  63.  
  64.     ARLibBase->ml_Lib.lib_Node.ln_Type = NT_LIBRARY;
  65.     ARLibBase->ml_Lib.lib_Node.ln_Name = (char *) myname;
  66.     ARLibBase->ml_Lib.lib_Flags        = LIBF_SUMUSED | LIBF_CHANGED;
  67.     ARLibBase->ml_Lib.lib_Version      = myRomTag.rt_Version;
  68.     ARLibBase->ml_Lib.lib_Revision     = MYREVISION;
  69.     ARLibBase->ml_Lib.lib_IdString     = (APTR) myid;
  70.   }
  71.  
  72. /*
  73.  * ARLibOpen -- Increment the library open count and get rid of any
  74.  *              delayed expunge flag.
  75.  */
  76.  
  77. LONG ARLibOpen( void )
  78.   {
  79.     struct ARLibBase *ARLibBase;
  80.  
  81.     ARLibBase->ml_Lib.lib_OpenCnt++;
  82.     ARLibBase->ml_Lib.lib_Flags &= ~LIBF_DELEXP;
  83.  
  84.     return( (LONG) ARLibBase );
  85.   }
  86.  
  87. /*
  88.  * ARLibClose -- Decrement the library open count, and expunge if no
  89.  *               one has it open and the delayed expunge flag is set.
  90.  */
  91.  
  92. LONG ARLibClose( void )
  93.   {
  94.     struct ARLibBase *ARLibBase;
  95.     LONG              retval = 0;
  96.  
  97.     if( --ARLibBase->ml_Lib.lib_OpenCnt == 0 ){
  98.         if( ARLibBase->ml_Lib.lib_Flags & LIBF_DELEXP ){
  99.             retval = ARLibExpunge(); /* return segment list    */
  100.         }
  101.     }
  102.  
  103.     return( retval );
  104.   }
  105.  
  106. /*
  107.  * ARLibExpunge -- Remove the library if no one is using it, otherwise
  108.  *                 mark it for a delayed expunge.
  109.  */
  110.  
  111. LONG ARLibExpunge( void )
  112.   {
  113.     struct ARLibBase      *ARLibBase;
  114.     unsigned long          seglist = 0;
  115.     long                   libsize;
  116.     extern struct Library *DOSBase;
  117.  
  118.     if( ARLibBase->ml_Lib.lib_OpenCnt == 0 ){
  119.         seglist = ARLibBase->ml_SegList;
  120.         Remove( &ARLibBase->ml_Lib.lib_Node );
  121.  
  122.         libsize = ARLibBase->ml_Lib.lib_NegSize+ARLibBase->ml_Lib.lib_PosSize;
  123.         FreeMem( (char *)ARLibBase-ARLibBase->ml_Lib.lib_NegSize, libsize );
  124.         CloseLibrary(DOSBase); /* keep the counts even */
  125.     } else {
  126.         ARLibBase->ml_Lib.lib_Flags |= LIBF_DELEXP;
  127.     }
  128.  
  129.     return( (LONG) seglist );
  130.   }
  131.  
  132.