home *** CD-ROM | disk | FTP | other *** search
- /*
- ** regtest.c
- ** tests some RegExec() returncodes and error conditions
- ** (L) 1998 by Matthias Bethke
- */
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/regexp.h>
-
- void TestExp(STRPTR,STRPTR);
-
-
- struct RegexpBase *RegexpBase;
-
- LONG main(void)
- {
- LONG rcode=RETURN_OK; // program return code
-
- /* open regexp.library */
- if(RegexpBase = (struct RegexpBase*)OpenLibrary("regexp.library",37))
- {
-
- TestExp("..[a-zAB](123|456)+","xyg123456");
- TestExp(NULL,"blah");
- TestExp(".+",NULL);
- TestExp("..[a[-zAB]","blah");
- TestExp("?(.))","blah");
- TestExp("ab*+cd","abcd");
- CloseLibrary((struct Library*)RegexpBase);
- } else
- {
- Printf("Can't open regexp.library V37+!\n");
- rcode = RETURN_FAIL;
- }
- return rcode;
- }
-
- void TestExp(STRPTR e, STRPTR s)
- {
- LONG ret,err;
- regexp *re;
-
- if(re = RegComp(e))
- {
- ret = RegExec(re,s);
- err = IoErr();
- RegFree(re);
- } else err = IoErr();
- Printf("RegSMatch(\"%s\",\"%s\") = %ld",e?e:(STRPTR)"NULL",s?s:(STRPTR)"NULL",ret);
- if(err) Printf(" (IoErr()=%ld)\n",err);
- else Printf("\n");
- }
-