aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2007-01-18 02:54:56 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2007-01-18 02:54:56 +0000
commit80dcfb23d2dc85dde9591cbcaae6127c5f9f5c37 (patch)
treec7d8bc2e9a8fd2c9f05c45494723a1f87ea5bfef
parent3e9ac49497c59ca683a6f31d12cab2018c3a9d75 (diff)
display filter macros.
NOT to be copied over to release 0.99.5 svn path=/trunk/; revision=20467
-rw-r--r--epan/dfilter/Makefile.am9
-rw-r--r--epan/dfilter/Makefile.nmake10
-rw-r--r--epan/dfilter/dfilter-macro.c428
-rw-r--r--epan/dfilter/dfilter-macro.h65
-rw-r--r--epan/dfilter/dfilter.c23
-rw-r--r--epan/dfilter/dfilter_macro_load.l136
-rw-r--r--gtk/macros_dlg.c80
-rw-r--r--gtk/macros_dlg.h24
-rw-r--r--gtk/menu.c6
9 files changed, 775 insertions, 6 deletions
diff --git a/epan/dfilter/Makefile.am b/epan/dfilter/Makefile.am
index 99ef072d1a..9120450c2d 100644
--- a/epan/dfilter/Makefile.am
+++ b/epan/dfilter/Makefile.am
@@ -34,6 +34,8 @@ DISTCLEANFILES = \
grammar.h
MAINTAINERCLEANFILES = \
+ dfilter-macro.c \
+ dfilter_macro_load.c \
Makefile.in \
grammar.c \
grammar.h \
@@ -46,6 +48,9 @@ libdfilter_la_SOURCES = \
dfilter.c \
dfilter.h \
dfilter-int.h \
+ dfilter-macro.h \
+ dfilter-macro.c \
+ dfilter_macro_load.c \
dfunctions.c \
dfunctions.h \
dfvm.c \
@@ -78,6 +83,9 @@ EXTRA_DIST = \
scanner.l \
Makefile.nmake
+dfilter_macro_load.c : dfilter_macro_load.l
+ $(LEX) -Pdf_ -odfilter_macro_load.c $(srcdir)/dfilter_macro_load.l
+
scanner.c : scanner.l
@if [ ! -x "$(LEX)" ]; then \
echo "Neither lex nor flex was found"; \
@@ -93,4 +101,3 @@ grammar.h : grammar.c
grammar.c : grammar.lemon $(LEMON)/lemon$(EXEEXT)
$(LEMON)/lemon$(EXEEXT) t=$(srcdir)/$(LEMON)/lempar.c $(srcdir)/grammar.lemon || \
(rm -f grammar.c grammar.h ; false)
-
diff --git a/epan/dfilter/Makefile.nmake b/epan/dfilter/Makefile.nmake
index 1d5f4fb9a4..974009ac91 100644
--- a/epan/dfilter/Makefile.nmake
+++ b/epan/dfilter/Makefile.nmake
@@ -20,6 +20,9 @@ CVARSDLL=-DWIN32 -DNULL=0 -D_MT -D_DLL
OBJECTS = \
dfilter.obj \
+ dfilter-macro.obj \
+ dfilter_macro_expand.obj \
+ dfilter_macro_load.obj \
dfunctions.obj \
dfvm.obj \
drange.obj \
@@ -63,6 +66,13 @@ distclean: clean
maintainer-clean: distclean
+
+dfilter_macro_expand.c : dfilter_macro_expand.l
+ $(LEX) -Pdf_ -odfilter_macro_expand.c $(srcdir)/dfilter_macro_expand.l
+
+dfilter_macro_load.c : dfilter_macro_load.l
+ $(LEX) -Pdf_ -odfilter_macro_load.c $(srcdir)/dfilter_macro_load.l
+
scanner.c : scanner.l
$(LEX) -Pdf_ -oscanner.c scanner.l
diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c
new file mode 100644
index 0000000000..ec5a11bdab
--- /dev/null
+++ b/epan/dfilter/dfilter-macro.c
@@ -0,0 +1,428 @@
+/* dfilter-macro.c
+ *
+ * $Id: dfilter_macro_expand.l 18197 2006-05-21 05:12:17Z sahlberg $
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "dfilter-int.h"
+#include "dfilter.h"
+#include "dfilter-macro.h"
+#include <epan/emem.h>
+
+dfilter_macro_t* macros = NULL;
+
+void dfilter_macro_foreach(dfilter_macro_cb_t cb, void* data) {
+ dfilter_macro_t* c;
+
+ for (c = macros; c; c = c->next) {
+ cb(c,data);
+ }
+ return;
+}
+
+static void macro_fprint(dfilter_macro_t* m, void* ud) {
+ FILE* f = ud;
+
+ fprintf(f,"%s\t%s\n",m->name,m->text);
+}
+
+void dfilter_macro_save(const gchar* filename, gchar** error) {
+ FILE* f = fopen(filename,"w");
+
+ if (!f) {
+ *error = ep_strdup_printf("Could not open file: '%s', error: %s\n", filename, strerror(errno) );
+ return;
+ }
+
+ dfilter_macro_foreach(macro_fprint, f);
+
+ fclose(f);
+
+ return;
+}
+
+#ifdef DUMP_MACROS
+static void macro_dump(dfilter_macro_t* m _U_, void* ud _U_) {
+ gchar** part = m->parts;
+ int* args_pos = m->args_pos;
+
+ printf("\n->%s\t%s\t%d\n\t'%s'\n",
+ m->name, m->text, m->argc, *(part++));
+
+ while (*part) {
+ printf("\t$%d '%s'\n",*args_pos,*part);
+
+ args_pos++;
+ part++;
+ }
+}
+#endif
+
+void dfilter_macro_dump(void) {
+#ifdef DUMP_MACROS
+ dfilter_macro_foreach(macro_dump, NULL);
+#endif
+}
+
+gchar* dfilter_macro_resolve(gchar* name, gchar** args, gchar** error) {
+ GString* text;
+ int argc = 0;
+ dfilter_macro_t* m;
+ int* arg_pos_p;
+ gchar** parts;
+ gchar* ret;
+
+ for (m = macros; m; m = m->next) {
+ if ( g_str_equal(m->name,name) ) break;
+ }
+
+ if (!m) {
+ *error = ep_strdup_printf("macro '%s' does not exist", name);
+ return NULL;
+ }
+
+ if (args) {
+ while(args[argc]) argc++;
+ }
+
+ if (argc != m->argc) {
+ *error = ep_strdup_printf("wrong number of arguments for macro '%s', expecting %d instead of %d",
+ name, m->argc, argc);
+ return NULL;
+ }
+
+ arg_pos_p = m->args_pos;
+ parts = m->parts;
+
+ text = g_string_new(*(parts++));
+
+ while (*parts) {
+ g_string_sprintfa(text,"%s%s",
+ args[*(arg_pos_p++)],
+ *(parts++));
+ }
+
+ ret = ep_strdup(text->str);
+
+ g_string_free(text,TRUE);
+
+ return ret;
+}
+
+void dfilter_macro_add(const gchar* name, const gchar* text, gchar** error) {
+ dfilter_macro_t* m;
+ GPtrArray* parts;
+ GArray* args_pos;
+ const gchar* r;
+ gchar* w;
+ gchar* part;
+ int argc = 0;
+
+ *error = NULL;
+
+ for (m = macros; m; m = m->next) {
+ if ( g_str_equal(m->name,name) ) {
+ *error = ep_strdup_printf("macro '%s' exists already", name);
+ return;
+ }
+ }
+
+ m = g_malloc(sizeof(dfilter_macro_t));
+ m->name = g_strdup(name);
+ m->text = g_strdup(text);
+
+ parts = g_ptr_array_new();
+ args_pos = g_array_new(FALSE,FALSE,sizeof(int));
+
+ m->priv = part = w = g_strdup(text);
+ r = text;
+ g_ptr_array_add(parts,part);
+
+ do {
+
+ switch (*r) {
+ default:
+ *(w++) = *(r++);
+ break;
+ case '\0':
+ *(w++) = *(r++);
+ goto done;
+ case '\\':
+ *(w++) = *(++r);
+ r++;
+ break;
+ case '$': {
+ int cnt = 0;
+ int arg_pos = 0;
+ do {
+ char c = *(r+1);
+ if (c >= '0' && c <= '9') {
+ cnt++;
+ r++;
+ arg_pos *= 10;
+ arg_pos += c - '0';
+ } else {
+ break;
+ }
+ } while(1);
+
+ if (cnt) {
+ *(w++) = '\0';
+ r++;
+ argc = argc < arg_pos ? arg_pos : argc;
+ arg_pos--;
+ g_array_append_val(args_pos,arg_pos);
+ g_ptr_array_add(parts,w);
+ } else {
+ *(w++) = *(r++);
+ }
+ break;
+ }
+ }
+
+ } while(1);
+
+done:
+ g_ptr_array_add(parts,NULL);
+ m->parts = (gchar**)parts->pdata;
+
+ m->args_pos = (int*)args_pos->data;
+
+ g_ptr_array_free(parts,FALSE);
+ g_array_free(args_pos,FALSE);
+
+ m->argc = argc;
+ m->next = macros;
+ macros = m;
+
+ return;
+}
+
+void dfilter_macro_remove(const gchar* name, gchar** error) {
+ dfilter_macro_t* m;
+ dfilter_macro_t* p = NULL;
+
+ for (m = macros; m; m = m->next) {
+ if ( g_str_equal(m->name,name) ) {
+ p = m;
+ break;
+ }
+ }
+
+ if (!m) {
+ *error = ep_strdup_printf("macro '%s' does not exist", name);
+ return;
+ }
+
+ if (p) {
+ p->next = m->next;
+ } else {
+ macros = m->next;
+ }
+
+ g_free(m->name);
+ g_free(m->text);
+ g_free(m->priv);
+ g_free(m->parts);
+ g_free(m->args_pos);
+ g_free(m);
+}
+
+
+
+gchar* dfilter_macro_apply(const gchar* text, guint depth, gchar** error) {
+ enum { OUTSIDE, STARTING, NAME, ARGS } state = OUTSIDE;
+ GString* out;
+ GString* name = NULL;
+ GString* arg = NULL;
+ GPtrArray* args = NULL;
+ gchar c;
+ const gchar* r = text;
+ gboolean changed = FALSE;
+
+ if ( depth > 31) {
+ *error = "too much nesting in macros";
+ return NULL;
+ }
+
+#define FGS(n) if (n) g_string_free(n,TRUE); n = NULL
+
+#define FREE_ALL() do { \
+ FGS(name); \
+ FGS(arg); \
+ if (args) { \
+ while(args->len) { void* p = g_ptr_array_remove_index_fast(args,0); if (p) g_free(p); } \
+ g_ptr_array_free(args,TRUE); \
+ args = NULL; } } while(0)
+
+ *error = NULL;
+ out = g_string_sized_new(64);
+
+ while(1) {
+ c = *r++;
+
+ switch(state) {
+ case OUTSIDE: {
+ switch(c) {
+ case '\0': {
+ goto finish;
+ } case '$': {
+ state = STARTING;
+ break;
+ } default: {
+ g_string_append_c(out,c);
+ break;
+ }
+ }
+ break;
+ } case STARTING: {
+ switch (c) {
+ case '{': {
+ args = g_ptr_array_new();
+ arg = g_string_sized_new(32);
+ name = g_string_sized_new(32);
+
+ state = NAME;
+
+ break;
+ } case '\0': {
+ g_string_append_c(out,'$');
+
+ goto finish;
+ } default: {
+ g_string_append_c(out,'$');
+ g_string_append_c(out,c);
+
+ state = OUTSIDE;
+
+ break;
+ }
+ }
+ break;
+ } case NAME: {
+ if ( isalnum(c) || c == '_' ) {
+ g_string_append_c(name,c);
+ } else if ( c == ':') {
+ state = ARGS;
+ } else if ( c == '}') {
+ gchar* resolved;
+
+ g_ptr_array_add(args,NULL);
+
+ resolved = dfilter_macro_resolve(name->str, (gchar**)args->pdata, error);
+ if (*error) goto on_error;
+
+ changed = TRUE;
+
+ g_string_append(out,resolved);
+
+ FREE_ALL();
+
+ state = OUTSIDE;
+ } else if ( c == '\0') {
+ *error = "end of filter in the middle of a macro expression";
+ goto on_error;
+ } else {
+ *error = "invalid char in macro name";
+ goto on_error;
+ }
+ break;
+ } case ARGS: {
+ switch(c) {
+ case '\0': {
+ *error = "end of filter in the middle of a macro expression";
+ goto on_error;
+ } case ';': {
+ g_ptr_array_add(args,arg->str);
+ g_string_free(arg,FALSE);
+
+ arg = g_string_sized_new(32);
+ break;
+ } case '\\': {
+ c = *r++;
+ if (c) {
+ g_string_append_c(arg,c);
+ break;
+ } else {
+ *error = "end of filter in the middle of a macro expression";
+ goto on_error;
+ }
+ } default: {
+ g_string_append_c(arg,c);
+ break;
+ } case '}': {
+ gchar* resolved;
+ g_ptr_array_add(args,arg->str);
+ g_ptr_array_add(args,NULL);
+
+ g_string_free(arg,FALSE);
+ arg = NULL;
+
+ resolved = dfilter_macro_resolve(name->str, (gchar**)args->pdata, error);
+ if (*error) goto on_error;
+
+ changed = TRUE;
+
+ g_string_append(out,resolved);
+
+ FREE_ALL();
+
+ state = OUTSIDE;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+finish:
+ {
+ FREE_ALL();
+
+ if (changed) {
+ gchar* resolved = dfilter_macro_apply(out->str, depth++, error);
+ g_string_free(out,TRUE);
+ return (*error) ? NULL : resolved;
+ } else {
+ gchar* out_str = ep_strdup(out->str);
+ g_string_free(out,TRUE);
+ return out_str;
+ }
+ }
+on_error:
+ {
+ FREE_ALL();
+ if (! *error) *error = "unknown error in macro expression";
+ g_string_free(out,TRUE);
+ return NULL;
+ }
+}
+
diff --git a/epan/dfilter/dfilter-macro.h b/epan/dfilter/dfilter-macro.h
new file mode 100644
index 0000000000..9e6b5a00be
--- /dev/null
+++ b/epan/dfilter/dfilter-macro.h
@@ -0,0 +1,65 @@
+/* dfilter-macro.h
+ *
+ * $Id: $
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _DFILTER_MACRO_H
+#define _DFILTER_MACRO_H
+
+#define DFILTER_MACRO_FILENAME "df_macros"
+
+
+typedef struct _dfilter_macro_t {
+ gchar* name; /* the macro id */
+ gchar* text; /* raw data from file */
+ gchar** parts; /* various segments of text between insertion targets */
+ int* args_pos; /* what's to be inserted */
+ int argc; /* the expected number of arguments */
+ void* priv; /* a copy of text that contains every c-string in parts */
+ struct _dfilter_macro_t* next; /* in macros list */
+} dfilter_macro_t;
+
+/* loop over the macros list */
+typedef void (*dfilter_macro_cb_t)(dfilter_macro_t*, void*);
+void dfilter_macro_foreach(dfilter_macro_cb_t, void*);
+
+/* add a macro to the list, text s raw text from file */
+void dfilter_macro_add(const gchar* name, const gchar* text, gchar** error);
+
+/* remove a macro from the list */
+void dfilter_macro_remove(const gchar* name, gchar** error);
+
+/* loads the macros from file in userdir or else datadir */
+gboolean dfilter_macro_load(gchar** error);
+
+/* save the macro list to file */
+void dfilter_macro_save(const gchar* filename, gchar** error);
+
+/* dumps the macros in the list (debug info, not formated as in the macros file) */
+void dfilter_macro_dump(void);
+
+/* given a macro_name and its arguments returns an ep_allocated string */
+gchar* dfilter_macro_resolve(gchar* macro_name, gchar** macro_args, gchar** error);
+
+/* applies all macros to the given text and returns the resulting string or NULL on failure */
+gchar* dfilter_macro_apply(const gchar* text, guint depth, gchar** error);
+
+#endif /* _DFILTER_MACRO_H */ \ No newline at end of file
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c
index a2bb2ecd61..06a9dd55a2 100644
--- a/epan/dfilter/dfilter.c
+++ b/epan/dfilter/dfilter.c
@@ -34,6 +34,8 @@
#include "dfvm.h"
#include <epan/epan_dissect.h>
#include "dfilter.h"
+#include "dfilter-macro.h"
+#include <epan/report_err.h>
#define DFILTER_TOKEN_ID_OFFSET 1
@@ -42,7 +44,7 @@ static gchar dfilter_error_msg_buf[1024];
gchar *dfilter_error_msg; /* NULL when no error resulted */
/* From scanner.c */
-void df_scanner_text(const char *text);
+void df_scanner_text(const char *text);
void df_scanner_cleanup(void);
int df_lex(void);
@@ -71,6 +73,8 @@ dfilter_fail(const char *format, ...)
void
dfilter_init(void)
{
+ gchar* err;
+
if (ParserObj) {
g_message("I expected ParserObj to be NULL\n");
/* Free the Lemon Parser object */
@@ -86,9 +90,15 @@ dfilter_init(void)
/* Trace parser */
DfilterTrace(stdout, "lemon> ");
#endif
-
+
/* Initialize the syntax-tree sub-sub-system */
sttype_init();
+
+ if ( ! dfilter_macro_load(&err) ) {
+ if (err) {
+ report_failure("%s",err);
+ }
+ }
}
/* Clean-up the dfilter module */
@@ -182,8 +192,7 @@ dfwork_free(dfwork_t *dfw)
if (dfw->insns) {
free_insns(dfw->insns);
}
-
-
+
g_free(dfw);
}
@@ -195,9 +204,13 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
dfilter_t *dfilter;
dfwork_t *dfw;
gboolean failure = FALSE;
-
+
dfilter_error_msg = NULL;
+ if ( !( text = dfilter_macro_apply(text, 0, &dfilter_error_msg) ) ) {
+ return FALSE;
+ }
+
dfw = dfwork_new();
df_scanner_text(text);
diff --git a/epan/dfilter/dfilter_macro_load.l b/epan/dfilter/dfilter_macro_load.l
new file mode 100644
index 0000000000..52f4a4a187
--- /dev/null
+++ b/epan/dfilter/dfilter_macro_load.l
@@ -0,0 +1,136 @@
+%option never-interactive
+%option prefix="dfml_"
+%option outfile="dfilter_macro_load.c"
+%option nounput
+%option noyywrap
+%{
+/* dfilter_macro_load.l
+ *
+ * $Id: dfilter_macro_expand.l 18197 2006-05-21 05:12:17Z sahlberg $
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "dfilter-int.h"
+#include "dfilter.h"
+#include "dfilter-macro.h"
+#include <epan/emem.h>
+#include <epan/filesystem.h>
+
+ static char* macro_name;
+ static char* macro_body;
+ static gchar* err;
+ static const gchar* fname;
+ static int linenum;
+
+%}
+name [a-zA-Z][-_[:alnum:]]*
+colon ":"
+body [^\r\n]+
+nl [\r]?\n
+ws [:blank:]+
+
+%START GET_NAME GET_COLON GET_BODY GET_NL
+%%
+<GET_NAME>[:blank:]*[\r]?\n ; /* ignore empty lines*/
+
+<GET_NAME>{name} { macro_name = ep_strdup(yytext); BEGIN GET_COLON; }
+<GET_NAME>{ws} ;
+<GET_NAME>. {
+ err = ep_strdup_printf("%s:%d: unexpected char at: '%s'", fname, linenum, yytext);
+ yyterminate();
+}
+
+<GET_COLON>{colon} { BEGIN GET_BODY; };
+<GET_COLON>{ws} ;
+<GET_COLON>. {
+ err = ep_strdup_printf("%s:%d: unexpected char at: '%s'", fname, linenum, yytext);
+ yyterminate();
+}
+
+<GET_BODY>{body} { macro_body = ep_strdup(yytext); BEGIN GET_NL; }
+<GET_BODY>{nl} {
+ err = ep_strdup_printf("%s:%d: empty body", fname, linenum);
+ yyterminate();
+}
+
+<GET_NL>{nl} {
+ dfilter_macro_add(macro_name, macro_body, &err);
+ if (err) yyterminate();
+ BEGIN GET_NAME;
+}
+<GET_NL><<EOF>> {
+ dfilter_macro_add(macro_name, macro_body, &err);
+ if (err) yyterminate();
+ return 1;
+}
+
+%%
+
+gboolean dfilter_macro_load(gchar** error) {
+
+ linenum = 1;
+ macro_name = NULL;
+ macro_body = NULL;
+ err = NULL;
+ *error = NULL;
+
+ fname = get_persconffile_path(DFILTER_MACRO_FILENAME,FALSE);
+
+ yyin = fopen(fname,"r");
+
+ if (!yyin) {
+ if(errno != ENOENT) {
+ *error = ep_strdup_printf("Could not open file: '%s', error: %s\n", fname, strerror(errno));
+ return FALSE;
+ }
+
+ fname = get_datafile_path(DFILTER_MACRO_FILENAME);
+
+ yyin = fopen(fname,"r");
+
+ if (!yyin) {
+ if(errno != ENOENT) {
+ *error = ep_strdup_printf("Could not open file: '%s', error: %s\n", fname, strerror(errno));
+ return FALSE;
+ } else {
+ return TRUE;
+ }
+ }
+ }
+
+ BEGIN GET_NAME;
+
+ yylex();
+
+ if (err) {
+ *error = err;
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff --git a/gtk/macros_dlg.c b/gtk/macros_dlg.c
new file mode 100644
index 0000000000..05ffee4d26
--- /dev/null
+++ b/gtk/macros_dlg.c
@@ -0,0 +1,80 @@
+/* macros_dlg.c
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <gtk/gtk.h>
+#include <epan/dfilter/dfilter-macro.h>
+#include "dlg_utils.h"
+#include "gui_utils.h"
+#include "compat_macros.h"
+
+static void append_macro(dfilter_macro_t* m, void* lp) {
+ GtkWidget *list = lp;
+ simple_list_append(list, 0, m->name, 1, m->text, -1);
+}
+
+void macros_dialog_cb(GtkWidget *w _U_, gpointer data _U_) {
+ GtkWidget *macros_w, *vbox;
+ GtkWidget *scrolledwindow;
+ GtkWidget *list;
+ const gchar *titles[] = {"Name", "Text"};
+
+ macros_w = window_new(GTK_WINDOW_TOPLEVEL, "Display Filter Macros");
+ gtk_window_set_default_size(GTK_WINDOW(macros_w), 650, 600);
+
+#if GTK_MAJOR_VERSION >= 2
+ gtk_window_set_position(GTK_WINDOW(macros_w), GTK_WIN_POS_CENTER_ON_PARENT);
+#else
+ gtk_window_set_position(GTK_WINDOW(macros_w), GTK_WIN_POS_CENTER);
+#endif
+
+ gtk_container_border_width(GTK_CONTAINER(macros_w), 6);
+
+ vbox = gtk_vbox_new(FALSE, 12);
+ gtk_container_border_width(GTK_CONTAINER(vbox), 6);
+ gtk_container_add(GTK_CONTAINER(macros_w), vbox);
+
+ scrolledwindow = scrolled_window_new(NULL, NULL);
+ gtk_container_add(GTK_CONTAINER(vbox), scrolledwindow);
+
+#if GTK_MAJOR_VERSION >= 2
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
+ GTK_SHADOW_IN);
+#endif
+
+ list = simple_list_new(2 , titles);
+ dfilter_macro_foreach(append_macro, list);
+ gtk_container_add(GTK_CONTAINER(scrolledwindow), list);
+
+ gtk_widget_show_all(macros_w);
+
+ return;
+}
+
diff --git a/gtk/macros_dlg.h b/gtk/macros_dlg.h
new file mode 100644
index 0000000000..680520eecb
--- /dev/null
+++ b/gtk/macros_dlg.h
@@ -0,0 +1,24 @@
+/* macros_dlg.h
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+void macros_dialog_cb(GtkWidget *w _U_, gpointer data _U_);
diff --git a/gtk/menu.c b/gtk/menu.c
index 176a56caf7..afe091733c 100644
--- a/gtk/menu.c
+++ b/gtk/menu.c
@@ -82,6 +82,7 @@
#include "sctp_stat.h"
#include "firewall_dlg.h"
#include "u3.h"
+#include "macros_dlg.h"
GtkWidget *popup_menu_object;
@@ -523,6 +524,11 @@ static GtkItemFactoryEntry menu_items[] =
ITEM_FACTORY_STOCK_ENTRY("/View/_Coloring Rules...", NULL, color_display_cb,
0, GTK_STOCK_SELECT_COLOR),
ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+
+ ITEM_FACTORY_ENTRY("/View/Display Filter _Macros...", NULL, macros_dialog_cb, 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/View/<separator>", NULL, NULL, 0, "<Separator>", NULL),
+
+
ITEM_FACTORY_ENTRY("/View/Show Packet in New _Window", NULL,
new_window_cb, 0, NULL, NULL),
ITEM_FACTORY_STOCK_ENTRY("/View/_Reload", "<control>R", file_reload_cmd_cb,