tools/perf/util/strfilter.c
Source file repositories/reference/linux-study-clean/tools/perf/util/strfilter.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/strfilter.c- Extension
.c- Size
- 6407 bytes
- Lines
- 313
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
string2.hstrfilter.herrno.hstdlib.hlinux/ctype.hlinux/string.hlinux/zalloc.h
Detected Declarations
function strfilter_node__deletefunction strfilter__deletefunction strfilter__appendfunction strfilter__orfunction strfilter__andfunction strfilter_node__comparefunction strfilter__comparefunction strfilter_node__sprint_ptfunction strfilter_node__sprint
Annotated Snippet
if (*(p - 1) == '\\' || (*p == '!' && *(p - 1) == '[')) {
p++;
goto retry;
}
}
end:
*e = p;
return s;
}
static struct strfilter_node *strfilter_node__alloc(const char *op,
struct strfilter_node *l,
struct strfilter_node *r)
{
struct strfilter_node *node = zalloc(sizeof(*node));
if (node) {
node->p = op;
node->l = l;
node->r = r;
}
return node;
}
static struct strfilter_node *strfilter_node__new(const char *s,
const char **ep)
{
struct strfilter_node root, *cur, *last_op;
const char *e;
if (!s)
return NULL;
memset(&root, 0, sizeof(root));
last_op = cur = &root;
s = get_token(s, &e);
while (*s != '\0' && *s != ')') {
switch (*s) {
case '&': /* Exchg last OP->r with AND */
if (!cur->r || !last_op->r)
goto error;
cur = strfilter_node__alloc(OP_and, last_op->r, NULL);
if (!cur)
goto nomem;
last_op->r = cur;
last_op = cur;
break;
case '|': /* Exchg the root with OR */
if (!cur->r || !root.r)
goto error;
cur = strfilter_node__alloc(OP_or, root.r, NULL);
if (!cur)
goto nomem;
root.r = cur;
last_op = cur;
break;
case '!': /* Add NOT as a leaf node */
if (cur->r)
goto error;
cur->r = strfilter_node__alloc(OP_not, NULL, NULL);
if (!cur->r)
goto nomem;
cur = cur->r;
break;
case '(': /* Recursively parses inside the parenthesis */
if (cur->r)
goto error;
cur->r = strfilter_node__new(s + 1, &s);
if (!s)
goto nomem;
if (!cur->r || *s != ')')
goto error;
e = s + 1;
break;
default:
if (cur->r)
goto error;
cur->r = strfilter_node__alloc(NULL, NULL, NULL);
if (!cur->r)
goto nomem;
cur->r->p = strndup(s, e - s);
if (!cur->r->p)
goto nomem;
}
s = get_token(e, &e);
}
if (!cur->r)
goto error;
Annotation
- Immediate include surface: `string2.h`, `strfilter.h`, `errno.h`, `stdlib.h`, `linux/ctype.h`, `linux/string.h`, `linux/zalloc.h`.
- Detected declarations: `function strfilter_node__delete`, `function strfilter__delete`, `function strfilter__append`, `function strfilter__or`, `function strfilter__and`, `function strfilter_node__compare`, `function strfilter__compare`, `function strfilter_node__sprint_pt`, `function strfilter_node__sprint`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.