Make some other statusbar routines take a format string and format args,
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 27 Nov 2010 23:06:14 +0000 (23:06 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 27 Nov 2010 23:06:14 +0000 (23:06 +0000)
and get rid of an unnecessary string pointer.

Make the argument to welcome_header_push_msg() a const pointer.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35042 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/filter_dlg.c
gtk/main.c
gtk/main_statusbar.c
gtk/main_welcome.c
gtk/main_welcome.h
main_statusbar.h

index f9dcd166c04a25ae05e35eb6b27078ccbf2f5173..4f66921f886f4dc2c436c0a65f16f898dd0cb5c8 100644 (file)
@@ -1317,7 +1317,6 @@ filter_te_syntax_check_cb(GtkWidget *w, gpointer user_data _U_)
     dfilter_t   *dfp;
     GPtrArray   *depr = NULL;
     gboolean     use_statusbar;
-    gchar       *msg;
     guchar       c;
 
     strval = gtk_entry_get_text(GTK_ENTRY(w));
@@ -1333,9 +1332,7 @@ filter_te_syntax_check_cb(GtkWidget *w, gpointer user_data _U_)
     {
         colorize_filter_te_as_invalid(w);
         if (use_statusbar) {
-            msg = g_strdup_printf(" Illegal character in field name: '%c'", c);
-            statusbar_push_filter_msg(msg);
-            g_free(msg);
+            statusbar_push_filter_msg(" Illegal character in field name: '%c'", c);
         }
     } else if (strval && dfilter_compile(strval, &dfp)) {
         if (dfp != NULL) {
@@ -1362,9 +1359,7 @@ filter_te_syntax_check_cb(GtkWidget *w, gpointer user_data _U_)
         colorize_filter_te_as_invalid(w);
         if (use_statusbar) {
             if (dfilter_error_msg) {
-                msg = g_strdup_printf(" Invalid filter: %s", dfilter_error_msg);
-                statusbar_push_filter_msg(msg);
-                g_free(msg);
+                statusbar_push_filter_msg(" Invalid filter: %s", dfilter_error_msg);
             } else {
                 statusbar_push_filter_msg(" Invalid filter");
             }
index 367f249e34a9bd2cbaab8bee9d6549c891d16b99..47c2900a87f2f5e7cdee003744b01d4870bfc71b 100644 (file)
@@ -799,7 +799,6 @@ static void
 tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
 {
     field_info   *finfo;
-    gchar        *help_str = NULL;
     gchar         len_str[2+10+1+5+1]; /* ", {N} bytes\0",
                                           N < 4294967296 */
     gboolean      has_blurb = FALSE;
@@ -862,11 +861,9 @@ tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
         }
         statusbar_pop_field_msg();     /* get rid of current help msg */
         if (length) {
-            help_str = g_strdup_printf(" %s (%s)%s",
+            statusbar_push_field_msg(" %s (%s)%s",
                     (has_blurb) ? finfo->hfinfo->blurb : finfo->hfinfo->name,
                     finfo->hfinfo->abbrev, len_str);
-            statusbar_push_field_msg(help_str);
-            g_free(help_str);
         } else {
             /*
              * Don't show anything if the field name is zero-length;
index eae9b22b204fbe78fd03818681340cff411003fc..3553004856b91ac6815f7761366774cf7bdff39f 100644 (file)
@@ -103,11 +103,13 @@ static gint flash_time;
 static gboolean flash_highlight = FALSE;
 
 /*
- * Push a message referring to file access onto the statusbar.
+ * Push a formatted message referring to file access onto the statusbar.
  */
 static void
-statusbar_push_file_msg(const gchar *msg)
+statusbar_push_file_msg(const gchar *msg_format, ...)
 {
+    va_list ap;
+    gchar *msg;
     int i;
 
     /*g_warning("statusbar_push: %s", msg);*/
@@ -117,7 +119,12 @@ statusbar_push_file_msg(const gchar *msg)
     }
     status_levels[STATUS_LEVEL_FILE]++;
 
+    va_start(ap, msg_format);
+    msg = g_strdup_vprintf(msg_format, ap);
+    va_end(ap);
+
     gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, msg);
+    g_free(msg);
 }
 
 /*
@@ -134,11 +141,14 @@ statusbar_pop_file_msg(void)
 }
 
 /*
- * Push a message referring to the currently-selected field onto the statusbar.
+ * Push a formatted message referring to the currently-selected field onto
+ * the statusbar.
  */
 void
-statusbar_push_field_msg(const gchar *msg)
+statusbar_push_field_msg(const gchar *msg_format, ...)
 {
+    va_list ap;
+    gchar *msg;
     int i;
 
     for (i = STATUS_LEVEL_HELP + 1; i < NUM_STATUS_LEVELS; i++) {
@@ -147,7 +157,12 @@ statusbar_push_field_msg(const gchar *msg)
     }
     status_levels[STATUS_LEVEL_HELP]++;
 
+    va_start(ap, msg_format);
+    msg = g_strdup_vprintf(msg_format, ap);
+    va_end(ap);
+
     gtk_statusbar_push(GTK_STATUSBAR(info_bar), help_ctx, msg);
+    g_free(msg);
 }
 
 /*
@@ -163,11 +178,13 @@ statusbar_pop_field_msg(void)
 }
 
 /*
- * Push a message referring to the current filter onto the statusbar.
+ * Push a formatted message referring to the current filter onto the statusbar.
  */
 void
-statusbar_push_filter_msg(const gchar *msg)
+statusbar_push_filter_msg(const gchar *msg_format, ...)
 {
+    va_list ap;
+    gchar *msg;
     int i;
 
     for (i = STATUS_LEVEL_FILTER + 1; i < NUM_STATUS_LEVELS; i++) {
@@ -176,7 +193,12 @@ statusbar_push_filter_msg(const gchar *msg)
     }
     status_levels[STATUS_LEVEL_FILTER]++;
 
+    va_start(ap, msg_format);
+    msg = g_strdup_vprintf(msg_format, ap);
+    va_end(ap);
+
     gtk_statusbar_push(GTK_STATUSBAR(info_bar), filter_ctx, msg);
+    g_free(msg);
 }
 
 /*
@@ -587,7 +609,6 @@ static void
 statusbar_set_filename(const char *file_name, gint64 file_length, nstime_t *file_elapsed_time)
 {
     gchar       *size_str;
-    gchar       *status_msg;
 
     /* expert info indicator */
     status_expert_update();
@@ -602,14 +623,12 @@ statusbar_set_filename(const char *file_name, gint64 file_length, nstime_t *file
         size_str = g_strdup_printf("%" G_GINT64_MODIFIER "d Bytes", file_length);
     }
 
-    status_msg = g_strdup_printf(" File: \"%s\" %s %02lu:%02lu:%02lu",
-                                 (file_name) ? file_name : "", size_str,
-                                 (long)file_elapsed_time->secs/3600,
-                                 (long)file_elapsed_time->secs%3600/60,
-                                 (long)file_elapsed_time->secs%60);
+    statusbar_push_file_msg(" File: \"%s\" %s %02lu:%02lu:%02lu",
+                            (file_name) ? file_name : "", size_str,
+                            (long)file_elapsed_time->secs/3600,
+                            (long)file_elapsed_time->secs%3600/60,
+                            (long)file_elapsed_time->secs%60);
     g_free(size_str);
-    statusbar_push_file_msg(status_msg);
-    g_free(status_msg);
 }
 
 
@@ -639,16 +658,13 @@ static void
 statusbar_cf_file_read_started_cb(capture_file *cf)
 {
     const gchar *name_ptr;
-    gchar       *load_msg;
 
     /* Ensure we pop any previous loaded filename */
     statusbar_pop_file_msg();
 
     name_ptr = get_basename(cf->filename);
 
-    load_msg = g_strdup_printf(" Loading: %s", name_ptr);
-    statusbar_push_file_msg(load_msg);
-    g_free(load_msg);
+    statusbar_push_file_msg(" Loading: %s", name_ptr);
 }
 
 
@@ -664,7 +680,7 @@ statusbar_cf_file_read_finished_cb(capture_file *cf)
 static void
 statusbar_capture_prepared_cb(capture_options *capture_opts _U_)
 {
-    gchar *msg = " Waiting for capture input data ...";
+    static const gchar msg[] = " Waiting for capture input data ...";
     statusbar_push_file_msg(msg);
     welcome_header_push_msg(msg);
 }
@@ -672,55 +688,44 @@ statusbar_capture_prepared_cb(capture_options *capture_opts _U_)
 static void
 statusbar_capture_update_started_cb(capture_options *capture_opts)
 {
-    gchar *capture_msg;
-
-
     statusbar_pop_file_msg();
     welcome_header_pop_msg();
 
     if(capture_opts->iface) {
-        capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
-                                      get_iface_description(capture_opts),
-                                      (capture_opts->save_file) ? capture_opts->save_file : "");
+        statusbar_push_file_msg(" %s: <live capture in progress> to file: %s",
+                                get_iface_description(capture_opts),
+                                (capture_opts->save_file) ? capture_opts->save_file : "");
     } else {
-        capture_msg = g_strdup_printf(" <live capture in progress> to file: %s",
-            (capture_opts->save_file) ? capture_opts->save_file : "");
+        statusbar_push_file_msg(" <live capture in progress> to file: %s",
+                                (capture_opts->save_file) ? capture_opts->save_file : "");
     }
-
-    statusbar_push_file_msg(capture_msg);
-
-    g_free(capture_msg);
 }
 
 static void
 statusbar_capture_update_continue_cb(capture_options *capture_opts)
 {
     capture_file *cf = capture_opts->cf;
-    gchar *capture_msg;
-
 
     status_expert_update();
 
     statusbar_pop_file_msg();
 
     if (cf->f_datalen/1024/1024 > 10) {
-        capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d MB",
-                                      get_iface_description(capture_opts),
-                                      capture_opts->save_file,
-                                      cf->f_datalen/1024/1024);
+        statusbar_push_file_msg(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d MB",
+                                get_iface_description(capture_opts),
+                                capture_opts->save_file,
+                                cf->f_datalen/1024/1024);
     } else if (cf->f_datalen/1024 > 10) {
-        capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d KB",
-                                      get_iface_description(capture_opts),
-                                      capture_opts->save_file,
-                                      cf->f_datalen/1024);
+        statusbar_push_file_msg(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d KB",
+                                get_iface_description(capture_opts),
+                                capture_opts->save_file,
+                                cf->f_datalen/1024);
     } else {
-        capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d Bytes",
-                                      get_iface_description(capture_opts),
-                                      capture_opts->save_file,
-                                      cf->f_datalen);
+        statusbar_push_file_msg(" %s: <live capture in progress> File: %s %" G_GINT64_MODIFIER "d Bytes",
+                                get_iface_description(capture_opts),
+                                capture_opts->save_file,
+                                cf->f_datalen);
     }
