source: regex.c @ a6560fe

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