aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dfilter
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-04-29 07:55:32 +0000
committerGuy Harris <guy@alum.mit.edu>2002-04-29 07:55:32 +0000
commit30f02bc99cb3a578758c76cc6cb0c8278273e6be (patch)
treea3155a07ee4729db28f98e60122b25f4f6a714a0 /epan/dfilter
parent6c553bf99839b464efb77891dfb9b9d473b1a6b5 (diff)
Move the code to build the balanced tree of fields into "proto_init()",
move the code from "dfilter_lookup_token()" into "proto_registrar_get_byname()", and get rid of "dfilter_lookup_token()" and have its callers call "proto_registrar_get_byname()" instead. svn path=/trunk/; revision=5287
Diffstat (limited to 'epan/dfilter')
-rw-r--r--epan/dfilter/dfilter-int.h7
-rw-r--r--epan/dfilter/dfilter.c95
-rw-r--r--epan/dfilter/scanner.l7
3 files changed, 5 insertions, 104 deletions
diff --git a/epan/dfilter/dfilter-int.h b/epan/dfilter/dfilter-int.h
index 1bd2f04754..4397e001c1 100644
--- a/epan/dfilter/dfilter-int.h
+++ b/epan/dfilter/dfilter-int.h
@@ -1,5 +1,5 @@
/*
- * $Id: dfilter-int.h,v 1.5 2002/01/21 07:37:37 guy Exp $
+ * $Id: dfilter-int.h,v 1.6 2002/04/29 07:55:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -57,11 +57,6 @@ void Dfilter(void*, int, stnode_t*, dfwork_t*);
/* Scanner's lval */
extern stnode_t *df_lval;
-/* Given a field abbreviation, returns the proto ID, or -1 if
- * it doesn't exist. */
-header_field_info*
-dfilter_lookup_token(char *abbrev);
-
/* Set dfilter_error_msg_buf and dfilter_error_msg */
void
dfilter_fail(char *format, ...);
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c
index d0afc3eaed..19af1c3179 100644
--- a/epan/dfilter/dfilter.c
+++ b/epan/dfilter/dfilter.c
@@ -1,5 +1,5 @@
/*
- * $Id: dfilter.c,v 1.8 2002/04/08 20:11:31 gram Exp $
+ * $Id: dfilter.c,v 1.9 2002/04/29 07:55:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -38,15 +38,8 @@
#include "dfvm.h"
#include <epan/epan_dissect.h>
-
-/* Balanced tree of abbreviations and IDs */
-static GTree *dfilter_tokens = NULL;
-
#define DFILTER_TOKEN_ID_OFFSET 1
-/* Comparision function for tree insertion. A wrapper around strcmp() */
-static int g_strcmp(gconstpointer a, gconstpointer b);
-
/* Global error message space for dfilter_compile errors */
static gchar dfilter_error_msg_buf[1024];
gchar *dfilter_error_msg; /* NULL when no error resulted */
@@ -85,68 +78,6 @@ dfilter_fail(char *format, ...)
void
dfilter_init(void)
{
- int id, num_symbols;
- char *abbrev;
- header_field_info *hfinfo, *same_name_hfinfo, *same_name_next_hfinfo;
-
- num_symbols = proto_registrar_n();
-
- if (dfilter_tokens) {
- /* XXX - needed? */
- g_message("I expected hf_ids to be NULL\n");
- g_tree_destroy(dfilter_tokens);
-
- /* Make sure the hfinfo->same_name links are broken */
- for (id = 0; id < num_symbols; id++) {
- hfinfo = proto_registrar_get_nth(id);
- hfinfo->same_name_next = NULL;
- hfinfo->same_name_prev = NULL;
- }
- }
- dfilter_tokens = g_tree_new(g_strcmp);
-
- /* Populate the abbrev/ID GTree (header-field symbol table) */
-
-
- for (id = 0; id < num_symbols; id++) {
- if (id == hf_text_only) {
- continue;
- }
- abbrev = proto_registrar_get_abbrev(id);
- hfinfo = proto_registrar_get_nth(id);
-
- g_assert(abbrev); /* Not Null */
- g_assert(abbrev[0] != 0); /* Not empty string */
-
- /* We allow multiple hfinfo's to be registered under the same
- * abbreviation. This was done for X.25, as, depending
- * on whether it's modulo-8 or modulo-128 operation,
- * some bitfield fields may be in different bits of
- * a byte, and we want to be able to refer to that field
- * with one name regardless of whether the packets
- * are modulo-8 or modulo-128 packets. */
- same_name_hfinfo = g_tree_lookup(dfilter_tokens, abbrev);
- if (same_name_hfinfo) {
- /* There's already a field with this name.
- * Put it after that field in the list of
- * fields with this name, then allow the code
- * after this if{} block to replace the old
- * hfinfo with the new hfinfo in the GTree. Thus,
- * we end up with a linked-list of same-named hfinfo's,
- * with the root of the list being the hfinfo in the GTree */
- same_name_next_hfinfo =
- same_name_hfinfo->same_name_next;
-
- hfinfo->same_name_next = same_name_next_hfinfo;
- if (same_name_next_hfinfo)
- same_name_next_hfinfo->same_name_prev = hfinfo;
-
- same_name_hfinfo->same_name_next = hfinfo;
- hfinfo->same_name_prev = same_name_hfinfo;
- }
- g_tree_insert(dfilter_tokens, abbrev, hfinfo);
- }
-
if (ParserObj) {
g_message("I expected ParserObj to be NULL\n");
/* Free the Lemon Parser object */
@@ -163,12 +94,6 @@ dfilter_init(void)
void
dfilter_cleanup(void)
{
- /* Free the abbrev/ID GTree */
- if (dfilter_tokens) {
- g_tree_destroy(dfilter_tokens);
- dfilter_tokens = NULL;
- }
-
/* Free the Lemon Parser object */
if (ParserObj) {
DfilterFree(ParserObj, g_free);
@@ -178,24 +103,6 @@ dfilter_cleanup(void)
sttype_cleanup();
}
-
-
-/* Lookup an abbreviation in our token tree, returing the ID #
- * If the abbreviation doesn't exit, returns -1 */
-header_field_info*
-dfilter_lookup_token(char *abbrev)
-{
- g_assert(abbrev != NULL);
- return g_tree_lookup(dfilter_tokens, abbrev);
-}
-
-/* String comparison func for dfilter_token GTree */
-static int
-g_strcmp(gconstpointer a, gconstpointer b)
-{
- return strcmp((const char*)a, (const char*)b);
-}
-
static dfilter_t*
dfilter_new(void)
{
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index e508e691a3..c65c12dcc9 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -1,11 +1,10 @@
%{
/*
- * $Id: scanner.l,v 1.6 2002/04/11 03:26:26 gram Exp $
+ * $Id: scanner.l,v 1.7 2002/04/29 07:55:32 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* 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
@@ -131,7 +130,7 @@ static gboolean str_to_guint32(char *s, guint32* pint);
/* Is it a field name? */
header_field_info *hfinfo;
- hfinfo = dfilter_lookup_token(yytext);
+ hfinfo = proto_registrar_get_byname(yytext);
if (hfinfo) {
/* Yes, it's a field name */
return set_lval(TOKEN_FIELD, hfinfo);