1 /* dfa.h - declarations for GNU deterministic regexp compiler
2 Copyright (C) 1988, 1998, 2007, 2009-2014 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)
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
17 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA */
19 /* Written June, 1988 by Mike Haertel */
25 /* Element of a list of strings, at least one of which is known to
26 appear in any R.E. matching the DFA. */
36 /* The dfa structure. It is completely opaque. */
41 /* Allocate a struct dfa. The struct dfa is completely opaque.
42 The returned pointer should be passed directly to free() after
43 calling dfafree() on it. */
44 extern struct dfa *dfaalloc (void);
46 /* Return the dfamusts associated with a dfa. */
47 extern struct dfamust *dfamusts (struct dfa const *);
49 /* dfasyntax() takes three arguments; the first sets the syntax bits described
50 earlier in this file, the second sets the case-folding flag, and the
51 third specifies the line terminator. */
52 extern void dfasyntax (reg_syntax_t, int, unsigned char);
54 /* Compile the given string of the given length into the given struct dfa.
55 Final argument is a flag specifying whether to build a searching or an
57 extern void dfacomp (char const *, size_t, struct dfa *, int);
59 /* Search through a buffer looking for a match to the given struct dfa.
60 Find the first occurrence of a string matching the regexp in the
61 buffer, and the shortest possible version thereof. Return a pointer to
62 the first character after the match, or NULL if none is found. BEGIN
63 points to the beginning of the buffer, and END points to the first byte
64 after its end. Note however that we store a sentinel byte (usually
65 newline) in *END, so the actual buffer must be one byte longer.
66 When NEWLINE is nonzero, newlines may appear in the matching string.
67 If COUNT is non-NULL, increment *COUNT once for each newline processed.
68 Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
69 encountered a back-reference (1) or not (0). The caller may use this
70 to decide whether to fall back on a backtracking matcher. */
71 extern char *dfaexec (struct dfa *d, char const *begin, char *end,
72 int newline, size_t *count, int *backref);
74 /* Return a superset for D. The superset matches everything that D
75 matches, along with some other strings (though the latter should be
76 rare, for efficiency reasons). Return a null pointer if no useful
77 superset is available. */
78 extern struct dfa *dfasuperset (struct dfa const *d) _GL_ATTRIBUTE_PURE;
80 /* The DFA is likely to be fast. */
81 extern bool dfaisfast (struct dfa const *) _GL_ATTRIBUTE_PURE;
83 /* Free the storage held by the components of a struct dfa. */
84 extern void dfafree (struct dfa *);
86 /* Entry points for people who know what they're doing. */
88 /* Initialize the components of a struct dfa. */
89 extern void dfainit (struct dfa *);
91 /* Incrementally parse a string of given length into a struct dfa. */
92 extern void dfaparse (char const *, size_t, struct dfa *);
94 /* Analyze a parsed regexp; second argument tells whether to build a searching
95 or an exact matcher. */
96 extern void dfaanalyze (struct dfa *, int);
98 /* Compute, for each possible character, the transitions out of a given
99 state, storing them in an array of integers. */
100 extern void dfastate (ptrdiff_t, struct dfa *, ptrdiff_t []);
102 /* Error handling. */
104 /* dfawarn() is called by the regexp routines whenever a regex is compiled
105 that likely doesn't do what the user wanted. It takes a single
106 argument, a NUL-terminated string describing the situation. The user
107 must supply a dfawarn. */
108 extern void dfawarn (const char *);
110 /* dfaerror() is called by the regexp routines whenever an error occurs. It
111 takes a single argument, a NUL-terminated string describing the error.
112 The user must supply a dfaerror. */
113 extern _Noreturn void dfaerror (const char *);
115 extern int using_utf8 (void);