"gtk_entry_get_text()" returns a "const char *" - assign the result to

one.

"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *". 

"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.

In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).

Clean up white space.

svn path=/trunk/; revision=12881
This commit is contained in:
Guy Harris 2004-12-31 00:26:36 +00:00
parent 6d24b27606
commit 6e622fd24e
14 changed files with 79 additions and 84 deletions

View File

@ -60,8 +60,8 @@
* character in the pathname, or NULL if the pathname contains no
* separators.
*/
char *
find_last_pathname_separator(char *path)
static char *
find_last_pathname_separator(const char *path)
{
char *separator;
@ -72,7 +72,7 @@ find_last_pathname_separator(char *path)
* We have to scan for '\' or '/'.
* Get to the end of the string.
*/
separator = path + strlen(path); /* points to ending '\0' */
separator = strchr(path, '\0'); /* points to ending '\0' */
while (separator > path) {
c = *--separator;
if (c == '\\' || c == '/')
@ -93,10 +93,10 @@ find_last_pathname_separator(char *path)
/*
* Given a pathname, return the last component.
*/
char *
get_basename(char *path)
const char *
get_basename(const char *path)
{
char *filename;
const char *filename;
g_assert(path != NULL);
filename = find_last_pathname_separator(path);

View File

@ -25,17 +25,10 @@
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
/*
* Given a pathname, return a pointer to the last pathname separator
* character in the pathname, or NULL if the pathname contains no
* separators.
*/
char *find_last_pathname_separator(char *);
/*
* Given a pathname, return the last component.
*/
char *get_basename(char *);
const char *get_basename(const char *);
/*
* Given a pathname, return a string containing everything but the

54
file.c
View File

@ -301,14 +301,14 @@ cf_close(capture_file *cf)
static void
set_display_filename(capture_file *cf)
{
gchar *name_ptr;
size_t msg_len;
const gchar *name_ptr;
size_t msg_len;
static const gchar done_fmt_nodrops[] = " File: %s %s %02u:%02u:%02u";
static const gchar done_fmt_drops[] = " File: %s %s %02u:%02u:%02u Drops: %u";
gchar *done_msg;
gchar *win_name_fmt = "%s - Ethereal";
gchar *win_name;
gchar *size_str;
gchar *done_msg;
gchar *win_name_fmt = "%s - Ethereal";
gchar *win_name;
gchar *size_str;
name_ptr = cf_get_display_name(cf);
@ -345,28 +345,29 @@ set_display_filename(capture_file *cf)
read_status_t
cf_read(capture_file *cf)
{
int err;
gchar *err_info;
gchar *name_ptr, *load_msg, *load_fmt = "%s";
char *errmsg;
char errmsg_errno[1024+1];
gchar err_str[2048+1];
long data_offset;
progdlg_t *progbar = NULL;
gboolean stop_flag;
int err;
gchar *err_info;
const gchar *name_ptr;
gchar *load_msg, *load_fmt = "%s";
char *errmsg;
char errmsg_errno[1024+1];
gchar err_str[2048+1];
long data_offset;
progdlg_t *progbar = NULL;
gboolean stop_flag;
/*
* XXX - should be "off_t", but Wiretap would need more work to handle
* the full size of "off_t" on platforms where it's more than a "long"
* as well.
*/
long file_pos;
float prog_val;
int fd;
struct stat cf_stat;
GTimeVal start_time;
gchar status_str[100];
int progbar_nextstep;
int progbar_quantum;
long file_pos;
float prog_val;
int fd;
struct stat cf_stat;
GTimeVal start_time;
gchar status_str[100];
int progbar_nextstep;
int progbar_quantum;
cum_bytes=0;
reset_tap_listeners();
@ -682,10 +683,10 @@ cf_finish_tail(capture_file *cf, int *err)
}
#endif /* HAVE_LIBPCAP */
gchar *
const gchar *
cf_get_display_name(capture_file *cf)
{
gchar *displayname;
const gchar *displayname;
/* Return a name to use in displays */
if (!cf->is_tempfile) {
@ -3042,7 +3043,8 @@ gboolean
cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format)
{
gchar *from_filename;
gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
const gchar *name_ptr;
gchar *save_msg, *save_fmt = " Saving: %s...";
size_t msg_len;
int err;
gboolean do_copy;

2
file.h
View File

@ -51,7 +51,7 @@ read_status_t cf_continue_tail(capture_file *, int, int *);
read_status_t cf_finish_tail(capture_file *, int *);
/* size_t read_frame_header(capture_file *); */
gboolean cf_save(char *fname, capture_file * cf, packet_range_t *range, guint save_format);
gchar *cf_get_display_name(capture_file *);
const gchar *cf_get_display_name(capture_file *);
gboolean
cf_merge_files(const char *out_filename, int out_fd, int in_file_count,

View File

@ -204,11 +204,11 @@ static GtkWidget *
about_folders_page_new(void)
{
GtkWidget *table;
const char *path;
const char *constpath;
char *path;
gchar *titles[] = { "Name", "Folder", "Typical Files"};
GtkWidget *scrolledwindow;
scrolledwindow = scrolled_window_new(NULL, NULL);
#if GTK_MAJOR_VERSION >= 2
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
@ -235,20 +235,18 @@ about_folders_page_new(void)
g_free((void *) path);
/* global conf */
path = get_datafile_dir();
about_folders_row(table, "Global configuration", path,
constpath = get_datafile_dir();
about_folders_row(table, "Global configuration", constpath,
"\"dfilters\", \"preferences\", \"manuf\", ...");
/*g_free(path);*/
/* system */
path = get_systemfile_dir();
about_folders_row(table, "System", path,
constpath = get_systemfile_dir();
about_folders_row(table, "System", constpath,
"\"ethers\", \"ipxnets\"");
/*g_free(path);*/
/* program */
path = g_strdup(ethereal_path);
path = get_dirname((char *) path);
path = get_dirname(path);
about_folders_row(table, "Program", path,
"program files");
g_free((void *) path);

View File

@ -352,7 +352,7 @@ static void
dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
char *filter;
const char *filter;
str = g_string_new("dcerpc,srt");
g_string_sprintfa(str,
@ -364,7 +364,7 @@ dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
dcerpc_uuid_program->Data4[4], dcerpc_uuid_program->Data4[5],
dcerpc_uuid_program->Data4[6], dcerpc_uuid_program->Data4[7],
dcerpc_version, 0);
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str, ",%s", filter);
}

View File

@ -214,10 +214,10 @@ static void
fcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
char *filter;
const char *filter;
str = g_string_new("fc,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter);
}

View File

@ -161,7 +161,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
}
label = OBJECT_GET_DATA(prev, PREVIEW_FILENAME_KEY);
gtk_label_set_text(GTK_LABEL(label), get_basename((char *)cf_name));
gtk_label_set_text(GTK_LABEL(label), get_basename(cf_name));
if (test_for_directory(cf_name) == EISDIR) {
label = OBJECT_GET_DATA(prev, PREVIEW_FORMAT_KEY);
@ -645,10 +645,11 @@ file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
/* user pressed "open" button */
static void
file_open_ok_cb(GtkWidget *w, gpointer fs) {
gchar *cf_name, *rfilter, *s;
GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
dfilter_t *rfcode = NULL;
int err;
gchar *cf_name, *s;
const gchar *rfilter;
GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
dfilter_t *rfcode = NULL;
int err;
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@ -656,7 +657,7 @@ file_open_ok_cb(GtkWidget *w, gpointer fs) {
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
#endif
filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (!dfilter_compile(rfilter, &rfcode)) {
bad_dfilter_alert_box(rfilter);
g_free(cf_name);
@ -992,14 +993,15 @@ file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) {
static void
file_merge_ok_cb(GtkWidget *w, gpointer fs) {
gchar *cf_name, *rfilter, *s;
GtkWidget *filter_te, *rb;
dfilter_t *rfcode = NULL;
int err;
gboolean merge_ok;
char *in_filenames[2];
int out_fd;
char tmpname[128+1];
gchar *cf_name, *s;
const gchar *rfilter;
GtkWidget *filter_te, *rb;
dfilter_t *rfcode = NULL;
int err;
gboolean merge_ok;
char *in_filenames[2];
int out_fd;
char tmpname[128+1];
#if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@ -1007,7 +1009,7 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
#endif
filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
if (!dfilter_compile(rfilter, &rfcode)) {
bad_dfilter_alert_box(rfilter);
g_free(cf_name);

View File

@ -979,7 +979,7 @@ gtk_iostat_draw(void *g)
pruned
*/
static GString *
enable_graph(io_stat_graph_t *gio, char *filter, char *field)
enable_graph(io_stat_graph_t *gio, const char *filter, const char *field)
{
char real_filter[260];
@ -1505,12 +1505,12 @@ create_ctrl_area(io_stat_t *io, GtkWidget *box)
static gint
filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
{
char *filter;
char *field;
const char *filter;
const char *field;
header_field_info *hfi;
dfilter_t *dfilter;
field=(char *)gtk_entry_get_text(GTK_ENTRY(gio->calc_field));
field=gtk_entry_get_text(GTK_ENTRY(gio->calc_field));
/* this graph is not active, just update display and redraw */
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gio->display_button))){
@ -1612,7 +1612,7 @@ filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
}
/* first check if the filter string is valid. */
filter=(char *)gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
filter=gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
if(!dfilter_compile(filter, &dfilter)) {
bad_dfilter_alert_box(filter);
disable_graph(gio);

View File

@ -249,10 +249,10 @@ static void
ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
char *filter;
const char *filter;
str = g_string_new("ldap,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter);
}

View File

@ -1525,7 +1525,7 @@ int
main(int argc, char *argv[])
{
#ifdef HAVE_LIBPCAP
char *command_name;
const char *command_name;
#endif
char *s;
int i;

View File

@ -316,11 +316,11 @@ static void
rpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
char *filter;
const char *filter;
str = g_string_new("rpc,srt");
g_string_sprintfa(str, ",%d,%d", rpc_program, rpc_version);
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str, ",%s", filter);
}

View File

@ -252,10 +252,10 @@ static void
smbstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
{
GString *str;
char *filter;
const char *filter;
str = g_string_new("smb,srt");
filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
if(filter[0]!=0){
g_string_sprintfa(str,",%s", filter);
}

View File

@ -85,16 +85,16 @@ dlg_destroy_cb(GtkWidget *item _U_, gpointer dialog_data)
static void
tap_dfilter_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data)
{
char *filter;
const char *filter;
char str[256];
tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data;
filter=(char *)gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
filter=gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
if(filter[0]==0){
g_snprintf(str, sizeof(str), "%s", dlg_data->cont.init_string);
} else {
g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);
g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);
}
(dlg_data->cont.tap_init_cb)(str);
}