home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / libs / regexp / regexp.doc next >
Encoding:
Text File  |  1998-02-19  |  3.2 KB  |  124 lines

  1. TABLE OF CONTENTS
  2.  
  3. regexp.library/--background--
  4. regexp.library/RegComp
  5. regexp.library/RegFree
  6. regexp.library/RegExec
  7.  
  8. regexp.library/--background--
  9.  
  10.     /****************************************************************
  11.      *                    regexp.library                            *
  12.      *                   1998 by M.Bethke                           *
  13.      *                         V37.1                                *
  14.      ****************************************************************/
  15.  
  16.     regexp.library gives you the functionality of the NetBSD regexp
  17.     package through the standard AmigaOS shared library API.
  18.     Basically it works just like the dos.library pattern matching
  19.     functions (ParsePattern() / MatchPattern()), excpet that instead
  20.     of you providing your own buffer for the parsed expression the
  21.     library allocates one for you which you have to free later. A
  22.     typical call will look like this:
  23.  
  24.     BOOL MatchStrings(STRPTR pattern, STRPTR string)
  25.     {
  26.     regexp *re;
  27.     LONG result;
  28.  
  29.        if(re = RegComp(pattern))
  30.        {
  31.           result = RegExec(re,string);
  32.           if(result == -1)
  33.           {
  34.               result = 0;
  35.               Printf("Error matching pattern: #%ld\n",IoErr());
  36.           }
  37.        } else Printf("Error compiling pattern: #%ld!\n",IoErr());
  38.        return (BOOL)result;
  39.     }
  40.  
  41.     The translation of error codes is given in libraries/regexp.h
  42.  
  43. regexp.library/RegComp
  44.  
  45.     NAME
  46.     RegComp -- compile a regular expression to internal format
  47.  
  48.     SYNOPSIS
  49.     handle = RegComp(Expression)
  50.     D0         A0
  51.  
  52.     regexp *RegComp(STRPTR);
  53.  
  54.     FUNCTION
  55.     RegComp compiles a regular expression to an internal format that the
  56.     actual pattern matcher can understand. It's roughly the equivalent of
  57.     dos.library/ParsePattern() for AmigaDOS patternmatching.
  58.  
  59.     INPUTS
  60.     Expression = a pointer to the regular expression as a C string
  61.  
  62.     RESULT
  63.     regexp handle as defines in libraries/regexp.h. The structure of this
  64.     handle is defined in the same include file but should usually not be
  65.     messed with.
  66.  
  67.     SEE ALSO
  68.     RegFree()
  69.  
  70. regexp.library/RegFree
  71.  
  72.     NAME
  73.     RegFree -- free any storage allocated by RegComp().
  74.  
  75.     SYNOPSIS
  76.     RegFree (Handle)
  77.          A1
  78.  
  79.     void RegFree(regexp*);
  80.  
  81.     FUNCTION
  82.     Frees any storage that RegComp() may have attached to the regexp
  83.     handle it gave you. Basically, RegFree() does nothing more than a
  84.     FreeVec() at the moment but it's there to complete the API and to
  85.     allow future extensions.
  86.  
  87.     INPUTS
  88.     Handle    = a regexp handle as returned by RegComp()
  89.  
  90.     RESULT
  91.     nothing
  92.  
  93.     SEE ALSO
  94.     RegComp()
  95.  
  96. regexp.library/RegExec
  97.  
  98.     NAME
  99.     RegExec -- match a regular expression
  100.  
  101.     SYNOPSIS
  102.     Success = RegExec (Handle,String)
  103.     D0                 A0     A1
  104.  
  105.     LONG RegExec(regexp*, STRPTR);
  106.  
  107.     FUNCTION
  108.     This is the actual matching function. It takes a regexp handle and a
  109.     stringpointer and tries to match the expression the handle was created
  110.     from onto the string. A match is indicated by a return value of 1.
  111.  
  112.     INPUTS
  113.     Handle  = regexp handle as returned by RegComp()
  114.     String  = string to match the expression on
  115.  
  116.     RESULT
  117.      1 : Pattern matched string
  118.      0 : Pattern did not match
  119.     -1 : Failure while matching. IoErr() will return an error number
  120.           as defined in libraries/regexp.h in this case.
  121.  
  122.     SEE ALSO
  123.     RegComp(), RegFree()
  124.