- Move setting _U_ into config.h, because
[obnox/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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdlib.h>
30 #include <glib.h>
31
32 #include <epan/prefs.h>
33
34 #include "epan/filter_expressions.h"
35
36 static struct filter_expression *_filter_expression_head = NULL;
37 struct filter_expression **pfilter_expression_head = &_filter_expression_head;
38
39 /*
40  * Create a new filter_expression and add it to the end of the list
41  * of filter_expressions.
42  */
43 struct filter_expression *
44 filter_expression_new(const gchar *label, const gchar *expr,
45     const gboolean enabled)
46 {
47         struct filter_expression *expression;
48         struct filter_expression *prev;
49
50         expression = (struct filter_expression *)g_malloc(sizeof(struct filter_expression));
51         memset(expression, '\0', sizeof(struct filter_expression));
52         expression->button = NULL;
53         expression->label = g_strdup(label);
54         expression->expression = g_strdup(expr);
55         expression->enabled = enabled;
56         expression->deleted = FALSE;
57         expression->index = 0;
58
59         expression->next = NULL;
60
61         /* Add it at the end so the button order is always the same*/
62         if (*pfilter_expression_head == NULL) {
63                 _filter_expression_head = expression;
64         } else {
65                 prev = *pfilter_expression_head;
66                 while (prev->next != NULL)
67                         prev = prev->next;
68                 prev->next = expression;
69                 expression->index = prev->index + 1;
70         }
71
72         return(expression);
73 }
74
75 void
76 filter_expression_init(gboolean enable_prefs)
77 {
78         if (enable_prefs)
79                 prefs.filter_expressions = pfilter_expression_head;
80 }