Add a much better workaround for bug #8382 and some expert info.
[metze/wireshark/wip.git] / epan / filter_expressions.c
1 /* filter_expressions.c
2  * Submitted by Edwin Groothuis <wireshark@mavetju.org>
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <glib.h>
29
30 #include <epan/prefs.h>
31
32 #include "epan/filter_expressions.h"
33
34 static struct filter_expression *_filter_expression_head = NULL;
35 struct filter_expression **pfilter_expression_head = &_filter_expression_head;
36
37 /*
38  * Create a new filter_expression and add it to the end of the list
39  * of filter_expressions.
40  */
41 struct filter_expression *
42 filter_expression_new(const gchar *label, const gchar *expr,
43     const gboolean enabled)
44 {
45         struct filter_expression *expression;
46         struct filter_expression *prev;
47
48         expression = (struct filter_expression *)g_malloc(sizeof(struct filter_expression));
49         memset(expression, '\0', sizeof(struct filter_expression));
50         expression->button = NULL;
51         expression->label = g_strdup(label);
52         expression->expression = g_strdup(expr);
53         expression->enabled = enabled;
54         expression->deleted = FALSE;
55         expression->index = 0;
56
57         expression->next = NULL;
58
59         /* Add it at the end so the button order is always the same*/
60         if (*pfilter_expression_head == NULL) {
61                 _filter_expression_head = expression;
62         } else {
63                 prev = *pfilter_expression_head;
64                 while (prev->next != NULL)
65                         prev = prev->next;
66                 prev->next = expression;
67                 expression->index = prev->index + 1;
68         }
69
70         return(expression);
71 }
72
73 void
74 filter_expression_init(gboolean enable_prefs)
75 {
76         if (enable_prefs)
77                 prefs.filter_expressions = pfilter_expression_head;
78 }