1 /* dfa.h - declarations for GNU deterministic regexp compiler
2 Copyright (C) 1988, 1998, 2007, 2009-2012 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 */
21 /* Element of a list of strings, at least one of which is known to
22 appear in any R.E. matching the DFA. */
30 /* The dfa structure. It is completely opaque. */
35 /* Allocate a struct dfa. The struct dfa is completely opaque.
36 The returned pointer should be passed directly to free() after
37 calling dfafree() on it. */
38 extern struct dfa *dfaalloc (void);
40 /* Return the dfamusts associated with a dfa. */
41 extern struct dfamust *dfamusts (struct dfa const *);
43 /* dfasyntax() takes three arguments; the first sets the syntax bits described
44 earlier in this file, the second sets the case-folding flag, and the
45 third specifies the line terminator. */
46 extern void dfasyntax (reg_syntax_t, int, unsigned char);
48 /* Compile the given string of the given length into the given struct dfa.
49 Final argument is a flag specifying whether to build a searching or an
51 extern void dfacomp (char const *, size_t, struct dfa *, int);
53 /* Search through a buffer looking for a match to the given struct dfa.
54 Find the first occurrence of a string matching the regexp in the
55 buffer, and the shortest possible version thereof. Return a pointer to
56 the first character after the match, or NULL if none is found. BEGIN
57 points to the beginning of the buffer, and END points to the first byte
58 after its end. Note however that we store a sentinel byte (usually
59 newline) in *END, so the actual buffer must be one byte longer.
60 When NEWLINE is nonzero, newlines may appear in the matching string.
61 If COUNT is non-NULL, increment *COUNT once for each newline processed.
62 Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
63 encountered a back-reference (1) or not (0). The caller may use this
64 to decide whether to fall back on a backtracking matcher. */
65 extern char *dfaexec (struct dfa *d, char const *begin, char *end,
66 int newline, size_t *count, int *backref);
68 /* Free the storage held by the components of a struct dfa. */
69 extern void dfafree (struct dfa *);
71 /* Entry points for people who know what they're doing. */
73 /* Initialize the components of a struct dfa. */
74 extern void dfainit (struct dfa *);
76 /* Incrementally parse a string of given length into a struct dfa. */
77 extern void dfaparse (char const *, size_t, struct dfa *);
79 /* Analyze a parsed regexp; second argument tells whether to build a searching
80 or an exact matcher. */
81 extern void dfaanalyze (struct dfa *, int);
83 /* Compute, for each possible character, the transitions out of a given
84 state, storing them in an array of integers. */
85 extern void dfastate (ptrdiff_t, struct dfa *, ptrdiff_t []);
89 /* dfawarn() is called by the regexp routines whenever a regex is compiled
90 that likely doesn't do what the user wanted. It takes a single
91 argument, a NUL-terminated string describing the situation. The user
92 must supply a dfawarn. */
93 extern void dfawarn (const char *);
95 /* dfaerror() is called by the regexp routines whenever an error occurs. It
96 takes a single argument, a NUL-terminated string describing the error.
97 The user must supply a dfaerror. */
98 extern _Noreturn void dfaerror (const char *);