(Temporarily) Allow DCE/RPC dissector table to have duplicates.
[metze/wireshark/wip.git] / epan / filter_expressions.c
1 /* filter_expressions.c
2  * Submitted by Edwin Groothuis <wireshark@mavetju.org>
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <glib.h>
28
29 #include <epan/prefs.h>
30
31 #include "epan/filter_expressions.h"
32
33 static struct filter_expression *_filter_expression_head = NULL;
34 struct filter_expression **pfilter_expression_head = &_filter_expression_head;
35
36 /*
37  * Create a new filter_expression and add it to the end of the list
38  * of filter_expressions.
39  */
40 struct filter_expression *
41 filter_expression_new(const gchar *label, const gchar *expr,
42                       const gboolean enabled)
43 {
44         struct filter_expression *expression;
45         struct filter_expression *prev;
46
47     expression = (struct filter_expression *)g_malloc0(sizeof(struct filter_expression));
48         expression->label = g_strdup(label);
49         expression->expression = g_strdup(expr);
50         expression->enabled = enabled;
51
52         /* Add it at the end so the button order is always the same*/
53         if (*pfilter_expression_head == NULL) {
54                 _filter_expression_head = expression;
55         } else {
56                 prev = *pfilter_expression_head;
57                 while (prev->next != NULL)
58                         prev = prev->next;
59                 prev->next = expression;
60                 expression->index = prev->index + 1;
61         }
62
63         return(expression);
64 }
65
66 void
67 filter_expression_init(gboolean enable_prefs)
68 {
69         if (enable_prefs)
70                 prefs.filter_expressions = pfilter_expression_head;
71 }
72
73 void
74 filter_expression_free(struct filter_expression *list_head)
75 {
76     if (list_head == NULL)
77         return;
78     filter_expression_free(list_head->next);
79     g_free(list_head->label);
80     g_free(list_head->expression);
81 }
82
83
84
85 /*
86  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
87  *
88  * Local variables:
89  * c-basic-offset: 8
90  * tab-width: 8
91  * indent-tabs-mode: t
92  * End:
93  *
94  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
95  * :indentSize=8:tabSize=8:noTabs=false:
96  */