From 68119c5b5415c2797e11356dc8db63bd84c577cf Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Tue, 2 Apr 2013 18:46:41 +0300 Subject: [PATCH] Move set_filename() calls outside of parse_file() Remove the boolean parameter from parse_file; the code is more readable by having an explicit call to set_filename() where necessary, rather than a boolean parameter. Signed-off-by: Henrik Brautaset Aronsen Signed-off-by: Alberto Mardegan --- dive.h | 2 +- file.c | 12 +----------- gtk-gui.c | 5 +++-- main.c | 10 +++++++--- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/dive.h b/dive.h index 7d08828a8..5daafb38c 100644 --- a/dive.h +++ b/dive.h @@ -551,7 +551,7 @@ extern void set_filename(const char *filename, gboolean force); extern int parse_dm4_buffer(const char *url, const char *buf, int size, struct dive_table *table, GError **error); -extern void parse_file(const char *filename, GError **error, gboolean possible_default_filename); +extern void parse_file(const char *filename, GError **error); extern void show_dive_info(struct dive *); diff --git a/file.c b/file.c index 8deb2fe97..401bd5c36 100644 --- a/file.c +++ b/file.c @@ -263,7 +263,7 @@ static void parse_file_buffer(const char *filename, struct memblock *mem, GError parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, error); } -void parse_file(const char *filename, GError **error, gboolean possible_default_filename) +void parse_file(const char *filename, GError **error) { struct memblock mem; #ifdef SQLITE3 @@ -283,19 +283,9 @@ void parse_file(const char *filename, GError **error, gboolean possible_default_ filename); } - /* - * We do *not* want to leave the old default_filename - * just because the open failed. - */ - if (possible_default_filename) - set_filename(filename, TRUE); - return; } - if (possible_default_filename) - set_filename(filename, TRUE); - #ifdef SQLITE3 fmt = strrchr(filename, '.'); if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK"))) { diff --git a/gtk-gui.c b/gtk-gui.c index 91a70acf0..becf0fdac 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -321,7 +321,8 @@ static void file_open(GtkWidget *w, gpointer data) GError *error = NULL; filename = fn_glist->data; - parse_file(filename, &error, TRUE); + parse_file(filename, &error); + set_filename(filename, TRUE); if (error != NULL) { report_error(error); @@ -2204,7 +2205,7 @@ static GtkWidget *dive_profile_widget(void) static void do_import_file(gpointer data, gpointer user_data) { GError *error = NULL; - parse_file(data, &error, FALSE); + parse_file((const char *)data, &error); if (error != NULL) { diff --git a/main.c b/main.c index 3b6e00449..3c0ea7381 100644 --- a/main.c +++ b/main.c @@ -348,8 +348,12 @@ int main(int argc, char **argv) /* if we have exactly one filename, parse_file will set * that to be the default. Otherwise there will be no default filename */ set_filename(NULL, TRUE); - parse_file(a, &error, no_filenames); - no_filenames = FALSE; + parse_file(a, &error); + if (no_filenames) + { + set_filename(a, TRUE); + no_filenames = FALSE; + } if (error != NULL) { report_error(error); @@ -360,7 +364,7 @@ int main(int argc, char **argv) if (no_filenames) { GError *error = NULL; const char *filename = prefs.default_filename; - parse_file(filename, &error, TRUE); + parse_file(filename, &error); /* don't report errors - this file may not exist, but make sure we remember this as the filename in use */ set_filename(filename, FALSE);