Run clang-format on the whole tree
[lttng-tools.git] / src / common / filter / filter-visitor-ir-normalize-glob-patterns.cpp
CommitLineData
9f449915
PP
1/*
2 * filter-visitor-ir-normalize-glob-patterns.c
3 *
4 * LTTng filter IR normalize string
5 *
ab5be9fa 6 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
9f449915 7 *
ab5be9fa 8 * SPDX-License-Identifier: LGPL-2.1-only
9f449915 9 *
9f449915
PP
10 */
11
28ab034a
JG
12#include "filter-ast.hpp"
13#include "filter-ir.hpp"
14#include "filter-parser.hpp"
9f449915 15
c9e313bc
SM
16#include <common/compat/errno.hpp>
17#include <common/macros.hpp>
18#include <common/string-utils/string-utils.hpp>
9f449915 19
28ab034a
JG
20#include <inttypes.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
9f449915 25
28ab034a 26static int normalize_glob_patterns(struct ir_op *node)
9f449915
PP
27{
28 switch (node->op) {
29 case IR_OP_UNKNOWN:
30 default:
31 fprintf(stderr, "[error] %s: unknown op type\n", __func__);
32 return -EINVAL;
33
34 case IR_OP_ROOT:
35 return normalize_glob_patterns(node->u.root.child);
36 case IR_OP_LOAD:
37 {
38 if (node->data_type == IR_DATA_STRING) {
28ab034a 39 enum ir_load_string_type type = node->u.load.u.string.type;
9f449915 40 if (type == IR_LOAD_STRING_TYPE_GLOB_STAR_END ||
28ab034a 41 type == IR_LOAD_STRING_TYPE_GLOB_STAR) {
a0377dfe 42 LTTNG_ASSERT(node->u.load.u.string.value);
28ab034a 43 strutils_normalize_star_glob_pattern(node->u.load.u.string.value);
9f449915
PP
44 }
45 }
46
47 return 0;
48 }
49 case IR_OP_UNARY:
50 return normalize_glob_patterns(node->u.unary.child);
51 case IR_OP_BINARY:
52 {
53 int ret = normalize_glob_patterns(node->u.binary.left);
54
55 if (ret)
56 return ret;
57 return normalize_glob_patterns(node->u.binary.right);
58 }
59 case IR_OP_LOGICAL:
60 {
61 int ret;
62
63 ret = normalize_glob_patterns(node->u.logical.left);
64 if (ret)
65 return ret;
66 return normalize_glob_patterns(node->u.logical.right);
67 }
68 }
69}
70
71/*
72 * This function normalizes all the globbing literal strings with
73 * utils_normalize_glob_pattern(). See the documentation of
74 * utils_normalize_glob_pattern() for more details.
75 */
9f449915
PP
76int filter_visitor_ir_normalize_glob_patterns(struct filter_parser_ctx *ctx)
77{
78 return normalize_glob_patterns(ctx->ir_root);
79}
This page took 0.049182 seconds and 4 git commands to generate.