summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorJaap Keuter <jaap.keuter@xs4all.nl>2006-01-20 19:56:02 +0000
committerJaap Keuter <jaap.keuter@xs4all.nl>2006-01-20 19:56:02 +0000
commit613d04a1ce869e9811eb13f4cf5a1a5b0bb5c632 (patch)
tree0266ec8cae5598e91c900a6b743fd67bc904ffe8 /gtk
parentf194c9eddb26bef896410c01a4b6b9881c6d3833 (diff)
downloadwireshark-613d04a1ce869e9811eb13f4cf5a1a5b0bb5c632.tar.gz
Cleaning up copy to CSV code
svn path=/trunk/; revision=17064
Diffstat (limited to 'gtk')
-rw-r--r--gtk/conversations_table.c26
-rw-r--r--gtk/expert_comp_table.c32
2 files changed, 28 insertions, 30 deletions
diff --git a/gtk/conversations_table.c b/gtk/conversations_table.c
index 07bb9a72a8..cd9afa7899 100644
--- a/gtk/conversations_table.c
+++ b/gtk/conversations_table.c
@@ -1145,36 +1145,36 @@ copy_as_csv_cb(GtkWindow *win _U_, gpointer data)
{
guint32 i,j;
gchar *table_entry;
- gchar *CSV_str;
GtkClipboard *cb;
+ GString *CSV_str = g_string_new("");
conversations_table *talkers=(conversations_table *)data;
- CSV_str=g_new(gchar,(80*(talkers->num_conversations+1))); /* 80 chars * num rows */
- strcpy(CSV_str,""); /* initialize string */
/* Add the column headers to the CSV data */
for(i=0;i<talkers->num_columns;i++){ /* all columns */
if((i==1 || i==3) && !talkers->has_ports) continue; /* Don't add the port column if it's empty */
- strcat(CSV_str,talkers->default_titles[i]); /* add the column heading to the CSV string */
- strcat(CSV_str,",");
+ g_string_append(CSV_str,talkers->default_titles[i]);/* add the column heading to the CSV string */
+ if(i!=talkers->num_columns-1)
+ g_string_append(CSV_str,",");
}
- strcat(CSV_str,"\n"); /* new row */
+ g_string_append(CSV_str,"\n"); /* new row */
/* Add the column values to the CSV data */
- for(i=0;i<talkers->num_conversations;i++){ /* all rows */
+ for(i=0;i<talkers->num_conversations;i++){ /* all rows */
for(j=0;j<talkers->num_columns;j++){ /* all columns */
if((j==1 || j==3) && !talkers->has_ports) continue; /* Don't add the port column if it's empty */
gtk_clist_get_text(talkers->table,i,j,&table_entry);/* copy table item into string */
- strcat(CSV_str,table_entry); /* add the table entry to the CSV string */
- strcat(CSV_str,",");
+ g_string_append(CSV_str,table_entry); /* add the table entry to the CSV string */
+ if(j!=talkers->num_columns-1)
+ g_string_append(CSV_str,",");
}
- strcat(CSV_str,"\n"); /* new row */
+ g_string_append(CSV_str,"\n"); /* new row */
}
/* Now that we have the CSV data, copy it into the default clipboard */
- cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
- gtk_clipboard_set_text(cb, CSV_str, -1); /* Copy the CSV data into the clipboard */
- g_free(CSV_str); /* Free the memory */
+ cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
+ gtk_clipboard_set_text(cb, CSV_str->str, -1); /* Copy the CSV data into the clipboard */
+ g_string_free(CSV_str, TRUE); /* Free the memory */
}
#endif
diff --git a/gtk/expert_comp_table.c b/gtk/expert_comp_table.c
index ae65243df3..b4b9df8fce 100644
--- a/gtk/expert_comp_table.c
+++ b/gtk/expert_comp_table.c
@@ -141,38 +141,36 @@ error_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
}
-/* used from gtk/conversations_table.c */
#if (GTK_MAJOR_VERSION >= 2)
static void
-copy_as_csv_cb(GtkWindow *win _U_, gpointer table_data)
+copy_as_csv_cb(GtkWindow *win _U_, gpointer data)
{
guint32 i,j;
gchar *table_entry;
- gchar *CSV_str;
GtkClipboard *cb;
+ GString *CSV_str = g_string_new("");
- error_equiv_table *expert=(error_equiv_table *)table_data;
+ error_equiv_table *expert=(error_equiv_table *)data;
- CSV_str=g_new(gchar,(120*(expert->num_procs+1))); /* 120 chars * num rows */
- strcpy(CSV_str,""); /* initialize string */
/* Add the column headers to the CSV data */
- strcat(CSV_str,"Summary, Group, Protocol, Count,"); /* add the column headings to the CSV string */
- strcat(CSV_str,"\n"); /* new row */
+ g_string_append(CSV_str,"Summary,Group,Protocol,Count"); /* add the column headings to the CSV string */
+ g_string_append(CSV_str,"\n"); /* new row */
/* Add the column values to the CSV data */
- for(i=0;i<expert->num_procs;i++){ /* all rows */
- for(j=0;j<4;j++){ /* all columns */
- gtk_clist_get_text(expert->table,i,j,&table_entry);/* copy table item into string */
- strcat(CSV_str,table_entry); /* add the table entry to the CSV string */
- strcat(CSV_str,",");
+ for(i=0;i<expert->num_procs;i++){ /* all rows */
+ for(j=0;j<4;j++){ /* all columns */
+ gtk_clist_get_text(expert->table,i,j,&table_entry); /* copy table item into string */
+ g_string_append(CSV_str,table_entry); /* add the table entry to the CSV string */
+ if(j!=(4-1))
+ g_string_append(CSV_str,",");
}
- strcat(CSV_str,"\n"); /* new row */
+ g_string_append(CSV_str,"\n"); /* new row */
}
/* Now that we have the CSV data, copy it into the default clipboard */
- cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
- gtk_clipboard_set_text(cb, CSV_str, -1); /* Copy the CSV data into the clipboard */
- g_free(CSV_str); /* Free the memory */
+ cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
+ gtk_clipboard_set_text(cb, CSV_str->str, -1); /* Copy the CSV data into the clipboard */
+ g_string_free(CSV_str, TRUE); /* Free the memory */
}
#endif