]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - tools/perf/util/strfilter.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-kernels.git] / tools / perf / util / strfilter.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
68baa431
MH
2#ifndef __PERF_STRFILTER_H
3#define __PERF_STRFILTER_H
4/* General purpose glob matching filter */
5
6#include <linux/list.h>
7#include <stdbool.h>
8
9/* A node of string filter */
10struct 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 */
14};
15
16/* String filter */
17struct strfilter {
18 struct strfilter_node *root;
19};
20
21/**
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
25 *
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.
29 */
30struct strfilter *strfilter__new(const char *rules, const char **err);
31
4e60a2ca
MH
32/**
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
38 *
39 * Parse @rules and join it to the @filter by using logical-or.
40 * Return 0 if success, or return the error code.
41 */
42int strfilter__or(struct strfilter *filter,
43 const char *rules, const char **err);
44
45/**
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
51 *
52 * Parse @rules and join it to the @filter by using logical-and.
53 * Return 0 if success, or return the error code.
54 */
55int strfilter__and(struct strfilter *filter,
56 const char *rules, const char **err);
57
68baa431
MH
58/**
59 * strfilter__compare - compare given string and a string filter
316c7136 60 * @filter: String filter
68baa431
MH
61 * @str: target string
62 *
316c7136 63 * Compare @str and @filter. Return true if the str match the rule
68baa431 64 */
316c7136 65bool strfilter__compare(struct strfilter *filter, const char *str);
68baa431
MH
66
67/**
68 * strfilter__delete - delete a string filter
316c7136 69 * @filter: String filter to delete
68baa431 70 *
316c7136 71 * Delete @filter.
68baa431 72 */
316c7136 73void strfilter__delete(struct strfilter *filter);
68baa431 74
3f51972c
MH
75/**
76 * strfilter__string - Reconstruct a rule string from filter
77 * @filter: String filter to reconstruct
78 *
79 * Reconstruct a rule string from @filter. This will be good for
80 * debug messages. Note that returning string must be freed afterward.
81 */
82char *strfilter__string(struct strfilter *filter);
83
68baa431 84#endif