Move (un)?lists and (un)subscribe to MAlias.
[apps/madmutt.git] / lib-lib / rx.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * This file is part of mutt-ng, see http://www.muttng.org/.
21  * It's licensed under the GNU General Public License,
22  * please see the file GPL in the top level source directory.
23  */
24
25 /*
26  * this is an internal abstraction layer for regular expressions
27  */
28
29 #ifndef MUTT_LIB_LIB_RX_H
30 #define MUTT_LIB_LIB_RX_H
31
32 #include "lib-lib.h"
33
34 /* this is a non-standard option supported by Solaris 2.5.x which allows
35  * patterns of the form \<...\>
36  */
37 #ifndef REG_WORDS
38 #define REG_WORDS 0
39 #endif
40
41 typedef struct rx_t {
42     struct rx_t *next;
43
44     unsigned neg : 1;             /* do not match */
45     int flags;
46     int nmatch;                   /* nb matches */
47
48     char *pattern;                /* printable version */
49     char *tpl;                    /* out template */
50
51     regex_t *rx;                  /* compiled expression */
52 } rx_t;
53
54 rx_t *rx_compile(const char*, int);
55 void rx_wipe(rx_t *);
56 rx_t *rx_dup(rx_t *);
57 DO_DELETE(rx_t, rx);
58 DO_SLIST(rx_t, rx, rx_delete);
59
60 int  rx_validate(const char*, char*, ssize_t);
61 void rx_set_template(rx_t *, const char*);
62 int  rx_sanitize_string(char *, ssize_t, const char *);
63
64 /* for handling lists */
65 rx_t **rx_lookup(rx_t**, const char*);       /* lookup pattern */
66
67 int rx_list_match(rx_t *, const char*);      /* match all items list agains string */
68 void rx_list_add(rx_t **, rx_t *);
69 void rx_list_remove(rx_t **, const rx_t *);
70
71 int rx_list_match2(rx_t *l, const char *s, char *dst, int dlen);
72 void rx_list_add2(rx_t **, rx_t **);
73
74 #define REGCOMP(X,Y,Z)  regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
75 #define REGEXEC(X,Y)    regexec(X, Y, 0, NULL, 0)
76
77 #endif /* !MUTT_LIB_LIB_RX_H */