aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2011-01-30 21:15:59 +0200
committerArnold D. Robbins <arnold@skeeve.com>2011-01-30 21:15:59 +0200
commita7dd34e347fecd3a09be19c9c2b9fe99e1bbbcd7 (patch)
treeb821b50c9b29e7c1e2afd15f0b70c2c64a58570e
parented816b945b9725b26aa7f44fdab5bec0c48a8507 (diff)
downloadegawk-a7dd34e347fecd3a09be19c9c2b9fe99e1bbbcd7.tar.gz
egawk-a7dd34e347fecd3a09be19c9c2b9fe99e1bbbcd7.tar.bz2
egawk-a7dd34e347fecd3a09be19c9c2b9fe99e1bbbcd7.zip
Sync dfa to grep, import hard-locale.[ch].
-rw-r--r--ChangeLog9
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.in9
-rw-r--r--awk.h3
-rw-r--r--builtin.c4
-rw-r--r--dfa.c57
-rw-r--r--dfa.h2
-rw-r--r--hard-locale.c83
-rw-r--r--hard-locale.h68
9 files changed, 153 insertions, 83 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d756011..dd7d16ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sun Jan 30 21:13:01 2011 Arnold D. Robbins <arnold@skeeve.com>
+
+ * hard-locale.h: Synced to GNU grep.
+ * hard-locale.c: New file, brought in from GNU grep.
+ * Makefile.am (base_sources): Add hard-locale.c.
+ * dfa.h: Sync as much as possible to GNU grep.
+ * dfa.c: Sync as much as possible to GNU grep.
+ * builtin.c (do_strftime): Remove unneeded variable.
+
Thu Jan 27 22:52:54 2011 Arnold D. Robbins <arnold@skeeve.com>
* awk.h (comp_func): Add declaration.
diff --git a/Makefile.am b/Makefile.am
index 0010cc4e..7813352f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,6 +97,7 @@ base_sources = \
getopt_int.h \
gettext.h \
hard-locale.h \
+ hard-locale.c \
io.c \
mbsupport.h \
main.c \
diff --git a/Makefile.in b/Makefile.in
index e681d502..2a763a43 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -90,9 +90,10 @@ PROGRAMS = $(bin_PROGRAMS)
am__objects_1 = array.$(OBJEXT) awkgram.$(OBJEXT) builtin.$(OBJEXT) \
dfa.$(OBJEXT) ext.$(OBJEXT) field.$(OBJEXT) \
floatcomp.$(OBJEXT) gawkmisc.$(OBJEXT) getopt.$(OBJEXT) \
- getopt1.$(OBJEXT) io.$(OBJEXT) main.$(OBJEXT) msg.$(OBJEXT) \
- node.$(OBJEXT) random.$(OBJEXT) re.$(OBJEXT) regex.$(OBJEXT) \
- replace.$(OBJEXT) version.$(OBJEXT)
+ getopt1.$(OBJEXT) hard-locale.$(OBJEXT) io.$(OBJEXT) \
+ main.$(OBJEXT) msg.$(OBJEXT) node.$(OBJEXT) random.$(OBJEXT) \
+ re.$(OBJEXT) regex.$(OBJEXT) replace.$(OBJEXT) \
+ version.$(OBJEXT)
am_dgawk_OBJECTS = $(am__objects_1) eval_d.$(OBJEXT) profile.$(OBJEXT) \
command.$(OBJEXT) debug.$(OBJEXT)
dgawk_OBJECTS = $(am_dgawk_OBJECTS)
@@ -372,6 +373,7 @@ base_sources = \
getopt_int.h \
gettext.h \
hard-locale.h \
+ hard-locale.c \
io.c \
mbsupport.h \
main.c \
@@ -528,6 +530,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gawkmisc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hard-locale.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msg.Po@am__quote@
diff --git a/awk.h b/awk.h
index 8d6a7490..2baf4812 100644
--- a/awk.h
+++ b/awk.h
@@ -1186,13 +1186,12 @@ extern NODE *do_bindtextdomain(int nargs);
extern int strncasecmpmbs(const unsigned char *,
const unsigned char *, size_t);
#endif
-/* debug.c */
-extern int comp_func(const void *p1, const void *p2);
/* eval.c */
extern void PUSH_CODE(INSTRUCTION *cp);
extern INSTRUCTION *POP_CODE(void);
extern int interpret(INSTRUCTION *);
extern int cmp_nodes(NODE *, NODE *);
+extern int comp_func(const void *p1, const void *p2);
extern void set_IGNORECASE(void);
extern void set_OFS(void);
extern void set_ORS(void);
diff --git a/builtin.c b/builtin.c
index 8bb10486..7156601e 100644
--- a/builtin.c
+++ b/builtin.c
@@ -782,7 +782,7 @@ do_substr(int nargs)
NODE *
do_strftime(int nargs)
{
- NODE *t1, *t2, *t3, *ret;
+ NODE *t1, *t2, *ret;
struct tm *tm;
time_t fclock;
char *bufp;
@@ -814,7 +814,7 @@ do_strftime(int nargs)
}
}
- t1 = t2 = t3 = NULL;
+ t1 = t2 = NULL;
if (nargs > 0) { /* have args */
NODE *tmp;
diff --git a/dfa.c b/dfa.c
index 525d963b..953774b9 100644
--- a/dfa.c
+++ b/dfa.c
@@ -1,5 +1,5 @@
/* dfa.c - deterministic extended regexp routines for GNU
- Copyright (C) 1988, 1998, 2000, 2002, 2004, 2005, 2007-2010 Free Software
+ Copyright (C) 1988, 1998, 2000, 2002, 2004-2005, 2007-2011 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -64,10 +64,17 @@
#endif
#endif
+/* need this before include of hard-locale.h */
+#ifdef GAWK
+#define bool int
+#define true (1)
+#define false (0)
+#endif
+
#include "regex.h"
#include "dfa.h"
-#include "xalloc.h"
#include "hard-locale.h"
+#include "xalloc.h"
#ifdef GAWK
static int
@@ -714,26 +721,8 @@ static unsigned char const *buf_end; /* reference to end in dfaexec(). */
#endif /* MBS_SUPPORT */
-static int
-in_coll_range (char ch, char from, char to)
-{
- char c[6];
- c[0] = from;
- c[1] = 0;
- c[2] = ch;
- c[3] = 0;
- c[4] = to;
- c[5] = 0;
- return strcoll (&c[0], &c[2]) <= 0 && strcoll (&c[2], &c[4]) <= 0;
-}
-
typedef int predicate (int);
-#ifdef GAWK
-#define bool int
-#define true (1)
-#define false (0)
-#endif
/* The following list maps the names of the Posix named character classes
to predicate functions that determine whether a given character is in
the class. The leading [ has already been eaten by the lexical analyzer. */
@@ -1007,10 +996,30 @@ parse_bracket_exp (void)
for (c = c1; c <= c2; c++)
setbit_case_fold (c, ccl);
else
- for (c = 0; c < NOTCHAR; ++c)
- if (!(case_fold && isupper (c))
- && in_coll_range (c, c1, c2))
- setbit_case_fold (c, ccl);
+ {
+ /* Defer to the system regex library about the meaning
+ of range expressions. */
+ regex_t re;
+ char pattern[6];
+ char subject[2];
+
+ pattern[0] = '[';
+ pattern[1] = c1;
+ pattern[2] = '-';
+ pattern[3] = c2;
+ pattern[4] = ']';
+ pattern[5] = 0;
+ subject[0] = subject[1] = 0;
+ regcomp (&re, pattern, REG_NOSUB);
+ for (c = 0; c < NOTCHAR; ++c)
+ {
+ subject[0] = c;
+ if (!(case_fold && isupper (c))
+ && regexec (&re, subject, 0, NULL, 0) != REG_NOMATCH)
+ setbit_case_fold (c, ccl);
+ }
+ regfree (&re);
+ }
}
colon_warning_state |= 8;
diff --git a/dfa.h b/dfa.h
index ac339309..4d65ee34 100644
--- a/dfa.h
+++ b/dfa.h
@@ -1,5 +1,5 @@
/* dfa.h - declarations for GNU deterministic regexp compiler
- Copyright (C) 1988, 1998, 2007, 2009-2010 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1998, 2007, 2009-2011 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
diff --git a/hard-locale.c b/hard-locale.c
new file mode 100644
index 00000000..8b7353bb
--- /dev/null
+++ b/hard-locale.c
@@ -0,0 +1,83 @@
+/* hard-locale.c -- Determine whether a locale is hard.
+
+ Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004, 2006, 2007, 2009, 2010,
+ 2011,
+ 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 of the License, 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, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#ifdef GAWK
+#define bool int
+#define true (1)
+#define false (0)
+#endif
+
+#include "hard-locale.h"
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __GLIBC__
+# define GLIBC_VERSION __GLIBC__
+#else
+# define GLIBC_VERSION 0
+#endif
+
+/* Return true if the current CATEGORY locale is hard, i.e. if you
+ can't get away with assuming traditional C or POSIX behavior. */
+bool
+hard_locale (int category)
+{
+#if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
+ return 0;
+#else
+ bool hard = true;
+ char const *p = setlocale (category, NULL);
+
+ if (p)
+ {
+ if (2 <= GLIBC_VERSION)
+ {
+ if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
+ hard = false;
+ }
+ else
+ {
+ char *locale = strdup (p);
+ if (locale)
+ {
+ /* Temporarily set the locale to the "C" and "POSIX" locales
+ to find their names, so that we can determine whether one
+ or the other is the caller's locale. */
+ if (((p = setlocale (category, "C"))
+ && strcmp (p, locale) == 0)
+ || ((p = setlocale (category, "POSIX"))
+ && strcmp (p, locale) == 0))
+ hard = false;
+
+ /* Restore the caller's locale. */
+ setlocale (category, locale);
+ free (locale);
+ }
+ }
+ }
+
+ return hard;
+#endif
+}
diff --git a/hard-locale.h b/hard-locale.h
index c0075b2e..160d5443 100644
--- a/hard-locale.h
+++ b/hard-locale.h
@@ -1,16 +1,11 @@
-/* hard-locale.h -- Same as hard-locale.c.
- *
- * For gawk, put this in a header file, provides source code
- * compatibility with GNU grep for dfa.c, so that dfa.c need
- * not be continually modified by hand.
- */
-/* hard-locale.c -- Determine whether a locale is hard.
- Copyright 1997, 1998, 1999, 2010 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
+/* Determine whether a locale is hard.
+
+ Copyright (C) 1999, 2003, 2004, 2009, 2010, 2011 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 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, 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
@@ -18,44 +13,15 @@
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. */
-
-/* Return nonzero if the current CATEGORY locale is hard, i.e. if you
- can't get away with assuming traditional C or POSIX behavior. */
-static int
-hard_locale (int category)
-{
-#if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
- return 0;
-#else
-
- int hard = 1;
- char const *p = setlocale (category, 0);
-
- if (p)
- {
-# if defined __GLIBC__ && __GLIBC__ >= 2
- if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
- hard = 0;
-# else
- char *locale = (char *) xmalloc (strlen (p) + 1);
- strcpy (locale, p);
-
- /* Temporarily set the locale to the "C" and "POSIX" locales to
- find their names, so that we can determine whether one or the
- other is the caller's locale. */
- if (((p = setlocale (category, "C")) && strcmp (p, locale) == 0)
- || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0))
- hard = 0;
-
- /* Restore the caller's locale. */
- setlocale (category, locale);
- free(locale);
-# endif
- }
-
- return hard;
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef HARD_LOCALE_H_
+# define HARD_LOCALE_H_ 1
+#ifndef GAWK
+# include <stdbool.h>
#endif
-}
+
+bool hard_locale (int);
+
+#endif /* HARD_LOCALE_H_ */