home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff247.lzh / XprLib / library / protolib.c < prev    next >
C/C++ Source or Header  |  1989-09-15  |  3KB  |  164 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. *   Note: if your library *is* reentrant, remove this statement.
  94. */
  95.    if (base->mb_Lib.lib_OpenCnt) return(NULL);
  96. /*
  97. *   mark us as having another customer
  98. */
  99.    base->mb_Lib.lib_OpenCnt++;
  100. /*
  101. *   prevent delayed expunges (standard procedure)
  102. */
  103.    base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;
  104.  
  105.    return ((LONG) base);
  106. }
  107.  
  108. /**
  109. *
  110. *   Close library
  111. *
  112. **/
  113. LONG XPRClose(base)
  114. struct XPRBase *base;
  115. {
  116.    LONG retval = 0;
  117.  
  118.    if ((--base->mb_Lib.lib_OpenCnt == 0) &&
  119.          (base->mb_Lib.lib_Flags & LIBF_DELEXP)) {
  120. /*
  121. *   No more people have me open,
  122. *   and I have a delayed expunge pending:
  123. *   return segment list.
  124. */
  125.       retval = XPRExpunge();
  126.    }
  127.  
  128.    return (retval);
  129. }
  130.  
  131. /**
  132. *
  133. *   Expunge library
  134. *
  135. **/
  136. LONG XPRExpunge(base)
  137. struct XPRBase *base;
  138. {
  139.    ULONG seglist = 0;
  140.    LONG libsize;
  141.  
  142.    if (base->mb_Lib.lib_OpenCnt == 0) {
  143. /*
  144. *   Really expunge: remove libbase and freemem
  145. */
  146.       seglist   = base->mb_SegList;
  147.  
  148.       Remove(base);
  149.  
  150.       libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;
  151.  
  152.       FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);
  153.    }
  154.    else {
  155.       base->mb_Lib.lib_Flags |= LIBF_DELEXP;
  156.    }
  157. /*
  158. *   Return NULL or real seglist
  159. */
  160.    return ((LONG) seglist);
  161. }
  162.  
  163.  
  164.