-lttv_filter_new(char *expression, LttvTrace *t) {
-
- unsigned
- i,
- p=0, /* parenthesis nesting value */
- b=0; /* current breakpoint in expression string */
-
- gpointer tree;
-
- GString *current_option = g_string_new("");
- lttv_simple_expression current_expression;
-
- g_print("filter::lttv_filter_new()\n"); /* debug */
-
- /*
- * 1. parse expression
- * 2. construct binary tree
- * 3. return corresponding filter
- */
-
- /*
- * Binary tree memory allocation
- * - based upon a preliminary block size
- */
- gulong size = (strlen(expression)/6) * 1.5;
- tree = g_malloc(size*sizeof(lttv_filter_tree));
-
- /*
- * Parse entire expression and construct
- * the binary tree. There are two steps
- * in browsing that string
- * 1. finding boolean ops ( &,|,^,! ) and parenthesis
- * 2. finding simple expressions
- * - field path
- * - op ( >, <, =, >=, <=, !=)
- * - value
- */
-
- for(i=0;i<strlen(expression);i++) {
- switch(expression[i]) {
- /*
- * boolean operators
- */
- case '&': /* and */
- parse_simple_expression(current_option);
- g_print("%s\n",¤t_option);
- current_option = g_string_new("");
- break;
- case '|': /* or */
- g_print("%s\n",current_option);
- current_option = g_string_new("");
- break;
- case '^': /* xor */
- g_print("%s\n",current_option);
- current_option = g_string_new("");
- break;
- case '!': /* not, or not equal (math op) */
- if(expression[i+1] == '=') { /* != */
- current_expression.op = LTTV_FIELD_NE;
- i++;
- } else { /* ! */
- g_print("%s\n",current_option);
- current_option = g_string_new("");
- }
- break;
- case '(': /* start of parenthesis */
- p++;
- break;
- case ')': /* end of parenthesis */
- p--;
- break;
-
- /*
- * mathematic operators
- */
- case '<': /* lower, lower or equal */
- if(expression[i+1] == '=') { /* <= */
- i++;
- current_expression.op = LTTV_FIELD_LE;
- } else current_expression.op = LTTV_FIELD_LT;
- break;
- case '>': /* higher, higher or equal */
- if(expression[i+1] == '=') { /* >= */
- i++;
- current_expression.op = LTTV_FIELD_GE;
- } else current_expression.op = LTTV_FIELD_GT;
- break;
- case '=': /* equal */
- current_expression.op = LTTV_FIELD_EQ;
- break;
- default: /* concatening current string */
- g_string_append_c(current_option,expression[i]);
- }
- }