home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / RegexLibrary_v1.0 / library.c < prev    next >
C/C++ Source or Header  |  1989-08-06  |  3KB  |  128 lines

  1. /*
  2.  *  Amiga Shared library code for the GNU regular expression package.
  3.  *  Edwin Hoogerbeets 18/07/89
  4.  *
  5.  *  This file may be copied and distributed under the GNU Public
  6.  *  Licence. See the comment at the top of regex.c for details.
  7.  *
  8.  *  Adapted from Elib by Jim Mackraz, mklib by Edwin Hoogerbeets, and the
  9.  *  GNU regular expression package by the Free Software Foundation.
  10.  */
  11.  
  12.  
  13. /* created by jim mackraz using mylib.asm by neil katin
  14.  * may be used and distributed providing this comment block
  15.  * is retained in the source code
  16.  */
  17. #define NULL 0L
  18. #include "library.h"
  19. #include <exec/memory.h>
  20.  
  21. extern  PFL     libfunctab[];   /* my function table (libface.asm)      */
  22. extern  LONG    funkyInit();    /* hacked up version of Aztec crt0.a68  */
  23.  
  24. LONG    myExpunge();
  25.  
  26. struct InitTable myInitTab =  {
  27.   sizeof (struct RegexBase),
  28.   libfunctab,
  29.   NULL,           /* will initialize my data in funkymain()       */
  30.   funkyInit
  31. };
  32.  
  33. #define MYREVISION      0   /* would be nice to auto-increment this     */
  34.  
  35. extern char myname[];
  36. extern char myid[];
  37.  
  38. extern struct Resident  myRomTag;
  39.  
  40. /*
  41.  * this function is my C-language library initRoutine.  It is called
  42.  * by funkyInit() after register saves and small model initialization is
  43.  * done.
  44.  */
  45.  
  46. LONG
  47. funkymain(libbase, seglist)
  48. struct  RegexBase  *libbase;
  49. ULONG                   seglist;
  50. {
  51.   register        struct RegexBase *base;
  52.  
  53.   /* cookie       */
  54.   base = libbase;
  55.   base->rb_Cookie = 0xDEAD1234;   /* debug kind of stuff                  */
  56.   base->rb_SegList = seglist;
  57.  
  58.   /* init. library structure (since I don't do automatic data init.)      */
  59.   base->rb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  60.   base->rb_Lib.lib_Node.ln_Name = (char *) myname;
  61.   base->rb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  62.   base->rb_Lib.lib_Version = myRomTag.rt_Version;
  63.   base->rb_Lib.lib_Revision = MYREVISION;
  64.   base->rb_Lib.lib_IdString = (APTR) myid;
  65.  
  66.   return(0);
  67. }
  68.  
  69. LONG
  70. myOpen(base)    /* baseptr in A6, version in D0 */
  71. struct  RegexBase *base;
  72. {
  73.   /* mark us as having another customer                                   */
  74.   base->rb_Lib.lib_OpenCnt++;
  75.  
  76.   /* prevent delayed expunges (standard procedure)                */
  77.   base->rb_Lib.lib_Flags &= ~LIBF_DELEXP;
  78.  
  79.   return ((LONG) base);
  80. }
  81.  
  82. LONG
  83. myClose(base)
  84. struct  RegexBase *base;
  85. {
  86.   LONG    retval = 0;
  87.  
  88.   if ((--base->rb_Lib.lib_OpenCnt == 0) &&
  89.                   (base->rb_Lib.lib_Flags & LIBF_DELEXP))
  90.   {
  91.     /* no more people have me open,
  92.      * and I have a delayed expunge pending
  93.      */
  94.     retval = myExpunge(); /* return segment list    */
  95.   }
  96.  
  97.   return (retval);
  98. }
  99.  
  100. LONG
  101. myExpunge(base)
  102. struct  RegexBase  *base;
  103. {
  104.   ULONG seglist = 0;
  105.   LONG  libsize;
  106.  
  107.   if (base->rb_Lib.lib_OpenCnt == 0)
  108.   {
  109.     /* really expunge: remove libbase and freemem   */
  110.  
  111.     seglist = base->rb_SegList;
  112.  
  113.     Remove(base);
  114.  
  115.     libsize = base->rb_Lib.lib_NegSize + base->rb_Lib.lib_PosSize;
  116.     FreeMem((char *) base - base->rb_Lib.lib_NegSize, (LONG) libsize);
  117.   }
  118.   else
  119.   {
  120.     base->rb_Lib.lib_Flags &= LIBF_DELEXP;
  121.   }
  122.  
  123.  
  124.   /* return NULL or real seglist */
  125.   return ((LONG) seglist);
  126. }
  127.  
  128.