home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff330.lzh / XprKermit / protolib.c < prev    next >
C/C++ Source or Header  |  1990-03-02  |  3KB  |  163 lines

  1. /** protolib.c
  2. *
  3. *   DESCRIPTION:
  4. *   ===========
  5. *
  6. *    An exec library compiled with Aztec 3.40b, small model.
  7. *
  8. *    Based on "elib", an example library:
  9. *    created by jim mackraz using mylib.asm by neil katin.
  10. *    May be used and distributed providing this comment block
  11. *    is retained in the source code.
  12. *
  13. *   THIS VERSION:
  14. *   ============
  15. *
  16. *
  17. *    This version implements a protocol transfer handler.
  18. *    This file only handles the calls to Open, Close and Expunge.
  19. *
  20. *   AUTHOR/DATE:  W.G.J. Langeveld, February 1989.
  21. *   ============
  22. *
  23. **/
  24.  
  25. #include "protolib.h"
  26.  
  27. extern PFL   libfunctab[];   /* XPR function table (libface.asm)     */
  28. extern LONG  funkyInit();    /* hacked up version of Aztec crt0.a68   */
  29.  
  30. LONG XPRExpunge();
  31.  
  32. struct InitTable XPRInitTab =  {
  33.    sizeof (struct XPRBase),
  34.    libfunctab,
  35.    NULL,                     /* will initialize XPR data in funkymain() */
  36.    funkyInit
  37. };
  38.  
  39. extern UWORD XPRrevision;
  40.  
  41. extern char XPRname[];
  42. extern char XPRid[];
  43. extern struct Resident XPRRomTag;
  44.  
  45. unsigned long XPRO = ('X' << 24) | ('P' << 16) | ('R' << 8) | 'O';
  46.  
  47. /**
  48. *
  49. *   This function is Jim's C-language library initRoutine.  It is called
  50. *   by funkyInit() after register saves and small model initialization is
  51. *   done.
  52. *
  53. **/
  54. LONG funkymain(libbase, seglist)
  55. struct XPRBase *libbase;
  56. ULONG seglist;
  57. {
  58.    register   struct XPRBase *base;
  59. /*
  60. *   Cookie
  61. */
  62.    base = libbase;
  63. /*
  64. *   Debug kind of stuff
  65. */
  66.    base->mb_Cookie = XPRO;
  67.    base->mb_SegList = seglist;
  68. /*
  69. *   init. library structure (since I don't do automatic data init.)
  70. */
  71.    base->mb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  72.    base->mb_Lib.lib_Node.ln_Name = (char *) XPRname;   
  73.    base->mb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  74.    base->mb_Lib.lib_Version = XPRRomTag.rt_Version;
  75.    base->mb_Lib.lib_Revision = XPRrevision;
  76.    base->mb_Lib.lib_IdString = (APTR) XPRid;
  77.  
  78.    return;
  79. }
  80.  
  81.  
  82. /**
  83. *
  84. *   Open library. Baseptr in A6, version in D0.
  85. *
  86. **/
  87. LONG XPROpen(base)
  88. struct XPRBase *base;
  89. {
  90. /*
  91. *   Don't allow more than one open on this one. These libraries are
  92. *   typically non-reentrant.
  93. */
  94.    if (base->mb_Lib.lib_OpenCnt) return(NULL);
  95. /*
  96. *   mark us as having another customer
  97. */
  98.    base->mb_Lib.lib_OpenCnt++;
  99. /*
  100. *   prevent delayed expunges (standard procedure)
  101. */
  102.    base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;
  103.  
  104.    return ((LONG) base);
  105. }
  106.  
  107. /**
  108. *
  109. *   Close library
  110. *
  111. **/
  112. LONG XPRClose(base)
  113. struct XPRBase *base;
  114. {
  115.    LONG retval = 0;
  116.  
  117.    if ((--base->mb_Lib.lib_OpenCnt == 0) &&
  118.          (base->mb_Lib.lib_Flags & LIBF_DELEXP)) {
  119. /*
  120. *   No more people have me open,
  121. *   and I have a delayed expunge pending:
  122. *   return segment list.
  123. */
  124.       retval = XPRExpunge();
  125.    }
  126.  
  127.    return (retval);
  128. }
  129.  
  130. /**
  131. *
  132. *   Expunge library
  133. *
  134. **/
  135. LONG XPRExpunge(base)
  136. struct XPRBase *base;
  137. {
  138.    ULONG seglist = 0;
  139.    LONG libsize;
  140.  
  141.    if (base->mb_Lib.lib_OpenCnt == 0) {
  142. /*
  143. *   Really expunge: remove libbase and freemem
  144. */
  145.       seglist   = base->mb_SegList;
  146.  
  147.       Remove(base);
  148.  
  149.       libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;
  150.  
  151.       FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);
  152.    }
  153.    else {
  154.       base->mb_Lib.lib_Flags |= LIBF_DELEXP;
  155.    }
  156. /*
  157. *   Return NULL or real seglist
  158. */
  159.    return ((LONG) seglist);
  160. }
  161.  
  162.  
  163.