disclosing genocided/extinct monsters
[aNetHack.git] / sys / share / pmatchregex.c
blobd41e441c1b4cf8f564ca146980ff1cdf7f1b11c4
1 /* NetHack 3.6 posixregex.c $NHDT-Date: 1434446946 2015/06/16 09:29:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.1 $ */
2 /* Copyright (c) Sean Hunt 2015. */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
7 /* Implementation of the regex engine using pmatch().
8 * [Switched to pmatchi() so as to ignore case.]
10 * This is a fallback ONLY and should be avoided where possible, as it results
11 * in regexes not behaving as POSIX extended regular expressions. As a result,
12 * configuration files for NetHacks built with this engine will not be
13 * portable to ones built with an alternate regex engine.
16 const char regex_id[] = "pmatchregex";
18 struct nhregex {
19 const char *pat;
22 struct nhregex *
23 regex_init()
25 struct nhregex *re;
27 re = (struct nhregex *) alloc(sizeof (struct nhregex));
28 re->pat = (const char *) 0;
29 return re;
32 boolean
33 regex_compile(s, re)
34 const char *s;
35 struct nhregex *re;
37 if (!re)
38 return FALSE;
39 if (re->pat)
40 free((genericptr_t) re->pat);
42 re->pat = dupstr(s);
43 return TRUE;
46 const char *
47 regex_error_desc(re)
48 struct nhregex *re UNUSED;
50 return "pattern match compilation error";
53 boolean
54 regex_match(s, re)
55 const char *s;
56 struct nhregex *re;
58 if (!re || !re->pat || !s)
59 return FALSE;
61 return pmatchi(re->pat, s);
64 void
65 regex_free(re)
66 struct nhregex *re;
68 if (re) {
69 if (re->pat)
70 free((genericptr_t) re->pat);
71 free((genericptr_t) re);