Blame lib/dfa.h

Packit 709fb3
/* dfa.h - declarations for GNU deterministic regexp compiler
Packit 709fb3
   Copyright (C) 1988, 1998, 2007, 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
   This program is free software; you can redistribute it and/or modify
Packit 709fb3
   it under the terms of the GNU General Public License as published by
Packit 709fb3
   the Free Software Foundation; either version 3, or (at your option)
Packit 709fb3
   any later version.
Packit 709fb3
Packit 709fb3
   This program is distributed in the hope that it will be useful,
Packit 709fb3
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
   GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
   You should have received a copy of the GNU General Public License
Packit 709fb3
   along with this program; if not, write to the Free Software
Packit 709fb3
   Foundation, Inc.,
Packit 709fb3
   51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA */
Packit 709fb3
Packit 709fb3
/* Written June, 1988 by Mike Haertel */
Packit 709fb3
Packit 709fb3
#include <regex.h>
Packit 709fb3
#include <stdbool.h>
Packit 709fb3
#include <stddef.h>
Packit 709fb3
Packit 709fb3
#if 3 <= __GNUC__
Packit 709fb3
# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
Packit 709fb3
#else
Packit 709fb3
# define _GL_ATTRIBUTE_MALLOC
Packit 709fb3
#endif
Packit 709fb3
Packit 709fb3
struct localeinfo; /* See localeinfo.h.  */
Packit 709fb3
Packit 709fb3
/* Element of a list of strings, at least one of which is known to
Packit 709fb3
   appear in any R.E. matching the DFA. */
Packit 709fb3
struct dfamust
Packit 709fb3
{
Packit 709fb3
  bool exact;
Packit 709fb3
  bool begline;
Packit 709fb3
  bool endline;
Packit 709fb3
  char *must;
Packit 709fb3
};
Packit 709fb3
Packit 709fb3
/* The dfa structure. It is completely opaque. */
Packit 709fb3
struct dfa;
Packit 709fb3
Packit 709fb3
/* Entry points. */
Packit 709fb3
Packit 709fb3
/* Allocate a struct dfa.  The struct dfa is completely opaque.
Packit 709fb3
   The returned pointer should be passed directly to free() after
Packit 709fb3
   calling dfafree() on it. */
Packit 709fb3
extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC;
Packit 709fb3
Packit 709fb3
/* DFA options that can be ORed together, for dfasyntax's 4th arg.  */
Packit 709fb3
enum
Packit 709fb3
  {
Packit 709fb3
    /* ^ and $ match only the start and end of data, and do not match
Packit 709fb3
       end-of-line within data.  This is always false for grep, but
Packit 709fb3
       possibly true for other apps.  */
Packit 709fb3
    DFA_ANCHOR = 1 << 0,
Packit 709fb3
Packit 709fb3
    /* '\0' in data is end-of-line, instead of the traditional '\n'.  */
Packit 709fb3
    DFA_EOL_NUL = 1 << 1
Packit 709fb3
  };
Packit 709fb3
Packit 709fb3
/* Initialize or reinitialize a DFA.  This must be called before
Packit 709fb3
   any of the routines below.  The arguments are:
Packit 709fb3
   1. The DFA to operate on.
Packit 709fb3
   2. Information about the current locale.
Packit 709fb3
   3. Syntax bits described in regex.h.
Packit 709fb3
   4. Additional DFA options described above.  */
Packit 709fb3
extern void dfasyntax (struct dfa *, struct localeinfo const *,
Packit 709fb3
                       reg_syntax_t, int);
Packit 709fb3
Packit 709fb3
/* Build and return the struct dfamust from the given struct dfa. */
Packit 709fb3
extern struct dfamust *dfamust (struct dfa const *);
Packit 709fb3
Packit 709fb3
/* Free the storage held by the components of a struct dfamust. */
Packit 709fb3
extern void dfamustfree (struct dfamust *);
Packit 709fb3
Packit 709fb3
/* Compile the given string of the given length into the given struct dfa.
Packit 709fb3
   Final argument is a flag specifying whether to build a searching or an
Packit 709fb3
   exact matcher. */
Packit 709fb3
extern void dfacomp (char const *, size_t, struct dfa *, bool);
Packit 709fb3
Packit 709fb3
/* Search through a buffer looking for a match to the given struct dfa.
Packit 709fb3
   Find the first occurrence of a string matching the regexp in the
Packit 709fb3
   buffer, and the shortest possible version thereof.  Return a pointer to
Packit 709fb3
   the first character after the match, or NULL if none is found.  BEGIN
Packit 709fb3
   points to the beginning of the buffer, and END points to the first byte
Packit 709fb3
   after its end.  Note however that we store a sentinel byte (usually
Packit 709fb3
   newline) in *END, so the actual buffer must be one byte longer.
Packit 709fb3
   When ALLOW_NL is true, newlines may appear in the matching string.
Packit 709fb3
   If COUNT is non-NULL, increment *COUNT once for each newline processed.
Packit 709fb3
   Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
Packit 709fb3
   encountered a back-reference.  The caller can use this to decide
Packit 709fb3
   whether to fall back on a backtracking matcher.  */
Packit 709fb3
extern char *dfaexec (struct dfa *d, char const *begin, char *end,
Packit 709fb3
                      bool allow_nl, size_t *count, bool *backref);
Packit 709fb3
Packit 709fb3
/* Return a superset for D.  The superset matches everything that D
Packit 709fb3
   matches, along with some other strings (though the latter should be
Packit 709fb3
   rare, for efficiency reasons).  Return a null pointer if no useful
Packit 709fb3
   superset is available.  */
Packit 709fb3
extern struct dfa *dfasuperset (struct dfa const *d) _GL_ATTRIBUTE_PURE;
Packit 709fb3
Packit 709fb3
/* The DFA is likely to be fast.  */
Packit 709fb3
extern bool dfaisfast (struct dfa const *) _GL_ATTRIBUTE_PURE;
Packit 709fb3
Packit 709fb3
/* Free the storage held by the components of a struct dfa. */
Packit 709fb3
extern void dfafree (struct dfa *);
Packit 709fb3
Packit 709fb3
/* Error handling. */
Packit 709fb3
Packit 709fb3
/* dfawarn() is called by the regexp routines whenever a regex is compiled
Packit 709fb3
   that likely doesn't do what the user wanted.  It takes a single
Packit 709fb3
   argument, a NUL-terminated string describing the situation.  The user
Packit 709fb3
   must supply a dfawarn.  */
Packit 709fb3
extern void dfawarn (const char *);
Packit 709fb3
Packit 709fb3
/* dfaerror() is called by the regexp routines whenever an error occurs.  It
Packit 709fb3
   takes a single argument, a NUL-terminated string describing the error.
Packit 709fb3
   The user must supply a dfaerror.  */
Packit 709fb3
extern _Noreturn void dfaerror (const char *);