| 1 |
/***************************************************************************
|
| 2 |
regex.c - description
|
| 3 |
-------------------
|
| 4 |
begin : Mon Oct 11 2004
|
| 5 |
copyright : (C) 2004 by Leaflet
|
| 6 |
email : leaflet@leafok.com
|
| 7 |
***************************************************************************/
|
| 8 |
|
| 9 |
/***************************************************************************
|
| 10 |
* *
|
| 11 |
* This program is free software; you can redistribute it and/or modify *
|
| 12 |
* it under the terms of the GNU General Public License as published by *
|
| 13 |
* the Free Software Foundation; either version 2 of the License, or *
|
| 14 |
* (at your option) any later version. *
|
| 15 |
* *
|
| 16 |
***************************************************************************/
|
| 17 |
|
| 18 |
#include <stdlib.h>
|
| 19 |
#include <regex.h>
|
| 20 |
|
| 21 |
int ireg(const char *pattern, const char *string, size_t nmatch,
|
| 22 |
regmatch_t pmatch[])
|
| 23 |
{
|
| 24 |
regex_t *preg;
|
| 25 |
int cflags = 0, eflags = 0, ret;
|
| 26 |
|
| 27 |
preg = (regex_t *)malloc(sizeof(regex_t));
|
| 28 |
|
| 29 |
cflags = REG_EXTENDED;
|
| 30 |
|
| 31 |
if (pmatch == NULL)
|
| 32 |
cflags |= REG_NOSUB;
|
| 33 |
|
| 34 |
if (regcomp(preg, pattern, cflags) != 0)
|
| 35 |
{
|
| 36 |
log_error("Compile regular expression pattern failed\n");
|
| 37 |
free(preg);
|
| 38 |
return -1;
|
| 39 |
}
|
| 40 |
ret = regexec(preg, string, nmatch, pmatch, eflags);
|
| 41 |
|
| 42 |
regfree(preg);
|
| 43 |
free(preg);
|
| 44 |
|
| 45 |
// For debug
|
| 46 |
// log_std(ret?"error\n":"ok\n");
|
| 47 |
|
| 48 |
return ret;
|
| 49 |
}
|