aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/testdfa.c
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/testdfa.c')
-rw-r--r--helpers/testdfa.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/helpers/testdfa.c b/helpers/testdfa.c
index 1e144bd7..72b97907 100644
--- a/helpers/testdfa.c
+++ b/helpers/testdfa.c
@@ -2,22 +2,22 @@
* testdfa.c --- abstracted from gawk.
*/
-/*
+/*
* Copyright (C) 1986, 1988, 1989, 1991-2013 the Free Software Foundation, Inc.
- *
+ *
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
- *
+ *
* GAWK 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 of the License, or
* (at your option) any later version.
- *
+ *
* GAWK 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
@@ -44,6 +44,7 @@
#define _Noreturn
#define _GL_ATTRIBUTE_PURE
#include "dfa.h"
+#include "localeinfo.h"
const char *regexflags2str(int flags);
char *databuf(int fd);
@@ -71,7 +72,8 @@ void usage(const char *myname)
int main(int argc, char **argv)
{
- int c, ret, try_backref;
+ int c, ret;
+ bool try_backref;
struct re_pattern_buffer pat;
struct re_registers regs;
struct dfa *dfareg;
@@ -84,6 +86,7 @@ int main(int argc, char **argv)
char save;
size_t count = 0;
char *place;
+ struct localeinfo localeinfo;
if (argc < 2)
usage(argv[0]);
@@ -158,7 +161,6 @@ int main(int argc, char **argv)
dfa_syn = syn;
if (ignorecase)
dfa_syn |= RE_ICASE;
- dfasyntax(dfa_syn, ignorecase, '\n');
re_set_syntax(syn);
if ((rerr = re_compile_pattern(pattern, len, & pat)) != NULL) {
@@ -171,6 +173,10 @@ int main(int argc, char **argv)
pat.newline_anchor = false; /* don't get \n in middle of string */
dfareg = dfaalloc();
+ init_localeinfo(&localeinfo);
+ dfasyntax(dfareg, &localeinfo, dfa_syn,
+ ignorecase ? DFA_CASE_FOLD : 0);
+
printf("Calling dfacomp(%s, %d, %p, true)\n",
pattern, (int) len, dfareg);
@@ -372,10 +378,10 @@ setup_pattern(const char *pattern, size_t *len)
{
size_t is_multibyte = 0;
int c, c2;
- size_t buflen = 0;
+ size_t buflen;
mbstate_t mbs;
bool has_anchor = false;
- char *buf = NULL;
+ char *buf;
char *dest;
const char *src, *end;
@@ -389,23 +395,14 @@ setup_pattern(const char *pattern, size_t *len)
/*
* Build a copy of the string (in buf) with the
* escaped characters translated, and generate the regex
- * from that.
+ * from that.
*/
+ buf = (char *) malloc(*len + 1);
if (buf == NULL) {
- buf = (char *) malloc(*len + 2);
- if (buf == NULL) {
- fprintf(stderr, "%s: malloc failed\n", __func__);
- exit(EXIT_FAILURE);
- }
- buflen = *len;
- } else if (*len > buflen) {
- buf = (char *) realloc(buf, *len + 2);
- if (buf == NULL) {
- fprintf(stderr, "%s: realloc failed\n", __func__);
- exit(EXIT_FAILURE);
- }
- buflen = *len;
+ fprintf(stderr, "%s: malloc failed\n", __func__);
+ exit(EXIT_FAILURE);
}
+ buflen = *len;
dest = buf;
while (src < end) {
@@ -502,16 +499,16 @@ setup_pattern(const char *pattern, size_t *len)
*
* Parse a C escape sequence. STRING_PTR points to a variable containing a
* pointer to the string to parse. That pointer is updated past the
- * characters we use. The value of the escape sequence is returned.
+ * characters we use. The value of the escape sequence is returned.
*
* A negative value means the sequence \ newline was seen, which is supposed to
- * be equivalent to nothing at all.
+ * be equivalent to nothing at all.
*
* If \ is followed by a null character, we return a negative value and leave
- * the string pointer pointing at the null character.
+ * the string pointer pointing at the null character.
*
* If \ is followed by 000, we return 0 and leave the string pointer after the
- * zeros. A value of 0 does not mean end of string.
+ * zeros. A value of 0 does not mean end of string.
*
* POSIX doesn't allow \x.
*/
@@ -600,7 +597,7 @@ parse_escape(const char **string_ptr)
#ifdef C
#undef C
#endif
-#define C(c) ((char)c)
+#define C(c) ((char)c)
/*
* This table is used by the regexp routines to do case independent
* matching. Basically, every ascii character maps to itself, except