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