-
-    statusbar_push_file_msg(capture_msg);
 }
 
 static void
@@ -737,19 +742,13 @@ statusbar_capture_update_finished_cb(capture_options *capture_opts)
 static void
 statusbar_capture_fixed_started_cb(capture_options *capture_opts)
 {
-    gchar *capture_msg;
-
-
     statusbar_pop_file_msg();
 
-    capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
-                                  get_iface_description(capture_opts),
-                                  (capture_opts->save_file) ? capture_opts->save_file : "");
+    statusbar_push_file_msg(" %s: <live capture in progress> to file: %s",
+                            get_iface_description(capture_opts),
+                            (capture_opts->save_file) ? capture_opts->save_file : "");
 
-    statusbar_push_file_msg(capture_msg);
     gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, " Packets: 0");
-
-    g_free(capture_msg);
 }
 
 static void
@@ -793,12 +792,8 @@ statusbar_cf_field_unselected_cb(capture_file *cf _U_)
 static void
 statusbar_cf_file_save_started_cb(gchar *filename)
 {
-    gchar        *save_msg;
-
     statusbar_pop_file_msg();
-    save_msg = g_strdup_printf(" Saving: %s...", get_basename(filename));
-    statusbar_push_file_msg(save_msg);
-    g_free(save_msg);
+    statusbar_push_file_msg(" Saving: %s...", get_basename(filename));
 }
 
 static void
