| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
regex.c - description |
regex.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 11 2004 |
begin : Mon Oct 11 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 6 |
email : leaflet@leafok.com |
email : leaflet@leafok.com |
| 7 |
***************************************************************************/ |
***************************************************************************/ |
| 8 |
|
|
| 9 |
/*************************************************************************** |
/*************************************************************************** |
| 18 |
#include <stdlib.h> |
#include <stdlib.h> |
| 19 |
#include <regex.h> |
#include <regex.h> |
| 20 |
|
|
| 21 |
int |
int ireg(const char *pattern, const char *string, size_t nmatch, |
| 22 |
ireg (const char *pattern, const char *string, size_t nmatch, |
regmatch_t pmatch[]) |
|
regmatch_t pmatch[]) |
|
| 23 |
{ |
{ |
| 24 |
regex_t *preg; |
regex_t *preg; |
| 25 |
int cflags = 0, eflags = 0, ret; |
int cflags = 0, eflags = 0, ret; |
| 26 |
|
|
| 27 |
preg = (regex_t *) malloc (sizeof (regex_t)); |
preg = (regex_t *)malloc(sizeof(regex_t)); |
| 28 |
|
|
| 29 |
cflags = REG_EXTENDED; |
cflags = REG_EXTENDED; |
| 30 |
|
|
| 31 |
if (pmatch == NULL) |
if (pmatch == NULL) |
| 32 |
cflags |= REG_NOSUB; |
cflags |= REG_NOSUB; |
| 33 |
|
|
| 34 |
if (regcomp (preg, pattern, cflags) != 0) |
if (regcomp(preg, pattern, cflags) != 0) |
| 35 |
{ |
{ |
| 36 |
log_error ("Compile regular expression pattern failed\n"); |
log_error("Compile regular expression pattern failed\n"); |
| 37 |
free (preg); |
free(preg); |
| 38 |
return -1; |
return -1; |
| 39 |
} |
} |
| 40 |
ret = regexec (preg, string, nmatch, pmatch, eflags); |
ret = regexec(preg, string, nmatch, pmatch, eflags); |
| 41 |
|
|
| 42 |
regfree (preg); |
regfree(preg); |
| 43 |
free (preg); |
free(preg); |
| 44 |
|
|
| 45 |
//For debug |
// For debug |
| 46 |
//log_std(ret?"error\n":"ok\n"); |
// log_std(ret?"error\n":"ok\n"); |
| 47 |
|
|
| 48 |
return ret; |
return ret; |
| 49 |
} |
} |