/* A compiled pattern arg. */
struct control
{
- char *regexpr; /* Non-compiled regular expression. */
- struct re_pattern_buffer re_compiled; /* Compiled regular expression. */
intmax_t offset; /* Offset from regexp to split at. */
uintmax_t lines_required; /* Number of lines required. */
uintmax_t repeat; /* Repeat count. */
int argnum; /* ARGV index. */
bool repeat_forever; /* True if `*' used as a repeat count. */
bool ignore; /* If true, produce no output (for regexp). */
+ bool regexpr; /* True if regular expression was used. */
+ struct re_pattern_buffer re_compiled; /* Compiled regular expression. */
+ char fastmap[UCHAR_MAX + 1]; /* Fastmap for RE_COMPILED. */
};
/* Initial size of data area in buffers. */
if (control_used == control_allocated)
controls = X2NREALLOC (controls, &control_allocated);
p = &controls[control_used++];
- p->regexpr = NULL;
+ p->regexpr = false;
p->repeat = 0;
p->repeat_forever = false;
p->lines_required = 0;
Unless IGNORE is true, mark these lines for output. */
static struct control *
-extract_regexp (int argnum, bool ignore, char *str)
+extract_regexp (int argnum, bool ignore, char const *str)
{
size_t len; /* Number of bytes in this regexp. */
char delim = *str;
- char *closing_delim;
+ char const *closing_delim;
struct control *p;
const char *err;
p->argnum = argnum;
p->ignore = ignore;
- p->regexpr = xmalloc (len + 1);
- strncpy (p->regexpr, str + 1, len);
- p->re_compiled.allocated = len * 2;
- p->re_compiled.buffer = xmalloc (p->re_compiled.allocated);
- p->re_compiled.fastmap = xmalloc (1 << CHAR_BIT);
+ p->regexpr = true;
+ p->re_compiled.buffer = NULL;
+ p->re_compiled.allocated = 0;
+ p->re_compiled.fastmap = p->fastmap;
p->re_compiled.translate = NULL;
- err = re_compile_pattern (p->regexpr, len, &p->re_compiled);
+ err = re_compile_pattern (str + 1, len, &p->re_compiled);
if (err)
{
error (0, 0, _("%s: invalid regular expression: %s"), str, err);