-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* $Log: matchregex.c,v $ | ||
* Revision 1.6 2023-09-05 11:02:50+05:30 Cprogrammer | ||
* removed qregex.h for inclusion of matchregex in libqmail | ||
* | ||
* Revision 1.5 2021-08-21 18:50:43+05:30 Cprogrammer | ||
* handle regexec error | ||
* | ||
* Revision 1.4 2020-09-16 19:02:25+05:30 Cprogrammer | ||
* FreeBSD fix | ||
* | ||
* Revision 1.3 2019-03-07 00:52:18+05:30 Cprogrammer | ||
* added regcomp error cases for documentation | ||
* | ||
* Revision 1.2 2015-07-23 15:01:42+05:30 Cprogrammer | ||
* fixed comparision of constant '-1' with 0 | ||
* | ||
* Revision 1.1 2009-05-01 10:34:29+05:30 Cprogrammer | ||
* Initial revision | ||
* | ||
*/ | ||
#include <regex.h> | ||
#include <unistd.h> | ||
#include "stralloc.h" | ||
#include "error.h" | ||
#include "matchregex.h" | ||
|
||
#define REGEXEC(X,Y) regexec(&X, Y, (size_t) 0, (regmatch_t *) 0, (int) 0) | ||
|
||
int | ||
matchregex(char *text, char *regex, char **errStr) | ||
{ | ||
regex_t qreg; | ||
char errbuf[512]; | ||
int retval = 0; | ||
static stralloc err_str = { 0 }; | ||
|
||
if (errStr) | ||
*errStr = 0; | ||
/*- build the regex */ | ||
if ((retval = regcomp(&qreg, regex, REG_EXTENDED|REG_ICASE)) != 0) { | ||
regerror(retval, &qreg, errbuf, sizeof(errbuf)); | ||
regfree(&qreg); | ||
if (!stralloc_copys(&err_str, text) || | ||
!stralloc_cats(&err_str, ": ") || | ||
!stralloc_cats(&err_str, regex) || | ||
!stralloc_cats(&err_str, ": ") || | ||
!stralloc_cats(&err_str, errbuf) || | ||
!stralloc_0(&err_str)) | ||
return (AM_MEMORY_ERR); | ||
if (errStr) | ||
*errStr = err_str.s; | ||
switch (retval) | ||
{ | ||
case REG_BADBR: | ||
case REG_BADPAT: | ||
case REG_BADRPT: | ||
case REG_EBRACE: | ||
case REG_EBRACK: | ||
case REG_ECOLLATE: | ||
case REG_ECTYPE: | ||
#ifdef REG_EEND | ||
case REG_EEND: | ||
#endif | ||
case REG_EESCAPE: | ||
case REG_EPAREN: | ||
case REG_ERANGE: | ||
#ifdef REG_ESIZE | ||
case REG_ESIZE: | ||
#endif | ||
case REG_ESPACE: | ||
case REG_ESUBREG: | ||
default: | ||
return (AM_REGEX_ERR); | ||
} | ||
} | ||
/*- execute the regex */ | ||
if ((retval = regexec(&qreg, text, (size_t) NULL, (regmatch_t *) NULL, 0)) == -1) { | ||
if (!stralloc_copys(&err_str, text) || | ||
!stralloc_cats(&err_str, ": ") || | ||
!stralloc_cats(&err_str, regex) || | ||
!stralloc_cats(&err_str, ": ") || | ||
!stralloc_cats(&err_str, errbuf) || | ||
!stralloc_0(&err_str)) | ||
return (AM_MEMORY_ERR); | ||
if (errStr) | ||
*errStr = err_str.s; | ||
return -1; | ||
} | ||
regfree(&qreg); | ||
return (retval == REG_NOMATCH ? 0 : 1); | ||
} | ||
|
||
void | ||
getversion_matchregex_c() | ||
{ | ||
static char *x = "$Id: matchregex.c,v 1.6 2023-09-05 11:02:50+05:30 Cprogrammer Exp mbhangui $"; | ||
|
||
x++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* $Log: matchregex.h,v $ | ||
* Revision 1.3 2023-09-05 11:03:15+05:30 Cprogrammer | ||
* added error definitions for matchregex function | ||
* | ||
* Revision 1.2 2009-05-01 10:40:37+05:30 Cprogrammer | ||
* added errorstr argument to matchregex() | ||
* | ||
* Revision 1.1 2009-04-30 15:49:47+05:30 Cprogrammer | ||
* Initial revision | ||
* | ||
*/ | ||
/* | ||
* simple header file for the matchregex prototype | ||
*/ | ||
#ifndef _MATCHREGEX_H_ | ||
#define _MATCHREGEX_H_ | ||
|
||
#ifndef AM_MEMORY_ERR | ||
#define AM_MEMORY_ERR -1 | ||
#endif | ||
#ifndef AM_FILE_ERR | ||
#define AM_FILE_ERR -2 | ||
#endif | ||
#ifndef AM_LSEEK_ERR | ||
#define AM_LSEEK_ERR -3 | ||
#endif | ||
#ifndef AM_REGEX_ERR | ||
#define AM_REGEX_ERR -4 | ||
#endif | ||
#ifndef AM_CONFIG_ERR | ||
#define AM_CONFIG_ERR -5 | ||
#endif | ||
#define MAX_AM_ERR -5 | ||
|
||
int matchregex(char *, char *, char **); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ Release @version@-@release@ Start 24/04/2023 End XX/XX/XXXX | |
non-zero | ||
- 26/08/2023 | ||
25. tls/tls.c: refactored tls_get_method(), tls_set_method() | ||
- 05/09/2023 | ||
26. matchregex.[c,h]: added matchregex function | ||
|
||
* Sun Apr 23 2023 16:55:15 +0000 Manvendra Bhangui <[email protected]> 1.1.3-1.1%{?dist} | ||
Release 1.1.3-1.1 Start 08/02/2023 End 23/04/2023 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters