1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/********************************************************************************
* *
* Regular Expression Test *
* *
*********************************************************************************
* Copyright (C) 1999,2001 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* $Id: rex.cpp,v 1.14 2001/12/27 07:52:33 jeroen Exp $ *
********************************************************************************/
#include "fx.h"
#include "FXRex.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*/
#define NCAP 10 // Must be less that or equal to 10
/*******************************************************************************/
// Start the whole thing
int main(int argc,char** argv){
FXRexError err;
FXRex rex;
FXbool ok;
FXint i;
FXint beg[NCAP];
FXint end[NCAP];
fxTraceLevel=101;
if(argc==1){
fprintf(stderr,"no arguments\n");
exit(1);
}
if(2<=argc){
err=rex.parse(argv[1],REX_NORMAL);
fprintf(stderr,"parse(\"%s\") = %s\n",argv[1],FXRex::getError(err));
}
if(3<=argc){
ok=rex.match(argv[2],strlen(argv[2]),beg,end,REX_FORWARD,NCAP);
if(ok){
fprintf(stderr,"match at %d:%d\n",beg[0],end[0]);
for(i=1; i<NCAP; i++){
fprintf(stderr,"capture at %d:%d\n",beg[i],end[i]);
}
for(i=beg[0]; i<end[0]; i++){
fprintf(stderr,"%c",argv[2][i]);
}
fprintf(stderr,"\n");
}
else{
fprintf(stderr,"no match\n");
}
}
return 1;
}
// int lineno; // Error location
//
//
//
// void complain(char *s1,char * s2){
// fprintf(stderr,"attempt: %d: ",lineno);
// fprintf(stderr,s1,s2);
// }
//
//
//
// void attempt(char **fields) {
// char buf[BUFSIZ];
// regexp *r;
//
// //printf("line: %d\n",lineno);
//
// r=regcomp(fields[0]);
//
// if(r==NULL){
// if(*fields[2]!='c') complain("regcomp failure in \"%s\"",fields[0]);
// return;
// }
//
// if(*fields[2]=='c'){
// complain("unexpected regcomp success in \"%s\"",fields[0]);
// free(r);
// return;
// }
//
// if(!regexec(r,fields[1])){
// if(*fields[2]!='n') complain("regexec failure in \"%s\"",fields[0]);
// free(r);
// return;
// }
//
// if(*fields[2]=='n') {
// complain("unexpected regexec success in \"%s\"",fields[0]);
// free(r);
// return;
// }
//
// regsub(r,fields[3],buf);
//
// if(strcmp(buf,fields[4])!=0){
// complain("regsub result \"%s\" wrong",buf);
// free(r);
// return;
// }
//
// free(r);
// }
//
//
// void multiple(){
// char rbuf[BUFSIZ];
// char *field[5];
// char *scan;
// int i;
//
// lineno=1;
//
// // Perform test battery
// while(fgets(rbuf,sizeof(rbuf),stdin)!=NULL){
//
// // Strip return
// rbuf[strlen(rbuf)-1]='\0';
//
// // Split into fields
// scan=rbuf;
// for(i=0; i<5; i++){
// field[i]=scan;
// if(field[i]==NULL){
// printf("Bad testfile format\n");
// exit(1);
// }
// scan=strchr(scan,'\t');
// if(scan!=NULL) *scan++='\0';
// }
//
// // Perform test
// attempt(field);
// lineno++;
// }
// }
//
//
//
// // Run test battery
// int main(int argc,char *argv[]){
// char buf[BUFSIZ];
// regexp *r;
// const char *p;
// int i,m;
//
// if(argc==1){
// multiple();
// exit(0);
// }
//
// r=regcomp(argv[1]);
// printf("compile: \"%s\" %s\n",argv[1],r?"OK":"FAIL");
//
// if(argc>2){
// m=regexec(r,argv[2]);
// printf("match: \"%s\" %s ",argv[2],m?"MATCH":"FAIL");
// for(i=0; i<NSUBEXP && r->startp[i]!=NULL && r->endp[i]!=NULL; i++){
// printf("\"");
// for(p=r->startp[i]; p!=r->endp[i]; p++){
// printf("%c",*p);
// }
// printf("\" ");
// }
// printf("\n");
// }
//
// if(argc>3){
// regsub(r,argv[3],buf);
// printf("subst: \"%s\" is \"%s\"\n",argv[3],buf);
// }
//
// exit(0);
// }
|