diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-07 22:08:12 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-07 22:08:12 +0000 |
commit | b5f22bf8a82eac162550d248e182add5edcb9cc4 (patch) | |
tree | df15e06d1e44d84ced83537305176acca86a51df /epan | |
parent | 3cb23ec4f80d5eae31c3331863ea0213967cfdb6 (diff) |
eXtenstion options access to the -X command line options
svn path=/trunk/; revision=17207
Diffstat (limited to 'epan')
-rw-r--r-- | epan/Makefile.common | 2 | ||||
-rw-r--r-- | epan/ex-opt.c | 120 | ||||
-rw-r--r-- | epan/ex-opt.h | 44 |
3 files changed, 166 insertions, 0 deletions
diff --git a/epan/Makefile.common b/epan/Makefile.common index 1f27c3d84f..2d9c2d1f89 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -48,6 +48,7 @@ LIBETHEREAL_SRC = \ dtd_preparse.c \ emem.c \ epan.c \ + ex-opt.c \ except.c \ expert.c \ filesystem.c \ @@ -123,6 +124,7 @@ LIBETHEREAL_INCLUDES = \ epan.h \ epan_dissect.h \ etypes.h \ + ex-opt.h \ except.h \ exceptions.h \ expert.h \ diff --git a/epan/ex-opt.c b/epan/ex-opt.c new file mode 100644 index 0000000000..99d965664a --- /dev/null +++ b/epan/ex-opt.c @@ -0,0 +1,120 @@ +/* + * ex-opt.c + * + * Extension command line options + * + * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com> + * + * $Id: $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 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 "ex-opt.h" + +static GHashTable* ex_opts = NULL; + +gboolean ex_opt_add(const gchar* optarg) { + gchar** splitted; + + if (!ex_opts) + ex_opts = g_hash_table_new(g_str_hash,g_str_equal); + + splitted = g_strsplit(optarg,":",2); + + if (splitted[0] && splitted[1]) { + GPtrArray* this_opts = g_hash_table_lookup(ex_opts,splitted[0]); + + if (this_opts) { + g_ptr_array_add(this_opts,splitted[1]); + g_free(splitted[0]); + } else { + this_opts = g_ptr_array_new(); + g_ptr_array_add(this_opts,splitted[1]); + g_hash_table_insert(ex_opts,splitted[0],this_opts); + } + + g_free(splitted); + + return TRUE; + } else { + g_strfreev(splitted); + return FALSE; + } +} + +gint ex_opt_count(const gchar* key) { + GPtrArray* this_opts; + + if (! ex_opts) + return 0; + + this_opts = g_hash_table_lookup(ex_opts,key); + + if (this_opts) { + return this_opts->len; + } else { + return 0; + } +} + +const gchar* ex_opt_get_nth(const gchar* key, guint index) { + GPtrArray* this_opts; + + if (! ex_opts) + return 0; + + this_opts = g_hash_table_lookup(ex_opts,key); + + if (this_opts) { + if (this_opts->len > index) { + return g_ptr_array_index(this_opts,index); + } else { + /* XXX: assert? */ + return NULL; + } + } else { + return NULL; + } + +} + +extern const gchar* ex_opt_get_next(const gchar* key) { + GPtrArray* this_opts; + + if (! ex_opts) + return 0; + + this_opts = g_hash_table_lookup(ex_opts,key); + + if (this_opts) { + if (this_opts->len) + return g_ptr_array_remove_index(this_opts,0); + else + return NULL; + } else { + return NULL; + } +} + diff --git a/epan/ex-opt.h b/epan/ex-opt.h new file mode 100644 index 0000000000..614a5bfb51 --- /dev/null +++ b/epan/ex-opt.h @@ -0,0 +1,44 @@ +/* + * ex-opt.h + * + * eXtension command line options + * + * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com> + * + * $Id: $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998 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 _EX_OPT_H +#define _EX_OPT_H + +/* will be called by main each time a -X option is found */ +extern gboolean ex_opt_add(const gchar* optarg); + +/* yields the number of arguments of a given key obviously returns 0 if there aren't */ +extern gint ex_opt_count(const gchar* key); + +/* fetches the nth argument of a given key returns NULL if there isn't */ +extern const gchar* ex_opt_get_index(const gchar* key, guint index); + +/* extracts the next value of a given key */ +extern const gchar* ex_opt_get_next(const gchar* key); + +#endif
\ No newline at end of file |