index ba19fafe365751a9465b00892cf5f6265a9b4160..96425c4faeb6f336365ab43dad4856d39678d187 100644 (file)
@@ -341,7 +341,7 @@ welcome_header_new(void)
 
 
 void
-welcome_header_push_msg(gchar *msg) {
+welcome_header_push_msg(const gchar *msg) {
     gchar *msg_copy = g_strdup(msg);
 
     status_messages = g_slist_append(status_messages, msg_copy);
index c17a2725ce1bb772782a4cbc3511f69bcdd4f72f..19299e27d995a7117f160c92b6f45b7022c92efa 100644 (file)
@@ -44,7 +44,7 @@ void welcome_if_panel_reload(void);
  *
  * @param msg The message
  */
-void welcome_header_push_msg(gchar *msg);
+void welcome_header_push_msg(const gchar *msg);
 
 /** Pop a status message from the welcome screen. If there are no
  *  messages on the stack, the default message and the main columns
index 6bf4d7ba7e924bfd69f05ac7daa8939b0069c8ef..92ecd27c44d153d04087a295b579674dcfb6363b 100644 (file)
@@ -29,21 +29,23 @@ void profile_bar_update(void);
 void packets_bar_update(void);
 void status_expert_update(void);
 
-/** Push a message referring to the currently-selected field onto the statusbar.
+/** Push a formatted message referring to the currently-selected field
+ * onto the statusbar.
  *
- * @param msg The message
+ * @param msg_format The format string for the message
  */
-void statusbar_push_field_msg(const gchar *msg);
+void statusbar_push_field_msg(const gchar *msg_format, ...);
 
 /** Pop a message referring to the currently-selected field off the statusbar.
  */
 void statusbar_pop_field_msg(void);
 
-/** Push a message referring to the current filter onto the statusbar.
+/** Push a formatted message referring to the current filter onto the
+ * statusbar.
  *
- * @param msg The message
+ * @param msg_format The format string for the message
  */
-void statusbar_push_filter_msg(const gchar *msg);
+void statusbar_push_filter_msg(const gchar *msg_format, ...);
 
 /** Pop a message referring to the current filter off the statusbar.
  */