home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 404.lha / xprxmodem.library_v34.1 / libsup.c < prev    next >
C/C++ Source or Header  |  1990-08-06  |  3KB  |  119 lines

  1. #include "xprxmodem.h"
  2.  
  3. void myInit(void);
  4. long myOpen(void);
  5. long myClose(void);
  6. long myExpunge(void);
  7.  
  8. #pragma amicall(XProtocolBase, 0x06, myOpen())
  9. #pragma amicall(XProtocolBase, 0x0c, myClose())
  10. #pragma amicall(XProtocolBase, 0x12, myExpunge())
  11.  
  12. /* library initialization table, used for AUTOINIT libraries             */
  13. struct InitTable {
  14.     unsigned long it_DataSize;    /* library data space size         */
  15.     void **it_FuncTable;    /* table of entry points             */
  16.     void *it_DataInit;    /* table of data initializers         */
  17.     void (*it_InitFunc) (void);    /* initialization function to run     */
  18. };
  19.  
  20. static void *libfunctab[] =
  21. {                /* my function table */
  22.     myOpen,            /* standard open     */
  23.     myClose,        /* standard close     */
  24.     myExpunge,        /* standard expunge     */
  25.     0,
  26.     XProtocolCleanup,
  27.     XProtocolSetup,
  28.     XProtocolSend,
  29.     XProtocolReceive,
  30.     (void *) -1        /* end of function vector table */
  31. };
  32.  
  33. struct InitTable myInitTab =
  34. {
  35.     sizeof(struct XProtocolBase),
  36.     libfunctab,
  37.     0,            /* will initialize my data in funkymain()     */
  38.     myInit
  39. };
  40.  
  41. #define MYREVISION    34    /* would be nice to auto-increment this         */
  42.  
  43. char myname[] = "xprxmodem.library";
  44. char myid[] = "xprxmodem 34.1 (" __DATE__ ")\n";
  45.  
  46. extern struct Resident myRomTag;
  47.  
  48. struct IntuitionBase *IntuitionBase = 0;
  49.  
  50. void _main(struct XProtocolBase * XProtocolBase, unsigned long seglist)
  51. {
  52.     XProtocolBase->xp_SegList = seglist;
  53.  
  54.     /* ----- init. library structure  -----         */
  55.     XProtocolBase->xp_Lib.lib_Node.ln_Type = NT_LIBRARY;
  56.     XProtocolBase->xp_Lib.lib_Node.ln_Name = (char *) myname;
  57.     XProtocolBase->xp_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  58.     XProtocolBase->xp_Lib.lib_Version = myRomTag.rt_Version;
  59.     XProtocolBase->xp_Lib.lib_Revision = MYREVISION;
  60.     XProtocolBase->xp_Lib.lib_IdString = (APTR) myid;
  61.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
  62. }
  63.  
  64. long myOpen(void)
  65. {
  66.     struct XProtocolBase *XProtocolBase;
  67.  
  68.     /* mark us as having another customer                     */
  69.     XProtocolBase->xp_Lib.lib_OpenCnt++;
  70.  
  71.     /* prevent delayed expunges (standard procedure)         */
  72.     XProtocolBase->xp_Lib.lib_Flags &= ~LIBF_DELEXP;
  73.  
  74.     return ((long) XProtocolBase);
  75. }
  76.  
  77. long myClose(void)
  78. {
  79.     struct XProtocolBase *XProtocolBase;
  80.     long retval = 0;
  81.  
  82.     if (--XProtocolBase->xp_Lib.lib_OpenCnt == 0) {
  83.         if (XProtocolBase->xp_Lib.lib_Flags & LIBF_DELEXP) {
  84.  
  85.             /*
  86.              * no more people have me open, and I have a delayed
  87.              * expunge pending
  88.              */
  89.             retval = myExpunge();    /* return segment list     */
  90.         }
  91.     }
  92.     return (retval);
  93. }
  94.  
  95. long myExpunge(void)
  96. {
  97.     struct XProtocolBase *XProtocolBase;
  98.     unsigned long seglist = 0;
  99.     long libsize;
  100.  
  101.     if (XProtocolBase->xp_Lib.lib_OpenCnt == 0) {
  102.  
  103.         CloseLibrary((struct Library *) IntuitionBase);
  104.  
  105.         /* really expunge: remove libbase and freemem */
  106.         seglist = XProtocolBase->xp_SegList;
  107.  
  108.         Remove(&XProtocolBase->xp_Lib.lib_Node);
  109.         /* i'm no longer an installed library */
  110.  
  111.         libsize = XProtocolBase->xp_Lib.lib_NegSize + XProtocolBase->xp_Lib.lib_PosSize;
  112.         FreeMem((char *) XProtocolBase - XProtocolBase->xp_Lib.lib_NegSize, libsize);
  113.     } else
  114.         XProtocolBase->xp_Lib.lib_Flags |= LIBF_DELEXP;
  115.  
  116.     /* return NULL or real seglist */
  117.     return ((long) seglist);
  118. }
  119.