+2019-12-17 Paul Eggert <eggert@cs.ucla.edu>
+
+ dfa: new function dfacopysyntax
+ * lib/dfa.c (struct dfa): Move syntax member later so
+ that dfacopysyntax can easily clear earlier members.
+ (dfacopysyntax): New function, used by Gawk.
+
2019-12-16 Paul Eggert <eggert@cs.ucla.edu>
dfa: port _GL_ATTRIBUTE_MALLOC to Gawk
/* A compiled regular expression. */
struct dfa
{
- /* Syntax configuration */
- struct regex_syntax syntax;
-
/* Fields filled by the scanner. */
charclass *charclasses; /* Array of character sets for CSET tokens. */
idx_t cindex; /* Index for adding new charclasses. */
state_num mb_trcount; /* Number of transition tables for states with
ANYCHAR that have actually been built. */
+ /* Syntax configuration. This is near the end so that dfacopysyntax
+ can memset up to here. */
+ struct regex_syntax syntax;
+
/* Information derived from the locale. This is at the end so that
a quick memset need not clear it specially. */
}
}
+/* Initialize TO by copying FROM's syntax settings. */
+void
+dfacopysyntax (struct dfa *to, struct dfa const *from)
+{
+ memset (to, 0, offsetof (struct dfa, syntax));
+ to->canychar = -1;
+ to->fast = from->fast;
+ to->syntax = from->syntax;
+ to->dfaexec = from->dfaexec;
+ to->localeinfo = from->localeinfo;
+}
+
/* vim:set shiftwidth=2: */
/* Entry points. */
/* Allocate a struct dfa. The struct dfa is completely opaque.
+ It should be initialized via dfasyntax or dfacopysyntax before other use.
The returned pointer should be passed directly to free() after
calling dfafree() on it. */
extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC;
DFA_EOL_NUL = 1 << 1
};
-/* Initialize or reinitialize a DFA. This must be called before
- any of the routines below. The arguments are:
+/* Initialize or reinitialize a DFA. The arguments are:
1. The DFA to operate on.
2. Information about the current locale.
3. Syntax bits described in regex.h.
extern void dfasyntax (struct dfa *, struct localeinfo const *,
reg_syntax_t, int);
+/* Initialize or reinitialize a DFA from an already-initialized DFA. */
+extern void dfacopysyntax (struct dfa *, struct dfa const *);
+
/* Parse the given string of given length into the given struct dfa. */
extern void dfaparse (char const *, ptrdiff_t, struct dfa *);