2 * Routines to register "-z" command-line argument handlers for stats
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
35 #include <epan/stat_cmd_args.h>
37 /* structure to keep track of what stats have registered command-line
40 typedef struct _stat_cmd_arg {
42 void (*func)(const char *arg);
44 static GSList *stat_cmd_arg_list=NULL;
46 /* structure to keep track of what stats have been specified on the
53 static GSList *stats_requested = NULL;
55 /* **********************************************************************
56 * Function called from stat to register the stat's command-line argument
57 * and initialization routine
58 * ********************************************************************** */
60 sort_by_name(gconstpointer a, gconstpointer b)
62 return strcmp(((const stat_cmd_arg *)a)->cmd,
63 ((const stat_cmd_arg *)b)->cmd);
66 register_stat_cmd_arg(const char *cmd, void (*func)(const char *arg))
70 newsca=g_malloc(sizeof(stat_cmd_arg));
73 stat_cmd_arg_list=g_slist_insert_sorted(stat_cmd_arg_list, newsca,
77 /* **********************************************************************
78 * Function called for a stat command-line argument
79 * ********************************************************************** */
81 process_stat_cmd_arg(char *optarg)
87 for(entry=stat_cmd_arg_list;entry;entry=g_slist_next(entry)){
89 if(!strncmp(sca->cmd,optarg,strlen(sca->cmd))){
90 tr=g_malloc(sizeof (stat_requested));
92 tr->arg=g_strdup(optarg);
93 stats_requested=g_slist_append(stats_requested, tr);
100 /* **********************************************************************
101 * Function to list all possible tap command-line arguments
102 * ********************************************************************** */
104 list_stat_cmd_args(void)
109 for(entry=stat_cmd_arg_list;entry;entry=g_slist_next(entry)){
111 fprintf(stderr," %s\n",sca->cmd);
115 /* **********************************************************************
116 * Function to process stats requested with command-line arguments
117 * ********************************************************************** */
119 start_requested_stats(void)
123 while(stats_requested){
124 sr=stats_requested->data;
125 (*sr->sca->func)(sr->arg);
128 stats_requested=g_slist_remove(stats_requested, sr);