aboutsummaryrefslogtreecommitdiffstats
path: root/support/dfa.c
diff options
context:
space:
mode:
Diffstat (limited to 'support/dfa.c')
-rw-r--r--support/dfa.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/support/dfa.c b/support/dfa.c
index 65b0972c..d112443f 100644
--- a/support/dfa.c
+++ b/support/dfa.c
@@ -24,6 +24,8 @@
#include "dfa.h"
+#include "flexmember.h"
+
#include <assert.h>
#include <ctype.h>
#ifndef VMS
@@ -76,18 +78,6 @@ isasciidigit (char c)
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
-#if defined(__DJGPP__)
-#include "mbsupport.h"
-#endif
-
-#ifdef GAWK
-static int
-is_blank (int c)
-{
- return (c == ' ' || c == '\t');
-}
-#endif /* GAWK */
-
/* HPUX defines these as macros in sys/param.h. */
#ifdef setbit
# undef setbit
@@ -96,18 +86,46 @@ is_blank (int c)
# undef clrbit
#endif
+/* For code that does not use Gnulib’s isblank module. */
+#if !defined isblank && !defined HAVE_ISBLANK && !defined GNULIB_ISBLANK
+# define isblank dfa_isblank
+static int
+isblank (int c)
+{
+ return c == ' ' || c == '\t';
+}
+#endif
+
/* First integer value that is greater than any character code. */
enum { NOTCHAR = 1 << CHAR_BIT };
+#ifdef UINT_LEAST64_MAX
+
/* Number of bits used in a charclass word. */
enum { CHARCLASS_WORD_BITS = 64 };
/* This represents part of a character class. It must be unsigned and
at least CHARCLASS_WORD_BITS wide. Any excess bits are zero. */
-typedef uint_fast64_t charclass_word;
+typedef uint_least64_t charclass_word;
+
+/* Part of a charclass initializer that represents 64 bits' worth of a
+ charclass, where LO and HI are the low and high-order 32 bits of
+ the 64-bit quantity. */
+# define CHARCLASS_PAIR(lo, hi) (((charclass_word) (hi) << 32) + (lo))
+
+#else
+/* Fallbacks for pre-C99 hosts that lack 64-bit integers. */
+enum { CHARCLASS_WORD_BITS = 32 };
+typedef unsigned long charclass_word;
+# define CHARCLASS_PAIR(lo, hi) lo, hi
+#endif
-/* An initializer for a charclass whose 64-bit words are A through D. */
-#define CHARCLASS_INIT(a, b, c, d) {{a, b, c, d}}
+/* An initializer for a charclass whose 32-bit words are A through H. */
+#define CHARCLASS_INIT(a, b, c, d, e, f, g, h) \
+ {{ \
+ CHARCLASS_PAIR (a, b), CHARCLASS_PAIR (c, d), \
+ CHARCLASS_PAIR (e, f), CHARCLASS_PAIR (g, h) \
+ }}
/* The maximum useful value of a charclass_word; all used bits are 1. */
static charclass_word const CHARCLASS_WORD_MASK
@@ -964,7 +982,7 @@ static const struct dfa_ctype prednames[] = {
{"print", isprint, false},
{"graph", isgraph, false},
{"cntrl", iscntrl, false},
- {"blank", is_blank, false},
+ {"blank", isblank, false},
{NULL, NULL, false}
};
@@ -1714,39 +1732,39 @@ add_utf8_anychar (struct dfa *dfa)
static charclass const utf8_classes[] = {
/* A. 00-7f: 1-byte sequence. */
- CHARCLASS_INIT (0xffffffffffffffff, 0xffffffffffffffff, 0, 0),
+ CHARCLASS_INIT (0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0, 0, 0, 0),
/* B. c2-df: 1st byte of a 2-byte sequence. */
- CHARCLASS_INIT (0, 0, 0, 0x00000000fffffffc),
+ CHARCLASS_INIT (0, 0, 0, 0, 0, 0, 0xfffffffc, 0),
/* C. 80-bf: non-leading bytes. */
- CHARCLASS_INIT (0, 0, 0xffffffffffffffff, 0),
+ CHARCLASS_INIT (0, 0, 0, 0, 0xffffffff, 0xffffffff, 0, 0),
/* D. e0 (just a token). */
/* E. a0-bf: 2nd byte of a "DEC" sequence. */
- CHARCLASS_INIT (0, 0, 0xffffffff00000000, 0),
+ CHARCLASS_INIT (0, 0, 0, 0, 0, 0xffffffff, 0, 0),
/* F. e1-ec + ee-ef: 1st byte of an "FCC" sequence. */
- CHARCLASS_INIT (0, 0, 0, 0x0000dffe00000000),
+ CHARCLASS_INIT (0, 0, 0, 0, 0, 0, 0, 0xdffe),
/* G. ed (just a token). */
/* H. 80-9f: 2nd byte of a "GHC" sequence. */
- CHARCLASS_INIT (0, 0, 0x000000000000ffff, 0),
+ CHARCLASS_INIT (0, 0, 0, 0, 0xffff, 0, 0, 0),
/* I. f0 (just a token). */
/* J. 90-bf: 2nd byte of an "IJCC" sequence. */
- CHARCLASS_INIT (0, 0, 0xffffffffffff0000, 0),
+ CHARCLASS_INIT (0, 0, 0, 0, 0xffff0000, 0xffffffff, 0, 0),
/* K. f1-f3: 1st byte of a "KCCC" sequence. */
- CHARCLASS_INIT (0, 0, 0, 0x000e000000000000),
+ CHARCLASS_INIT (0, 0, 0, 0, 0, 0, 0, 0xe0000),
/* L. f4 (just a token). */
/* M. 80-8f: 2nd byte of a "LMCC" sequence. */
- CHARCLASS_INIT (0, 0, 0x00000000000000ff, 0),
+ CHARCLASS_INIT (0, 0, 0, 0, 0xff, 0, 0, 0),
};
/* Define the character classes that are needed below. */
@@ -4289,11 +4307,11 @@ dfamust (struct dfa const *d)
struct dfamust *dm = NULL;
if (*result)
{
- dm = xmalloc (sizeof *dm);
+ dm = xmalloc (FLEXSIZEOF (struct dfamust, must, strlen (result) + 1));
dm->exact = exact;
dm->begline = begline;
dm->endline = endline;
- dm->must = xstrdup (result);
+ strcpy (dm->must, result);
}
while (mp)
@@ -4309,7 +4327,6 @@ dfamust (struct dfa const *d)
void
dfamustfree (struct dfamust *dm)
{
- free (dm->must);
free (dm);
}