]> git.neil.brown.name Git - edlib.git/blob - rexel.h
TODO: clean out done items.
[edlib.git] / rexel.h
1 /*
2  * Copyright Neil Brown ©2015-2023 <neil@brown.name>
3  * May be distributed under terms of GPLv2 - see file:COPYING
4  */
5
6 #include <wchar.h>
7 #include "safe.h"
8
9 struct match_state;
10 enum rxl_found {
11         RXL_NOMATCH,    /* No match has been found at all */
12         RXL_CONTINUE,   /* No match here, but it is worth looking further */
13         RXL_DONE,       /* A match was previously reported, but no further match
14                          * can be found as we are anchored on that match.
15                          */
16         RXL_MATCH,      /* There was a match once the char was processed */
17         RXL_MATCH_FLAG, /* A match was found due to flags, but not once char was
18                          * processed.
19                          */
20 };
21 unsigned short *rxl_parse(const char *patn safe, int *lenp, int nocase);
22 unsigned short *safe rxl_parse_verbatim(const char *patn safe, int nocase);
23
24 struct match_state *safe rxl_prepare(unsigned short *rxl safe, int flags);
25 #define RXLF_ANCHORED   1
26 #define RXLF_BACKTRACK  2
27
28 int rxl_prefix(unsigned short *rxl safe, char *ret safe, int max);
29 int rxl_fast_match(const char *needle safe, int nlen,
30                    const char *haystack safe, int hlen);
31 enum rxl_found rxl_advance(struct match_state *st safe, wint_t ch);
32 int rxl_info(struct match_state *st safe, int *lenp safe, int *totalp,
33               int *startp, int *since_startp);
34 int rxl_capture(struct match_state *st safe, int cap, int which,
35                 int *startp safe, int *lenp safe);
36 char *rxl_interp(struct match_state *s safe, const char *form safe);
37 void rxl_free_state(struct match_state *s);
38
39 /* These are 'or'ed in with the ch and reflect state *before*
40  * the ch.  For state at EOF, use WEOF for the ch
41  */
42 #define RXL_SOD         (1 << 22)
43 #define RXL_SOL         (1 << 23)
44 #define RXL_SOW         (1 << 24)
45 #define RXL_NOWBRK      (1 << 25) /* Not at a word boundary */
46 #define RXL_POINT       (1 << 26)
47 #define RXL_EOW         (1 << 27)
48 #define RXL_EOL         (1 << 28)
49 #define RXL_EOD         (1 << 29)
50 #define RXL_ANCHOR      (1 << 30) /* Set RXLF_ANCHORED from there on */
51 #define RXL_LAST RXL_ANCHOR