| 1 |
sysadm |
1.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
|
| 22 |
|
|
ireg (const char *pattern, const char *string, size_t nmatch,
|
| 23 |
|
|
regmatch_t pmatch[])
|
| 24 |
|
|
{
|
| 25 |
|
|
regex_t *preg;
|
| 26 |
|
|
int cflags = 0, eflags = 0, ret;
|
| 27 |
|
|
|
| 28 |
|
|
preg = (regex_t *) malloc (sizeof (regex_t));
|
| 29 |
|
|
|
| 30 |
|
|
cflags = REG_EXTENDED;
|
| 31 |
|
|
|
| 32 |
|
|
if (pmatch == NULL)
|
| 33 |
|
|
cflags |= REG_NOSUB;
|
| 34 |
|
|
|
| 35 |
|
|
if (regcomp (preg, pattern, cflags) != 0)
|
| 36 |
|
|
{
|
| 37 |
|
|
log_error ("Compile regular expression pattern failed\n");
|
| 38 |
|
|
free (preg);
|
| 39 |
|
|
return -1;
|
| 40 |
|
|
}
|
| 41 |
|
|
ret = regexec (preg, string, nmatch, pmatch, eflags);
|
| 42 |
|
|
|
| 43 |
|
|
regfree (preg);
|
| 44 |
|
|
free (preg);
|
| 45 |
|
|
|
| 46 |
|
|
//For debug
|
| 47 |
|
|
//log_std(ret?"error\n":"ok\n");
|
| 48 |
|
|
|
| 49 |
|
|
return ret;
|
| 50 |
|
|
}
|