barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change
on this file since a053de8 was
e187445,
checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
|
reformatted filter, filterelement and regex to new code style
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[7d4fbcd] | 1 | #include <string.h> |
---|
| 2 | #include "owl.h" |
---|
| 3 | |
---|
[1aee7d9] | 4 | static const char fileIdent[] = "$Id$"; |
---|
| 5 | |
---|
[e187445] | 6 | void owl_regex_init(owl_regex *re) |
---|
| 7 | { |
---|
[7d4fbcd] | 8 | re->negate=0; |
---|
| 9 | re->string=NULL; |
---|
| 10 | } |
---|
| 11 | |
---|
[e187445] | 12 | int owl_regex_create(owl_regex *re, char *string) |
---|
| 13 | { |
---|
[7d4fbcd] | 14 | int ret; |
---|
| 15 | char buff1[LINE], buff2[LINE]; |
---|
| 16 | char *ptr; |
---|
| 17 | |
---|
| 18 | re->string=owl_strdup(string); |
---|
| 19 | |
---|
| 20 | ptr=string; |
---|
| 21 | re->negate=0; |
---|
| 22 | if (string[0]=='!') { |
---|
| 23 | ptr++; |
---|
| 24 | re->negate=1; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | /* set the regex */ |
---|
| 28 | ret=regcomp(&(re->re), ptr, REG_EXTENDED|REG_ICASE); |
---|
| 29 | if (ret) { |
---|
| 30 | regerror(ret, NULL, buff1, LINE); |
---|
| 31 | sprintf(buff2, "Error in regular expression: %s", buff1); |
---|
| 32 | owl_function_makemsg(buff2); |
---|
| 33 | owl_free(re->string); |
---|
[a6560fe] | 34 | re->string=NULL; |
---|
[7d4fbcd] | 35 | return(-1); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | return(0); |
---|
| 39 | } |
---|
| 40 | |
---|
[e187445] | 41 | int owl_regex_compare(owl_regex *re, char *string) |
---|
| 42 | { |
---|
[7d4fbcd] | 43 | int out, ret; |
---|
| 44 | |
---|
| 45 | /* if the regex is not set we match */ |
---|
| 46 | if (!owl_regex_is_set(re)) { |
---|
| 47 | return(0); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | ret=regexec(&(re->re), string, 0, NULL, 0); |
---|
| 51 | out=ret; |
---|
| 52 | if (re->negate) { |
---|
| 53 | out=!out; |
---|
| 54 | } |
---|
| 55 | return(out); |
---|
| 56 | } |
---|
| 57 | |
---|
[e187445] | 58 | int owl_regex_is_set(owl_regex *re) |
---|
| 59 | { |
---|
[7d4fbcd] | 60 | if (re->string) return(1); |
---|
| 61 | return(0); |
---|
| 62 | } |
---|
| 63 | |
---|
[e187445] | 64 | char *owl_regex_get_string(owl_regex *re) |
---|
| 65 | { |
---|
[7d4fbcd] | 66 | return(re->string); |
---|
| 67 | } |
---|
| 68 | |
---|
[e187445] | 69 | void owl_regex_copy(owl_regex *a, owl_regex *b) |
---|
| 70 | { |
---|
[7d4fbcd] | 71 | b->negate=a->negate; |
---|
| 72 | b->string=owl_strdup(a->string); |
---|
| 73 | memcpy(&(b->re), &(a->re), sizeof(regex_t)); |
---|
| 74 | } |
---|
| 75 | |
---|
[e187445] | 76 | void owl_regex_free(owl_regex *re) |
---|
| 77 | { |
---|
[7d4fbcd] | 78 | if (re->string) owl_free(re->string); |
---|
| 79 | |
---|
| 80 | /* do we need to free the regular expression? */ |
---|
| 81 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.