move rx.[hc].
[apps/madmutt.git] / lib-lib / rx.h
diff --git a/lib-lib/rx.h b/lib-lib/rx.h
new file mode 100644 (file)
index 0000000..48e295b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2006 Pierre Habouzit
+ */
+/*
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+/*
+ * this is an internal abstraction layer for regular expressions
+ */
+
+#ifndef _LIB_RX_H
+#define _LIB_RX_H
+
+#include <sys/types.h>
+#include <regex.h>
+
+#include "../lib/list.h"
+
+/* this is a non-standard option supported by Solaris 2.5.x which allows
+ * patterns of the form \<...\>
+ */
+#ifndef REG_WORDS
+#define REG_WORDS 0
+#endif
+
+typedef struct rx_t {
+    char *pattern;                /* printable version */
+    regex_t *rx;                  /* compiled expression */
+    int not;                      /* do not match */
+} rx_t;
+
+rx_t* rx_compile (const char*, int);
+void rx_delete(rx_t **);
+
+/* for handling lists */
+int rx_list_match(list2_t*, const char*);      /* match all items list agains string */
+int rx_lookup(list2_t*, const char*);          /* lookup pattern */
+
+#define REGCOMP(X,Y,Z)  regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
+#define REGEXEC(X,Y)    regexec(X, Y, 0, NULL, 0)
+
+#endif /* !_LIB_RX_H */