]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/perf/util/strfilter.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_STRFILTER_H
3 #define __PERF_STRFILTER_H
4 /* General purpose glob matching filter */
6 #include <linux/list.h>
9 /* A node of string filter */
10 struct strfilter_node
{
11 struct strfilter_node
*l
; /* Tree left branche (for &,|) */
12 struct strfilter_node
*r
; /* Tree right branche (for !,&,|) */
13 const char *p
; /* Operator or rule */
18 struct strfilter_node
*root
;
22 * strfilter__new - Create a new string filter
23 * @rules: Filter rule, which is a combination of glob expressions.
24 * @err: Pointer which points an error detected on @rules
26 * Parse @rules and return new strfilter. Return NULL if an error detected.
27 * In that case, *@err will indicate where it is detected, and *@err is NULL
28 * if a memory allocation is failed.
30 struct strfilter
*strfilter__new(const char *rules
, const char **err
);
33 * strfilter__or - Append an additional rule by logical-or
34 * @filter: Original string filter
35 * @rules: Filter rule to be appended at left of the root of
36 * @filter by using logical-or.
37 * @err: Pointer which points an error detected on @rules
39 * Parse @rules and join it to the @filter by using logical-or.
40 * Return 0 if success, or return the error code.
42 int strfilter__or(struct strfilter
*filter
,
43 const char *rules
, const char **err
);
46 * strfilter__add - Append an additional rule by logical-and
47 * @filter: Original string filter
48 * @rules: Filter rule to be appended at left of the root of
49 * @filter by using logical-and.
50 * @err: Pointer which points an error detected on @rules
52 * Parse @rules and join it to the @filter by using logical-and.
53 * Return 0 if success, or return the error code.
55 int strfilter__and(struct strfilter
*filter
,
56 const char *rules
, const char **err
);
59 * strfilter__compare - compare given string and a string filter
60 * @filter: String filter
63 * Compare @str and @filter. Return true if the str match the rule
65 bool strfilter__compare(struct strfilter
*filter
, const char *str
);
68 * strfilter__delete - delete a string filter
69 * @filter: String filter to delete
73 void strfilter__delete(struct strfilter
*filter
);
76 * strfilter__string - Reconstruct a rule string from filter
77 * @filter: String filter to reconstruct
79 * Reconstruct a rule string from @filter. This will be good for
80 * debug messages. Note that returning string must be freed afterward.
82 char *strfilter__string(struct strfilter
*filter
);