dfa: reflect move of dfa code to new gnulib module
* bootstrap.conf (gnulib_modules): Add dfa. * sed/dfa.c: Remove file. * sed/dfa.h: Likewise. * sed/local.mk (sed_sed_SOURCES): Remove dfa.c. (NOINST_HEADERS): Remove dfa.h. * sed/regexp.c (compile_regex_1): Use new dfasyntax API. * sed/sed.c (localeinfo): New global. (main): Call init_localeinfo to initialize it. * sed/sed.h: Include localeinfo.h and declare the new global. * lib/.gitignore: Ignore new gnulib-imported files. * m4/.gitignore: Likewise. * po/POTFILES.in: s,sed/dfa.c,lib/dfa.c,
This commit is contained in:
1 parent
098ce3f6d1
commit
ba26be8954
10 files changed
+23
-4118
No files matched your search
@@ -27,6 +27,7 @@ stdalign
|
||||
btowc
|
||||
c-ctype
|
||||
closeout
|
||||
dfa
|
||||
extensions
|
||||
fwriting
|
||||
getdelim
|
||||
|
||||
@@ -220,3 +220,11 @@ xstrndup.h
|
||||
/acl-internal.c
|
||||
/get-permissions.c
|
||||
/set-permissions.c
|
||||
/ctype.in.h
|
||||
/dfa.c
|
||||
/dfa.h
|
||||
/getprogname.c
|
||||
/getprogname.h
|
||||
/localeinfo.c
|
||||
/localeinfo.h
|
||||
/isblank.c
|
||||
@@ -218,3 +218,7 @@ xstrndup.m4
|
||||
/fpending.m4
|
||||
/non-recursive-gnulib-prefix-hack.m4
|
||||
/ctype.m4
|
||||
/assert.m4
|
||||
/flexmember.m4
|
||||
/getprogname.m4
|
||||
/isblank.m4
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
lib/closeout.c
|
||||
lib/copy-acl.c
|
||||
lib/dfa.c
|
||||
lib/error.c
|
||||
lib/getopt.c
|
||||
lib/obstack.c
|
||||
@@ -9,7 +10,6 @@ lib/set-acl.c
|
||||
lib/version-etc.c
|
||||
lib/xalloc-die.c
|
||||
sed/compile.c
|
||||
sed/dfa.c
|
||||
sed/execute.c
|
||||
sed/regexp.c
|
||||
sed/sed.c
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/* dfa.h - declarations for GNU deterministic regexp compiler
|
||||
Copyright (C) 1988, 1998, 2007, 2009-2016 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc.,
|
||||
51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA */
|
||||
|
||||
/* Written June, 1988 by Mike Haertel */
|
||||
|
||||
#include <regex.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "xalloc.h" /* for _GL_ATTRIBUTE_MALLOC */
|
||||
|
||||
/* Element of a list of strings, at least one of which is known to
|
||||
appear in any R.E. matching the DFA. */
|
||||
struct dfamust
|
||||
{
|
||||
bool exact;
|
||||
bool begline;
|
||||
bool endline;
|
||||
char *must;
|
||||
};
|
||||
|
||||
/* The dfa structure. It is completely opaque. */
|
||||
struct dfa;
|
||||
|
||||
/* Entry points. */
|
||||
|
||||
/* Allocate a struct dfa. The struct dfa is completely opaque.
|
||||
The returned pointer should be passed directly to free() after
|
||||
calling dfafree() on it. */
|
||||
extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC;
|
||||
|
||||
/* Build and return the struct dfamust from the given struct dfa. */
|
||||
extern struct dfamust *dfamust (struct dfa const *);
|
||||
|
||||
/* Free the storage held by the components of a struct dfamust. */
|
||||
extern void dfamustfree (struct dfamust *);
|
||||
|
||||
/* dfasyntax() takes three arguments; the first sets the syntax bits described
|
||||
earlier in this file, the second sets the case-folding flag, and the
|
||||
third specifies the line terminator. */
|
||||
extern void dfasyntax (reg_syntax_t, bool, unsigned char);
|
||||
|
||||
/* Compile the given string of the given length into the given struct dfa.
|
||||
Final argument is a flag specifying whether to build a searching or an
|
||||
exact matcher. */
|
||||
extern void dfacomp (char const *, size_t, struct dfa *, bool);
|
||||
|
||||
/* Search through a buffer looking for a match to the given struct dfa.
|
||||
Find the first occurrence of a string matching the regexp in the
|
||||
buffer, and the shortest possible version thereof. Return a pointer to
|
||||
the first character after the match, or NULL if none is found. BEGIN
|
||||
points to the beginning of the buffer, and END points to the first byte
|
||||
after its end. Note however that we store a sentinel byte (usually
|
||||
newline) in *END, so the actual buffer must be one byte longer.
|
||||
When ALLOW_NL is true, newlines may appear in the matching string.
|
||||
If COUNT is non-NULL, increment *COUNT once for each newline processed.
|
||||
Finally, if BACKREF is non-NULL set *BACKREF to indicate whether we
|
||||
encountered a back-reference. The caller can use this to decide
|
||||
whether to fall back on a backtracking matcher. */
|
||||
extern char *dfaexec (struct dfa *d, char const *begin, char *end,
|
||||
bool allow_nl, size_t *count, bool *backref);
|
||||
|
||||
/* Return a superset for D. The superset matches everything that D
|
||||
matches, along with some other strings (though the latter should be
|
||||
rare, for efficiency reasons). Return a null pointer if no useful
|
||||
superset is available. */
|
||||
extern struct dfa *dfasuperset (struct dfa const *d) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* The DFA is likely to be fast. */
|
||||
extern bool dfaisfast (struct dfa const *) _GL_ATTRIBUTE_PURE;
|
||||
|
||||
/* Free the storage held by the components of a struct dfa. */
|
||||
extern void dfafree (struct dfa *);
|
||||
|
||||
/* Error handling. */
|
||||
|
||||
/* dfawarn() is called by the regexp routines whenever a regex is compiled
|
||||
that likely doesn't do what the user wanted. It takes a single
|
||||
argument, a NUL-terminated string describing the situation. The user
|
||||
must supply a dfawarn. */
|
||||
extern void dfawarn (const char *);
|
||||
|
||||
/* dfaerror() is called by the regexp routines whenever an error occurs. It
|
||||
takes a single argument, a NUL-terminated string describing the error.
|
||||
The user must supply a dfaerror. */
|
||||
extern _Noreturn void dfaerror (const char *);
|
||||
|
||||
extern bool using_utf8 (void);
|
||||
@@ -19,7 +19,6 @@ localedir = $(datadir)/locale
|
||||
|
||||
sed_sed_SOURCES = \
|
||||
sed/compile.c \
|
||||
sed/dfa.c \
|
||||
sed/execute.c \
|
||||
sed/mbcs.c \
|
||||
sed/regexp.c \
|
||||
@@ -27,7 +26,6 @@ sed_sed_SOURCES = \
|
||||
sed/utils.c
|
||||
|
||||
noinst_HEADERS += \
|
||||
sed/dfa.h \
|
||||
sed/sed.h \
|
||||
sed/utils.h
|
||||
|
||||
|
||||
+2
-1
@@ -142,8 +142,9 @@ compile_regex_1 (struct regex *new_regex, int needed_sub)
|
||||
bad_prog(buf);
|
||||
}
|
||||
|
||||
dfasyntax (syntax, (new_regex->flags & REG_ICASE) != 0, '\n');
|
||||
int dfaopts = (new_regex->flags & REG_ICASE) ? DFA_CASE_FOLD : 0;
|
||||
new_regex->dfa = dfaalloc ();
|
||||
dfasyntax (new_regex->dfa, &localeinfo, syntax, dfaopts);
|
||||
dfacomp (new_regex->re, new_regex->sz, new_regex->dfa, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ static struct vector *the_program = NULL;
|
||||
registered cleanup function. */
|
||||
static char const *G_file_to_unlink;
|
||||
|
||||
struct localeinfo localeinfo;
|
||||
|
||||
/* When exiting between temporary file creation and the rename
|
||||
associated with a sed -i invocation, remove that file. */
|
||||
static void
|
||||
@@ -235,6 +237,7 @@ main (int argc, char **argv)
|
||||
#endif
|
||||
set_program_name (argv[0]);
|
||||
initialize_mbcs ();
|
||||
init_localeinfo (&localeinfo);
|
||||
|
||||
/* Arrange to remove any un-renamed temporary file,
|
||||
upon premature exit. */
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
#include <config.h>
|
||||
#include "basicdefs.h"
|
||||
#include "regex.h"
|
||||
#include "dfa.h"
|
||||
#include "localeinfo.h"
|
||||
#include "regex.h"
|
||||
#include <stdio.h>
|
||||
#include "unlocked-io.h"
|
||||
|
||||
@@ -202,6 +203,8 @@ int process_files (struct vector *, char **argv);
|
||||
|
||||
int main (int, char **);
|
||||
|
||||
extern struct localeinfo localeinfo;
|
||||
|
||||
extern int extended_regexp_flags;
|
||||
|
||||
/* one-byte buffer delimiter */
|
||||
|
||||
Reference in new issue
Block a user