home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / term232.lha / Source_Code / XPRXModem / libsup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-26  |  3.1 KB  |  120 lines

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