diff options
author | Bill Meier <wmeier@newsguy.com> | 2012-09-15 14:08:48 +0000 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2012-09-15 14:08:48 +0000 |
commit | b69bbdf6acaa8fbdc396dc90c537c86ebffb86ca (patch) | |
tree | f185f02d367df9d240d664fca8b3abcac6707ad2 /ui | |
parent | dd01cc049038b934c19a33c4d2d01082ee58ca67 (diff) |
Trivial cleanup;
Remove a few unneeded initializers;
Fix a few typos in comments;
Use consistent formatting style.
svn path=/trunk/; revision=44917
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/bootp_stat.c | 132 |
1 files changed, 67 insertions, 65 deletions
diff --git a/ui/gtk/bootp_stat.c b/ui/gtk/bootp_stat.c index d8bbed7185..be93c3f044 100644 --- a/ui/gtk/bootp_stat.c +++ b/ui/gtk/bootp_stat.c @@ -47,7 +47,7 @@ typedef const char* bootp_info_value_t; -/* used to keep track of the statictics for an entire program interface */ +/* used to keep track of the statistics for an entire program interface */ typedef struct _dhcp_stats_t { char *filter; GtkWidget *win; @@ -55,6 +55,7 @@ typedef struct _dhcp_stats_t { GtkWidget *table_message_type; guint index; /* Number of to display */ } dhcpstat_t; + /* used to keep track of a single DHCP message type */ typedef struct _dhcp_message_type_t { const char *name; @@ -64,12 +65,12 @@ typedef struct _dhcp_message_type_t { } dhcp_message_type_t; static void -dhcp_free_hash( gpointer key _U_ , gpointer value, gpointer user_data _U_ ) +dhcp_free_hash(gpointer key _U_ , gpointer value, gpointer user_data _U_) { g_free(value); } static void -dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_ ) +dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_) { data->packets = 0; } @@ -78,63 +79,63 @@ dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_ ) * or create it if it don't exist. */ static void -dhcp_draw_message_type(gchar *key _U_, dhcp_message_type_t *data, gchar * unused _U_ ) +dhcp_draw_message_type(gchar *key _U_, dhcp_message_type_t *data, gchar * unused _U_) { char string_buff[256]; - if ((data==NULL) || (data->packets==0)) + if ((data == NULL) || (data->packets == 0)) return; - if (data->widget==NULL){ /* create an entry in the table */ - GtkWidget *tmp; + if (data->widget == NULL) { /* create an entry in the table */ + GtkWidget *tmp; int x = 2*((data->sp->index) % 2); int y = (data->sp->index) /2; /* Maybe we should display the hexadecimal value ? */ /* g_snprintf(string_buff, sizeof(string_buff), "%s (0X%x)", data->name, *key); */ - tmp = gtk_label_new( data->name /* string_buff */ ); + tmp = gtk_label_new(data->name /* string_buff */); gtk_table_attach_defaults(GTK_TABLE(data->sp->table_message_type), tmp, x, x+1, y, y+1); gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT); gtk_widget_show(tmp); - g_snprintf( string_buff, sizeof(string_buff), "%9d", data->packets ); - data->widget = gtk_label_new( string_buff ); + g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets); + data->widget = gtk_label_new(string_buff); gtk_table_attach_defaults(GTK_TABLE(data->sp->table_message_type), data->widget, x+1, x+2, y, y+1); gtk_label_set_justify(GTK_LABEL(data->widget), GTK_JUSTIFY_LEFT); - gtk_widget_show( data->widget ); + gtk_widget_show(data->widget); data->sp->index++; } else { /* Just update the label string */ - g_snprintf( string_buff, sizeof(string_buff), "%9d", data->packets ); - gtk_label_set_text( GTK_LABEL(data->widget), string_buff); + g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets); + gtk_label_set_text(GTK_LABEL(data->widget), string_buff); } } static void dhcpstat_reset(void *psp) { - dhcpstat_t *sp=psp; - g_hash_table_foreach( sp->hash, (GHFunc)dhcp_reset_hash, NULL); + dhcpstat_t *sp = psp; + g_hash_table_foreach(sp->hash, (GHFunc)dhcp_reset_hash, NULL); } static int dhcpstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri) { - dhcpstat_t *sp=psp; - const bootp_info_value_t value=pri; - dhcp_message_type_t *sc; + dhcpstat_t *sp = psp; + const bootp_info_value_t value = pri; + dhcp_message_type_t *sc; - if (sp==NULL) + if (sp == NULL) return 0; sc = g_hash_table_lookup( sp->hash, value); if (!sc) { /*g_warning("%s:%d What's Wrong for %s, doc ?", __FILE__, __LINE__, value);*/ - sc = g_malloc( sizeof(dhcp_message_type_t) ); - sc -> packets = 1; - sc -> name = value; - sc -> widget=NULL; - sc -> sp = sp; + sc = g_malloc(sizeof(dhcp_message_type_t)); + sc ->packets = 1; + sc ->name = value; + sc ->widget = NULL; + sc ->sp = sp; g_hash_table_insert( sp->hash, (gpointer) value, @@ -150,39 +151,39 @@ dhcpstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, cons static void dhcpstat_draw(void *psp) { - dhcpstat_t *sp=psp; - guint idx; + dhcpstat_t *sp = psp; + guint idx; - idx=sp->index; - g_hash_table_foreach( sp->hash, (GHFunc) dhcp_draw_message_type, NULL ); - if (idx != sp->index){ + idx = sp->index; + g_hash_table_foreach(sp->hash, (GHFunc)dhcp_draw_message_type, NULL); + if (idx != sp->index) { /* We have inserted a new entry corresponding to a status code , * let's resize the table */ - gtk_table_resize ( GTK_TABLE(sp->table_message_type), sp->index % 2 , 4); + gtk_table_resize(GTK_TABLE(sp->table_message_type), sp->index % 2 , 4); } } -/* since the gtk2 implementation of tap is multithreaded we must protect +/* Since the gtk2 implementation of tap is multithreaded we must protect * remove_tap_listener() from modifying the list while draw_tap_listener() - * is running. the other protected block is in main.c + * is running. The other protected block is in main.c * - * there should not be any other critical regions in gtk2 + * There should not be any other critical regions in gtk2 */ static void win_destroy_cb(GtkWindow *win _U_, gpointer data) { - dhcpstat_t *sp=(dhcpstat_t *)data; + dhcpstat_t *sp = (dhcpstat_t *)data; protect_thread_critical_region(); remove_tap_listener(sp); unprotect_thread_critical_region(); g_free(sp->filter); - g_hash_table_foreach( sp->hash, (GHFunc)dhcp_free_hash, NULL); - g_hash_table_destroy( sp->hash); + g_hash_table_foreach(sp->hash, (GHFunc)dhcp_free_hash, NULL); + g_hash_table_destroy(sp->hash); g_free(sp); } @@ -193,33 +194,33 @@ static void dhcpstat_init(const char *optarg, void *userdata _U_) { dhcpstat_t *sp; - const char *filter=NULL; - char *title=NULL; - GString *error_string; - GtkWidget *message_type_fr; - GtkWidget *vbox; - GtkWidget *bt_close; - GtkWidget *bbox; - - if (strncmp (optarg, "bootp,stat,", 11) == 0){ - filter=optarg+11; + const char *filter; + char *title; + GString *error_string; + GtkWidget *message_type_fr; + GtkWidget *vbox; + GtkWidget *bt_close; + GtkWidget *bbox; + + if (strncmp(optarg, "bootp,stat,", 11) == 0) { + filter = optarg+11; } else { - filter=NULL; + filter = NULL; } - sp = g_malloc( sizeof(dhcpstat_t) ); - sp->hash = g_hash_table_new( g_str_hash, g_str_equal); - if(filter){ - sp->filter=g_strdup(filter); - title=g_strdup_printf("DHCP statistics with filter: %s", filter); + sp = g_malloc(sizeof(dhcpstat_t)); + sp->hash = g_hash_table_new(g_str_hash, g_str_equal); + if(filter) { + sp->filter = g_strdup(filter); + title = g_strdup_printf("DHCP statistics with filter: %s", filter); } else { - sp->filter=NULL; - title=g_strdup("DHCP statistics"); + sp->filter = NULL; + title = g_strdup("DHCP statistics"); } /* transient_for top_level */ - sp->win= dlg_window_new(title); - gtk_window_set_destroy_with_parent (GTK_WINDOW(sp->win), TRUE); + sp->win = dlg_window_new(title); + gtk_window_set_destroy_with_parent(GTK_WINDOW(sp->win), TRUE); g_free(title); vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE); @@ -228,13 +229,13 @@ dhcpstat_init(const char *optarg, void *userdata _U_) /* Status Codes frame */ message_type_fr = gtk_frame_new("DHCP Message Type"); - gtk_box_pack_start(GTK_BOX (vbox), message_type_fr, TRUE, TRUE, 0); - gtk_widget_show(message_type_fr); + gtk_box_pack_start(GTK_BOX(vbox), message_type_fr, TRUE, TRUE, 0); + gtk_widget_show(message_type_fr); - sp->table_message_type = gtk_table_new( 0, 4, FALSE); - gtk_table_set_col_spacings( GTK_TABLE(sp->table_message_type), 10); - gtk_container_add( GTK_CONTAINER( message_type_fr), sp->table_message_type); - gtk_container_set_border_width( GTK_CONTAINER(sp->table_message_type) , 10); + sp->table_message_type = gtk_table_new(0, 4, FALSE); + gtk_table_set_col_spacings(GTK_TABLE(sp->table_message_type), 10); + gtk_container_add(GTK_CONTAINER(message_type_fr), sp->table_message_type); + gtk_container_set_border_width(GTK_CONTAINER(sp->table_message_type) , 10); sp->index = 0; /* Nothing to display yet */ @@ -246,9 +247,9 @@ dhcpstat_init(const char *optarg, void *userdata _U_) dhcpstat_reset, dhcpstat_packet, dhcpstat_draw); - if (error_string){ + if (error_string) { /* error, we failed to attach to the tap. clean up */ - simple_dialog( ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str ); + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str); g_free(sp->filter); g_free(sp); g_string_free(error_string, TRUE); @@ -294,7 +295,8 @@ register_tap_listener_gtkdhcpstat(void) } -void bootp_dhcp_stat_cb(GtkAction *action, gpointer user_data _U_) +void +bootp_dhcp_stat_cb(GtkAction *action, gpointer user_data _U_) { tap_param_dlg_cb(action, &dhcp_stat_dlg); } |