3 * $Id: pcre.c,v 1.1 2003/11/29 23:38:37 mdw Exp $
5 * Matches Perl-compatible regular expressions
7 * (c) 2002 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Anag: a simple wordgame helper.
14 * Anag is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Anag is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Anag; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 2003/11/29 23:38:37 mdw
37 /*----- Header files ------------------------------------------------------*/
50 /*----- Data structures ---------------------------------------------------*/
52 typedef struct node_pcre
{
61 /*----- Main code ---------------------------------------------------------*/
63 /* --- Node matcher --- */
65 static int n_pcre(node
*nn
, const char *p
, size_t sz
)
67 node_pcre
*n
= (node_pcre
*)nn
;
70 e
= pcre_exec(n
->rx
, n
->rx_study
, p
, sz
, 0, 0, n
->ovec
, n
->ovecsz
);
73 if (e
== PCRE_ERROR_NOMATCH
)
75 die("unexpected PCRE error code %d", e
);
79 /* --- Node creation --- */
81 node
*pcrenode(const char *const *av
)
83 node_pcre
*n
= xmalloc(sizeof(*n
));
89 if ((n
->rx
= pcre_compile(av
[0], PCRE_CASELESS
, &e
, &eo
, 0)) == 0)
90 die("bad regular expression `%s': %s", av
[0], e
);
91 n
->rx_study
= pcre_study(n
->rx
, 0, &e
);
93 die("error studying pattern `%s': %s", av
[0], e
);
94 pcre_fullinfo(n
->rx
, n
->rx_study
, PCRE_INFO_BACKREFMAX
, &c
);
96 n
->ovec
= xmalloc(n
->ovecsz
* sizeof(*n
->ovec
));
100 /*----- That's all, folks -------------------------------------------------*/