havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
[gnulib.git] / lib / dfa.h
blob65477897201caafd287ed446c7bbe273c75b3573
1 /* dfa.h - declarations for GNU deterministic regexp compiler
2 Copyright (C) 1988, 1998, 2007, 2009-2020 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc.,
17 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA */
19 /* Written June, 1988 by Mike Haertel */
21 #ifndef DFA_H_
22 #define DFA_H_
24 #include <regex.h>
25 #include <stdbool.h>
26 #include <stddef.h>
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 struct localeinfo; /* See localeinfo.h. */
34 /* Element of a list of strings, at least one of which is known to
35 appear in any R.E. matching the DFA. */
36 struct dfamust
38 bool exact;
39 bool begline;
40 bool endline;
41 char must[FLEXIBLE_ARRAY_MEMBER];
44 /* The dfa structure. It is completely opaque. */
45 struct dfa;
47 /* Needed when Gnulib is not used. */
48 #ifndef _GL_ATTRIBUTE_MALLOC
49 # define _GL_ATTRIBUTE_MALLOC
50 #endif
52 /* Entry points. */
54 /* Allocate a struct dfa. The struct dfa is completely opaque.
55 It should be initialized via dfasyntax or dfacopysyntax before other use.
56 The returned pointer should be passed directly to free() after
57 calling dfafree() on it. */
58 extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC;
60 /* DFA options that can be ORed together, for dfasyntax's 4th arg. */
61 enum
63 /* ^ and $ match only the start and end of data, and do not match
64 end-of-line within data. This is always false for grep, but
65 possibly true for other apps. */
66 DFA_ANCHOR = 1 << 0,
68 /* '\0' in data is end-of-line, instead of the traditional '\n'. */
69 DFA_EOL_NUL = 1 << 1
72 /* Initialize or reinitialize a DFA. The arguments are:
73 1. The DFA to operate on.
74 2. Information about the current locale.
75 3. Syntax bits described in regex.h.
76 4. Additional DFA options described above. */
77 extern void dfasyntax (struct dfa *, struct localeinfo const *,
78 reg_syntax_t, int);
80 /* Initialize or reinitialize a DFA from an already-initialized DFA. */
81 extern void dfacopysyntax (struct dfa *, struct dfa const *);
83 /* Parse the given string of given length into the given struct dfa. */
84 extern void dfaparse (char const *, ptrdiff_t, struct dfa *);
86 /* Allocate and return a struct dfamust from a struct dfa that was
87 initialized by dfaparse and not yet given to dfacomp. */
88 extern struct dfamust *dfamust (struct dfa const *);
90 /* Free the storage held by the components of a struct dfamust. */
91 extern void dfamustfree (struct dfamust *);
93 /* Compile the given string of the given length into the given struct dfa.
94 The last argument says whether to build a searching or an exact matcher.
95 A null first argument means the struct dfa has already been
96 initialized by dfaparse; the second argument is ignored. */
97 extern void dfacomp (char const *, ptrdiff_t, struct dfa *, bool);
99 /* Search through a buffer looking for a match to the given struct dfa.
100 Find the first occurrence of a string matching the regexp in the
101 buffer, and the shortest possible version thereof. Return a pointer to
102 the first character after the match, or NULL if none is found. BEGIN
103 points to the beginning of the buffer, and END points to the first byte
104 after its end. Note however that we store a sentinel byte (usually
105 newline) in *END, so the actual buffer must be one byte longer.
106 When ALLOW_NL is true, newlines may appear in the matching string.
107 If COUNT is non-NULL, increment *COUNT once for each newline processed.
108 Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
109 encountered a back-reference. The caller can use this to decide
110 whether to fall back on a backtracking matcher. */
111 extern char *dfaexec (struct dfa *d, char const *begin, char *end,
112 bool allow_nl, ptrdiff_t *count, bool *backref);
114 /* Return a superset for D. The superset matches everything that D
115 matches, along with some other strings (though the latter should be
116 rare, for efficiency reasons). Return a null pointer if no useful
117 superset is available. */
118 extern struct dfa *dfasuperset (struct dfa const *d) _GL_ATTRIBUTE_PURE;
120 /* The DFA is likely to be fast. */
121 extern bool dfaisfast (struct dfa const *) _GL_ATTRIBUTE_PURE;
123 /* Return true if every construct in D is supported by this DFA matcher. */
124 extern bool dfasupported (struct dfa const *) _GL_ATTRIBUTE_PURE;
126 /* Free the storage held by the components of a struct dfa. */
127 extern void dfafree (struct dfa *);
129 /* Error handling. */
131 /* dfawarn() is called by the regexp routines whenever a regex is compiled
132 that likely doesn't do what the user wanted. It takes a single
133 argument, a NUL-terminated string describing the situation. The user
134 must supply a dfawarn. */
135 extern void dfawarn (const char *);
137 /* dfaerror() is called by the regexp routines whenever an error occurs. It
138 takes a single argument, a NUL-terminated string describing the error.
139 The user must supply a dfaerror. */
140 extern _Noreturn void dfaerror (const char *);
142 #ifdef __cplusplus
144 #endif
146 #endif /* dfa.h */