home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Enlightenment
/
enl_DR-0.10.tar.gz
/
enl_DR-0.10.tar
/
enl
/
regexp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-24
|
1KB
|
75 lines
#include "enlightenment.h"
int isafter(int p, char *s1, char *s2)
{
int i,j;
int len,len2;
int match;
len=strlen(s1);
len2=strlen(s2);
match=0;
for(i=p;i<len;i++)
{
if (s1[i]==s2[0])
{
match=1;
for (j=0;j<len2;j++)
{
if ((i+j)>=len) return -1;
if (s1[i+j]!=s2[j]) match=0;
}
}
if (match) return i+len2;
}
return -1;
}
int matchregexp(char *rx, char *s)
{
int i,j,k,l,m;
int len, lenr;
int match;
char rx2[1024];
if (!s) return 0;
if (!rx) return 0;
len=strlen(s);
l=0;
lenr=0;
match=1;
if (rx[0]!='*')
{
m=0;
while ((rx[l]!='*')&&(rx[l]))
rx2[m++]=rx[l++];
rx2[m]=0;
lenr=strlen(rx2);
if (lenr>len) return 0;
for (i=0;i<lenr;i++)
{
if (s[i]!=rx[i]) return 0;
}
}
if ((!rx[l])&&(s[lenr])) return 0;
for (i=lenr;i<len;i++)
{
if (rx[l]) l++;
if (rx[l])
{
m=0;
while ((rx[l]!='*')&&(rx[l]))
rx2[m++]=rx[l++];
rx2[m]=0;
i=isafter(i,s,rx2);
if (i<0) return 0;
}
else
return match;
}
return match;
}