Commit 83e9cc89 authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent 10ad4d2a
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
......@@ -444,9 +444,6 @@ struct parser_state
/* 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. */
......@@ -562,6 +559,10 @@ struct dfa
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. */
......@@ -4303,4 +4304,16 @@ dfasyntax (struct dfa *dfa, struct localeinfo const *linfo,
}
}
/* 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: */
......@@ -45,6 +45,7 @@ struct dfa;
/* 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;
......@@ -61,8 +62,7 @@ enum
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.
......@@ -70,6 +70,9 @@ enum
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 *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment