home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / libs / regexp / examples / regtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-19  |  1.0 KB  |  54 lines

  1. /*
  2. ** regtest.c
  3. ** tests some RegExec() returncodes and error conditions
  4. ** (L) 1998 by Matthias Bethke
  5. */
  6.  
  7. #include <proto/exec.h>
  8. #include <proto/dos.h>
  9. #include <proto/regexp.h>
  10.  
  11. void TestExp(STRPTR,STRPTR);
  12.  
  13.  
  14. struct RegexpBase *RegexpBase;
  15.  
  16. LONG main(void)
  17. {
  18. LONG rcode=RETURN_OK;        // program return code
  19.  
  20. /* open regexp.library */
  21.     if(RegexpBase = (struct RegexpBase*)OpenLibrary("regexp.library",37))
  22.     {
  23.  
  24.         TestExp("..[a-zAB](123|456)+","xyg123456");
  25.         TestExp(NULL,"blah");
  26.         TestExp(".+",NULL);
  27.         TestExp("..[a[-zAB]","blah");
  28.         TestExp("?(.))","blah");
  29.         TestExp("ab*+cd","abcd");
  30.         CloseLibrary((struct Library*)RegexpBase);
  31.     } else
  32.     {
  33.         Printf("Can't open regexp.library V37+!\n");
  34.         rcode = RETURN_FAIL;
  35.     }
  36.     return rcode;
  37. }
  38.  
  39. void TestExp(STRPTR e, STRPTR s)
  40. {
  41. LONG ret,err;
  42. regexp *re;
  43.  
  44.     if(re = RegComp(e))
  45.     {
  46.         ret = RegExec(re,s);
  47.         err = IoErr();
  48.         RegFree(re);
  49.     } else err = IoErr();
  50.     Printf("RegSMatch(\"%s\",\"%s\") = %ld",e?e:(STRPTR)"NULL",s?s:(STRPTR)"NULL",ret);
  51.     if(err) Printf("  (IoErr()=%ld)\n",err);
  52.     else Printf("\n");
  53. }
  54.