Commit a1726adc authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Use VSL_List2Tags in -IX option processing.

Use VSL_List2Tags in -IX option processing so that the filters can be
applied to a list of tags.
parent 79b63330
......@@ -75,10 +75,10 @@
)
#define VSL_OPT_I \
VOPT("I:", "[-I <[tag:]regex>]", "Include by regex", \
VOPT("I:", "[-I <[taglist:]regex>]", "Include by regex", \
"Include by regex matching. Output only records matching" \
" tag and regular expression. Applies to any tag if tag" \
" is * or empty.\n" \
" taglist and regular expression. Applies to any tag if" \
" taglist is absent.\n" \
"\n" \
VSL_iI_PS \
)
......@@ -117,8 +117,8 @@
)
#define VSL_OPT_X \
VOPT("X:", "[-X <[tag:]regex>]", "Exclude by regex", \
VOPT("X:", "[-X <[taglist:]regex>]", "Exclude by regex", \
"Exclude by regex matching. Do not output records matching" \
" tag and regular expression. Applies to any tag if tag" \
" is * or empty." \
" taglist and regular expression. Applies to any tag if" \
" taglist is absent." \
)
......@@ -108,6 +108,8 @@ vsl_IX_free(vslf_list *list)
vslf = VTAILQ_FIRST(list);
CHECK_OBJ_NOTNULL(vslf, VSLF_MAGIC);
VTAILQ_REMOVE(list, vslf, list);
if (vslf->tags)
vbit_destroy(vslf->tags);
AN(vslf->vre);
VRE_free(&vslf->vre);
AZ(vslf->vre);
......@@ -167,7 +169,7 @@ vsl_match_IX(struct VSL_data *vsl, const vslf_list *list, const struct VSL_curso
VTAILQ_FOREACH(vslf, list, list) {
CHECK_OBJ_NOTNULL(vslf, VSLF_MAGIC);
if (vslf->tag >= 0 && vslf->tag != tag)
if (vslf->tags != NULL && !vbit_test(vslf->tags, tag))
continue;
if (VRE_exec(vslf->vre, cdata, len, 0, 0, NULL, 0, NULL) >= 0)
return (1);
......
......@@ -63,7 +63,7 @@ struct vslf {
#define VSLF_MAGIC 0x08650B39
VTAILQ_ENTRY(vslf) list;
int tag;
struct vbitmap *tags;
vre_t *vre;
};
......
......@@ -256,47 +256,46 @@ vsl_IX_arg(struct VSL_data *vsl, int opt, const char *arg)
const char *b, *e, *err;
vre_t *vre;
struct vslf *vslf;
struct vbitmap *tags = NULL;
CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
vsl->flags |= F_SEEN_ixIX;
l = 0;
b = arg;
e = strchr(b, ':');
if (e) {
while (isspace(*b))
b++;
tags = vbit_init(SLT__MAX);
AN(tags);
l = e - b;
while (l > 0 && isspace(b[l - 1]))
l--;
}
if (l > 0 && strncmp(b, "*", l))
i = VSL_Name2Tag(b, l);
else
i = -3;
if (i == -2)
return (vsl_diag(vsl,
"-%c: \"%*.*s\" matches multiple tags\n",
(char)opt, l, l, b));
else if (i == -1)
return (vsl_diag(vsl,
"-%c: Could not match \"%*.*s\" to any tag\n",
(char)opt, l, l, b));
assert(i >= -3);
if (e)
i = VSL_List2Tags(b, l, vsl_vbm_bitset, tags);
if (i < 0)
vbit_destroy(tags);
if (i == -1)
return (vsl_diag(vsl,
"-%c: \"%*.*s\" matches zero tags",
(char)opt, l, l, b));
else if (i == -2)
return (vsl_diag(vsl,
"-%c: \"%*.*s\" is ambiguous",
(char)opt, l, l, b));
else if (i == 3)
return (vsl_diag(vsl,
"-%c: Syntax error in \"%*.*s\"",
(char)opt, l, l, b));
b = e + 1;
}
vre = VRE_compile(b, 0, &err, &off);
if (vre == NULL)
if (vre == NULL) {
if (tags)
vbit_destroy(tags);
return (vsl_diag(vsl, "-%c: Regex error at position %d (%s)\n",
(char)opt, off, err));
}
ALLOC_OBJ(vslf, VSLF_MAGIC);
if (vslf == NULL) {
VRE_free(&vre);
return (vsl_diag(vsl, "Out of memory"));
}
vslf->tag = i;
AN(vslf);
vslf->tags = tags;
vslf->vre = vre;
if (opt == 'I')
......
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