95d85f59effbc796cb7d78ec5842ab9d1f21c010
[obnox/wireshark/wip.git] / dftest.c
1 /* dftest.c.c
2  *
3  * $Id: dftest.c,v 1.1 2001/02/01 20:21:13 gram Exp $
4  *
5  * Ethereal - Network traffic analyzer
6  * By Gerald Combs <gerald@zing.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * Shows display filter byte-code, for debugging dfilter routines.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <locale.h>
34 #include <string.h>
35 #include <errno.h>
36
37 #if 0
38
39 #ifdef HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42
43
44 #ifdef HAVE_SYS_TYPES_H
45 #include <sys/types.h>
46 #endif
47
48 #ifdef HAVE_SYS_STAT_H
49 #include <sys/stat.h>
50 #endif
51
52 #ifdef HAVE_FCNTL_H
53 #include <fcntl.h>
54 #endif
55
56 #include <signal.h>
57
58 #ifdef NEED_SNPRINTF_H
59 # include "snprintf.h"
60 #endif
61 #endif
62
63 #ifdef NEED_STRERROR_H
64 #include "strerror.h"
65 #endif
66
67 #include <glib.h>
68 #include <epan.h>
69
70 #if 0
71 #include "globals.h"
72 #include "packet.h"
73 #include "file.h"
74 #include "column.h"
75 #include "print.h"
76 #include "resolv.h"
77 #include "conversation.h"
78 #endif
79 #include "timestamp.h"
80 #include "plugins.h"
81 #include "prefs.h"
82 #include "util.h"
83 #include "epan/dfilter/dfilter.h"
84
85 packet_info     pi;
86 ts_type         timestamp_type = RELATIVE;
87
88 int
89 main(int argc, char **argv)
90 {
91         char            *text;
92         char            *gpf_path, *pf_path;
93         int             gpf_open_errno, pf_open_errno;
94         e_prefs         *prefs;
95         dfilter_t       *df;
96
97         /* register all dissectors; we must do this before checking for the
98         "-g" flag, as the "-g" flag dumps a list of fields registered
99         by the dissectors, and we must do it before we read the preferences,
100         in case any dissectors register preferences. */
101         epan_init(PLUGIN_DIR);
102
103         /* now register the preferences for any non-dissector modules.
104         we must do that before we read the preferences as well. */
105         prefs_register_modules();
106
107         /* set the c-language locale to the native environment. */
108         setlocale(LC_ALL, "");
109
110         prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path);
111         if (gpf_path != NULL) {
112                 fprintf(stderr, "can't open global preferences file \"%s\": %s.\n",
113                                 pf_path, strerror(gpf_open_errno));
114         }
115         if (pf_path != NULL) {
116                 fprintf(stderr, "can't open your preferences file \"%s\": %s.\n",
117                                 pf_path, strerror(pf_open_errno));
118         }
119
120         /* notify all registered modules that have had any of their preferences
121         changed either from one of the preferences file or from the command
122         line that its preferences have changed. */
123         prefs_apply_all();
124
125         /* Check for filter on command line */
126         if (argc <= 1) {
127                 fprintf(stderr, "Usage: dftest filter\n");
128                 exit(1);
129         }
130
131         /* Get filter text */
132         text = get_args_as_string(argc, argv, 1);
133
134         printf("Filter: \"%s\"\n", text);
135  
136         /* Compile it */
137         if (!dfilter_compile(text, &df)) {
138                 fprintf(stderr, "dftest: %s\n", dfilter_error_msg);
139                 epan_cleanup();
140                 exit(2);
141         }
142         printf("dfilter ptr = 0x%08x\n", (unsigned int) df);
143
144         printf("\n\n");
145
146         dfilter_dump(df);
147
148         epan_cleanup();
149         exit(0);
150 }