Clean-up: consumer.hpp: coding style indentation fix
[lttng-tools.git] / src / common / filter / filter-visitor-ir-normalize-glob-patterns.cpp
1 /*
2 * filter-visitor-ir-normalize-glob-patterns.c
3 *
4 * LTTng filter IR normalize string
5 *
6 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
7 *
8 * SPDX-License-Identifier: LGPL-2.1-only
9 *
10 */
11
12 #include "filter-ast.hpp"
13 #include "filter-ir.hpp"
14 #include "filter-parser.hpp"
15
16 #include <common/compat/errno.hpp>
17 #include <common/macros.hpp>
18 #include <common/string-utils/string-utils.hpp>
19
20 #include <inttypes.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 static int normalize_glob_patterns(struct ir_op *node)
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) {
39 enum ir_load_string_type type = node->u.load.u.string.type;
40 if (type == IR_LOAD_STRING_TYPE_GLOB_STAR_END ||
41 type == IR_LOAD_STRING_TYPE_GLOB_STAR) {
42 LTTNG_ASSERT(node->u.load.u.string.value);
43 strutils_normalize_star_glob_pattern(node->u.load.u.string.value);
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 */
76 int 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.029883 seconds and 4 git commands to generate.