From Ronald Henderson: make "format_text()", on Windows, escape all
[obnox/wireshark/wip.git] / proto_hier_stats.c
index 4153f884d893ea17f5af31c0df78f730705e8fc4..9ff7041c6016b628790648f4b684187f688b7e6f 100644 (file)
@@ -1,7 +1,7 @@
 /* proto_hier_stats.c
  * Routines for calculating statistics based on protocol.
  *
- * $Id: proto_hier_stats.c,v 1.12 2002/03/05 05:58:28 guy Exp $
+ * $Id: proto_hier_stats.c,v 1.16 2002/08/28 21:00:41 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -86,7 +86,7 @@ process_node(proto_item *ptree_node, GNode *parent_stat_node, ph_stats_t *ps, gu
        g_assert(finfo);
 
        stat_node = find_stat_node(parent_stat_node, finfo->hfinfo);
-       
+
        /* Assert that the finfo is related to a protocol, not a field. */
        g_assert(finfo->hfinfo->parent == -1);
 
@@ -152,11 +152,12 @@ ph_stats_new(void)
        ph_stats_t      *ps;
        frame_data      *frame;
        guint           tot_packets, tot_bytes;
-       progdlg_t       *progbar;
+       progdlg_t       *progbar = NULL;
        gboolean        stop_flag;
-       guint32         progbar_quantum;
-       guint32         progbar_nextstep;
-       unsigned int    count;
+       int             count;
+       float           prog_val;
+       GTimeVal        start_time;
+       gchar           status_str[100];
 
        /* Initialize the data */
        ps = g_new(ph_stats_t, 1);
@@ -165,16 +166,15 @@ ph_stats_new(void)
        ps->stats_tree = g_node_new(NULL);
 
        /* Update the progress bar when it gets to this value. */
-       progbar_nextstep = 0;
+       cfile.progbar_nextstep = 0;
        /* When we reach the value that triggers a progress bar update,
           bump that value by this amount. */
-       progbar_quantum = cfile.count/N_PROGBAR_UPDATES;
+       cfile.progbar_quantum = cfile.count/N_PROGBAR_UPDATES;
        /* Count of packets at which we've looked. */
        count = 0;
 
        stop_flag = FALSE;
-       progbar = create_progress_dlg("Computing protocol statistics", "Stop",
-           &stop_flag);
+       g_get_current_time(&start_time);
 
        tot_packets = 0;
        tot_bytes = 0;
@@ -186,16 +186,27 @@ ph_stats_new(void)
                   may involve an "ioctl()" to see if there's any pending
                   input from an X server, and doing that for every packet
                   can be costly, especially on a big file. */
-               if (count >= progbar_nextstep) {
+               if (count >= cfile.progbar_nextstep) {
                        /* let's not divide by zero. I should never be started
                         * with count == 0, so let's assert that
                         */
                        g_assert(cfile.count > 0);
 
-                       update_progress_dlg(progbar,
-                           (gfloat) count / cfile.count);
+                       prog_val = (gfloat) count / cfile.count;
+
+                       if (progbar == NULL)
+                               /* Create the progress bar if necessary */
+                               progbar = delayed_create_progress_dlg(
+                                   "Computing", "protocol hierarchy statistics", "Stop",
+                                   &stop_flag, &start_time, prog_val);
+
+                       if (progbar != NULL) {
+                               g_snprintf(status_str, sizeof(status_str),
+                                       "%4u of %u frames", count, cfile.count);
+                               update_progress_dlg(progbar, prog_val, status_str);
+                       }
 
-                       progbar_nextstep += progbar_quantum;
+                       cfile.progbar_nextstep += cfile.progbar_quantum;
                }
 
                if (stop_flag) {
@@ -219,8 +230,10 @@ ph_stats_new(void)
                count++;
        }
 
-       /* We're done calculating the statistics; destroy the progress bar. */
-       destroy_progress_dlg(progbar);
+       /* We're done calculating the statistics; destroy the progress bar
+           if it was created. */
+       if (progbar != NULL)
+               destroy_progress_dlg(progbar);
 
        if (stop_flag) {
                /*
@@ -239,7 +252,7 @@ ph_stats_new(void)
 }
 
 static gboolean
-stat_node_free(GNode *node, gpointer data)
+stat_node_free(GNode *node, gpointer data _U_)
 {
        ph_stats_node_t *stats = node->data;