source: regex.c @ 1c6c4d3

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 1c6c4d3 was 1aee7d9, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
* Added RCS Id strings to all files. * 'show keymaps' shows details of all keymaps after summary list.
  • 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    return(-1);
33  }
34
35  return(0);
36}
37
38int owl_regex_compare(owl_regex *re, char *string) {
39  int out, ret;
40
41  /* if the regex is not set we match */
42  if (!owl_regex_is_set(re)) {
43    return(0);
44  }
45 
46  ret=regexec(&(re->re), string, 0, NULL, 0);
47  out=ret;
48  if (re->negate) {
49    out=!out;
50  }
51  return(out);
52}
53
54int owl_regex_is_set(owl_regex *re) {
55  if (re->string) return(1);
56  return(0);
57}
58
59char *owl_regex_get_string(owl_regex *re) {
60  return(re->string);
61}
62
63void owl_regex_copy(owl_regex *a, owl_regex *b) {
64  b->negate=a->negate;
65  b->string=owl_strdup(a->string);
66  memcpy(&(b->re), &(a->re), sizeof(regex_t));
67}
68
69void owl_regex_free(owl_regex *re) {
70  if (re->string) owl_free(re->string);
71
72  /* do we need to free the regular expression? */
73 
74}
Note: See TracBrowser for help on using the repository browser.