1 /********************************************************************************
2 * *
3 * Regular Expression Test *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1999,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * $Id: rex.cpp,v 1.18 2006/01/22 17:59:02 fox Exp $ *
9 ********************************************************************************/
10 #include "fx.h"
11 #include "FXRex.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16
17 /*
18
19
20 */
21
22 #define NCAP 10 // Must be less that or equal to 10
23
24
25 /*******************************************************************************/
26
27
28 // Start the whole thing
main(int argc,char ** argv)29 int main(int argc,char** argv){
30 FXRexError err;
31 FXRex rex;
32 FXbool ok;
33 FXint i;
34 FXint beg[NCAP];
35 FXint end[NCAP];
36 fxTraceLevel=101;
37 if(argc==1){
38 fprintf(stderr,"no arguments\n");
39 exit(1);
40 }
41 if(2<=argc){
42 err=rex.parse(argv[1],REX_NORMAL);
43 fprintf(stderr,"parse(\"%s\") = %s\n",argv[1],FXRex::getError(err));
44 }
45 if(3<=argc){
46 ok=rex.match(argv[2],strlen(argv[2]),beg,end,REX_FORWARD,NCAP);
47 if(ok){
48 fprintf(stderr,"match at %d:%d\n",beg[0],end[0]);
49 for(i=1; i<NCAP; i++){
50 fprintf(stderr,"capture at %d:%d\n",beg[i],end[i]);
51 }
52 for(i=beg[0]; i<end[0]; i++){
53 fprintf(stderr,"%c",argv[2][i]);
54 }
55 fprintf(stderr,"\n");
56 }
57 else{
58 fprintf(stderr,"no match\n");
59 }
60 }
61 return 1;
62 }
63
64