Add another DL CRC error - Duplicate NonZero RV.
[obnox/wireshark/wip.git] / gtk / filter_utils.c
1 /* filter_utils.c
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gtk/gtk.h>
29 #include <string.h>
30
31 #include "gtk/main.h"
32 #include "gtk/gtkglobals.h"
33 #include "gtk/find_dlg.h"
34 #include "gtk/color_dlg.h"
35 #include "gtk/filter_utils.h"
36
37 #include "gtk/old-gtk-compat.h"
38
39 void
40 apply_selected_filter (guint callback_action, char *filter)
41 {
42         int action, type;
43         char *str = NULL;
44         const char *current_filter;
45
46         action = FILTER_ACTION(callback_action);
47         type = FILTER_ACTYPE(callback_action);
48
49         current_filter = gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
50
51         switch(type){
52         case ACTYPE_SELECTED:
53                 str = g_strdup_printf("%s", filter);
54                 break;
55         case ACTYPE_NOT_SELECTED:
56                 str = g_strdup_printf("!(%s)", filter);
57                 break;
58         case ACTYPE_AND_SELECTED:
59                 if ((!current_filter) || (0 == strlen(current_filter)))
60                         str = g_strdup_printf("%s", filter);
61                 else
62                         str = g_strdup_printf("(%s) && (%s)", current_filter, filter);
63                 break;
64         case ACTYPE_OR_SELECTED:
65                 if ((!current_filter) || (0 == strlen(current_filter)))
66                         str = g_strdup_printf("%s", filter);
67                 else
68                         str = g_strdup_printf("(%s) || (%s)", current_filter, filter);
69                 break;
70         case ACTYPE_AND_NOT_SELECTED:
71                 if ((!current_filter) || (0 == strlen(current_filter)))
72                         str = g_strdup_printf("!(%s)", filter);
73                 else
74                         str = g_strdup_printf("(%s) && !(%s)", current_filter, filter);
75                 break;
76         case ACTYPE_OR_NOT_SELECTED:
77                 if ((!current_filter) || (0 == strlen(current_filter)))
78                         str = g_strdup_printf("!(%s)", filter);
79                 else
80                         str = g_strdup_printf("(%s) || !(%s)", current_filter, filter);
81                 break;
82         }
83
84         switch(action){
85         case ACTION_MATCH:
86                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
87                 main_filter_packets(&cfile, str, FALSE);
88                 gdk_window_raise(gtk_widget_get_window(top_level));
89                 break;
90         case ACTION_PREPARE:
91                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
92                 break;
93         case ACTION_FIND_FRAME:
94                 find_frame_with_filter(str);
95                 break;
96         case ACTION_FIND_NEXT:
97                 cf_find_packet_dfilter_string(&cfile, str, SD_FORWARD);
98                 break;
99         case ACTION_FIND_PREVIOUS:
100                 cf_find_packet_dfilter_string(&cfile, str, SD_BACKWARD);
101                 break;
102         case ACTION_COLORIZE:
103                 color_display_with_filter(str);
104                 break;
105         }
106         g_free (str);
107 }