filter core, text module and gui module:
[lttv.git] / ltt / branches / poly / lttv / modules / text / textFilter.c
index f8a2ea4533ba92b25d09fbf317a39f9d114debac..488635caf7908cdc2904048b15bce23b7c4b7ecb 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the Linux Trace Toolkit viewer
- * Copyright (C) 2003-2004 Michel Dagenais
+ * Copyright (C) 2005 Simon Bouvier-Zappa 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License Version 2 as
  * MA 02111-1307, USA.
  */
 
-/* 
- * The text filter facility will prompt for user filter option 
- * and transmit them to the lttv core 
+/*! \file lttv/modules/text/textFilter.c
+ *  \brief Textual prompt for user filtering expression.
+ *  
+ *  The text filter facility will prompt for user filter option 
+ *  and transmit them to the lttv core.  User can either specify 
+ *  a filtering string with the command line or/and specify a 
+ *  file containing filtering expressions.
  */
 
 #include <lttv/lttv.h>
@@ -57,8 +61,6 @@ static LttvHooks
   *before_traceset,
   *event_hook;
 
-static FILE *a_file;
-
 /**
  * filters the file input from user
  * @param hook_data the hook data
@@ -66,8 +68,6 @@ static FILE *a_file;
  */
 void filter_analyze_file(void *hook_data) {
 
-  g_print("textFilter::filter_analyze_file\n");
   LttvAttributeValue value;
 
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
@@ -77,29 +77,23 @@ void filter_analyze_file(void *hook_data) {
         *      and/or command line string.  From these sources, an 
         *      option string is rebuilded and sent to the filter core
         */
-  GString* a_file_content = g_string_new("");
-  a_file = fopen(a_file_name, "r"); 
-       if(a_file == NULL) { 
-               g_warning("file %s does not exist", a_file_name);
+  if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) {
+    g_warning("file %s does not exist", a_file_name);
     return;
   }
-  
-  char* line = NULL;
-  size_t len = 0;
 
-  while(!feof(a_file)) {
-    len = getline(&line,&len,a_file);
-    g_string_append(a_file_content,line);
-  }
-  free(line);
+  char* a_file_content = NULL;
+
+  g_file_get_contents(a_file_name,&a_file_content,NULL,NULL);
   
   g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
       LTTV_POINTER, &value));
 
   if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
-  g_string_append((GString*)*(value.v_pointer),a_file_content->str);
+  g_string_append_c((GString*)*(value.v_pointer),'(');
+  g_string_append((GString*)*(value.v_pointer),a_file_content);
+  g_string_append_c((GString*)*(value.v_pointer),')');
   
-  fclose(a_file);
 }
 
 /**
@@ -109,8 +103,6 @@ void filter_analyze_file(void *hook_data) {
  */
 void filter_analyze_string(void *hook_data) {
 
-  g_print("textFilter::filter_analyze_string\n");
-
   LttvAttributeValue value;
 
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
@@ -120,24 +112,14 @@ void filter_analyze_string(void *hook_data) {
         *      and/or command line string.  From these sources, an 
         *      option string is rebuilded and sent to the filter core
         */
-/*  if(a_filter_string==NULL) {
-    a_filter_string = g_string_new("");
-    g_string_append(a_filter_string,a_string);
-  }
-  else {
-    g_string_append(a_filter_string,"&"); 
-    g_string_append(a_filter_string,a_string);
-  }
-*/
-  
   g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
       LTTV_POINTER, &value));
 
   if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&');
+  g_string_append_c((GString*)*(value.v_pointer),'(');
   g_string_append((GString*)*(value.v_pointer),a_string);
+  g_string_append_c((GString*)*(value.v_pointer),')');
 
-//  LttvFilter* filter = lttv_filter_new();
-//  lttv_filter_append_expression(filter,a_string);
 }
 
 /**
@@ -145,8 +127,6 @@ void filter_analyze_string(void *hook_data) {
  */
 static void init() {
   
-  g_print("textFilter::init()\n");     /* debug */
-
   LttvAttributeValue value;
 
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
This page took 0.033624 seconds and 4 git commands to generate.