fixed some errors !
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
CommitLineData
9c312311 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
31452f49 19/*
48f6f3c2 20 consist in AND, OR and NOT nested expressions, forming a tree with
21 simple relations as leaves. The simple relations test is a field
22 in an event is equal, not equal, smaller, smaller or equal, larger, or
23 larger or equal to a specified value. */
24
31452f49 25#include <lttv/filter.h>
26
31452f49 27/*
28 read_token
48f6f3c2 29
31452f49 30 read_expression
31 ( read expr )
32 simple expr [ op expr ]
48f6f3c2 33
31452f49 34 read_simple_expression
35 read_field_path [ rel value ]
48f6f3c2 36
31452f49 37 read_field_path
38 read_field_component [. field path]
48f6f3c2 39
31452f49 40 read_field_component
41 name [ \[ value \] ]
48f6f3c2 42
31452f49 43 data struct:
44 and/or(left/right)
45 not(child)
46 op(left/right)
47 path(component...) -> field
48*/
49
50/**
84a333d6 51 * Add an filtering option to the current tree
52 * @param expression Current expression to parse
53 * @return success/failure of operation
54 */
55gboolean
56parse_simple_expression(GString* expression) {
57
58 unsigned i;
59
74b3f7ee 60// for(i=0;i<strlen(expression);i++) {
61//
62// }
84a333d6 63}
64
65/**
66 * Creates a new lttv_filter
31452f49 67 * @param expression filtering options string
68 * @param t pointer to the current LttvTrace
84a333d6 69 * @return the current lttv_filter or NULL if error
31452f49 70 */
71lttv_filter*
72lttv_filter_new(char *expression, LttvTrace *t) {
48f6f3c2 73
84a333d6 74 unsigned
75 i,
76 p=0, /* parenthesis nesting value */
77 b=0; /* current breakpoint in expression string */
78
79 gpointer tree;
80
e854143a 81 GString *current_option = g_string_new("");
82 lttv_simple_expression current_expression;
83
31452f49 84 g_print("filter::lttv_filter_new()\n"); /* debug */
48f6f3c2 85
31452f49 86 /*
87 * 1. parse expression
88 * 2. construct binary tree
89 * 3. return corresponding filter
90 */
91
84a333d6 92 /*
93 * Binary tree memory allocation
94 * - based upon a preliminary block size
95 */
96 gulong size = (strlen(expression)/6) * 1.5;
97 tree = g_malloc(size*sizeof(lttv_filter_tree));
98
99 /*
100 * Parse entire expression and construct
e854143a 101 * the binary tree. There are two steps
74b3f7ee 102 * in browsing that string
103 * 1. finding boolean ops ( &,|,^,! ) and parenthesis
104 * 2. finding simple expressions
105 * - field path
106 * - op ( >, <, =, >=, <=, !=)
107 * - value
108 */
109
84a333d6 110 for(i=0;i<strlen(expression);i++) {
111 switch(expression[i]) {
74b3f7ee 112 /*
113 * boolean operators
114 */
84a333d6 115 case '&': /* and */
74b3f7ee 116 parse_simple_expression(current_option);
117 g_print("%s\n",&current_option);
118 current_option = g_string_new("");
84a333d6 119 break;
120 case '|': /* or */
74b3f7ee 121 g_print("%s\n",current_option);
122 current_option = g_string_new("");
84a333d6 123 break;
124 case '^': /* xor */
74b3f7ee 125 g_print("%s\n",current_option);
126 current_option = g_string_new("");
84a333d6 127 break;
e854143a 128 case '!': /* not, or not equal (math op) */
74b3f7ee 129 if(expression[i+1] == '=') { /* != */
130 current_expression.op = LTTV_FIELD_NE;
131 i++;
132 } else { /* ! */
133 g_print("%s\n",current_option);
134 current_option = g_string_new("");
135 }
136 break;
84a333d6 137 case '(': /* start of parenthesis */
138 p++;
139 break;
140 case ')': /* end of parenthesis */
141 p--;
142 break;
74b3f7ee 143
144 /*
145 * mathematic operators
146 */
147 case '<': /* lower, lower or equal */
148 if(expression[i+1] == '=') { /* <= */
149 i++;
150 current_expression.op = LTTV_FIELD_LE;
151 } else current_expression.op = LTTV_FIELD_LT;
152 break;
153 case '>': /* higher, higher or equal */
154 if(expression[i+1] == '=') { /* >= */
155 i++;
156 current_expression.op = LTTV_FIELD_GE;
157 } else current_expression.op = LTTV_FIELD_GT;
158 break;
159 case '=': /* equal */
160 current_expression.op = LTTV_FIELD_EQ;
161 break;
84a333d6 162 default: /* concatening current string */
74b3f7ee 163 g_string_append_c(current_option,expression[i]);
84a333d6 164 }
84a333d6 165 }
31452f49 166
84a333d6 167 if( p>0 ) {
168 g_warning("Wrong filtering options, the string\n\"%s\"\n\
169 is not valid due to parenthesis incorrect use",expression);
170 return NULL;
171 }
31452f49 172}
173
84a333d6 174/**
175 * Apply the filter to a specific trace
176 * @param filter the current filter applied
177 * @param tracefile the trace to apply the filter to
178 * @return success/failure of operation
179 */
31452f49 180gboolean
181lttv_filter_tracefile(lttv_filter *filter, void *tracefile) {
182
183}
184
84a333d6 185/**
186 * Apply the filter to a specific event
187 * @param filter the current filter applied
188 * @param event the event to apply the filter to
189 * @return success/failure of operation
190 */
31452f49 191gboolean
192lttv_filter_event(lttv_filter *filter, void *event) {
193
194}
This page took 0.038216 seconds and 4 git commands to generate.