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