From: John Darrington Date: Mon, 23 Feb 2009 03:09:13 +0000 (+0900) Subject: Refactor code from psppire.c X-Git-Tag: v0.7.3~292 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a02381223dd6d652c590e2a5514967b9448905;p=pspp-builds.git Refactor code from psppire.c Instead of using custom code for loading files given on the command line, instead use code from psppire-data-window.c --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 40e41dcc..e2fa7969 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -319,8 +319,9 @@ add_most_recent (const char *file_name) #endif } -static void -open_data_file (const gchar *file_name, PsppireDataWindow *de) +void +psppire_data_window_load_file (PsppireDataWindow *de, + const gchar *file_name) { struct getl_interface *sss; struct string filename; @@ -389,7 +390,7 @@ open_data_dialog (GtkAction *action, PsppireDataWindow *de) de->file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - open_data_file (de->file_name, de); + psppire_data_window_load_file (de, de->file_name); } break; default: @@ -920,7 +921,7 @@ on_recent_data_select (GtkMenuShell *menushell, gpointer user_data) g_free (uri); - open_data_file (file, de); + psppire_data_window_load_file (de, file); g_free (file); } diff --git a/src/ui/gui/psppire-data-window.h b/src/ui/gui/psppire-data-window.h index 77687dc9..68b77817 100644 --- a/src/ui/gui/psppire-data-window.h +++ b/src/ui/gui/psppire-data-window.h @@ -113,6 +113,7 @@ struct _PsppireDataWindowClass GType psppire_data_window_get_type (void); GtkWidget* psppire_data_window_new (void); +void psppire_data_window_load_file (PsppireDataWindow *, const gchar *); G_END_DECLS diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index b87a29f2..737b965c 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -257,46 +257,8 @@ parse_non_options (int key, char *arg, struct argp_state *state) { case ARGP_KEY_ARG: { - struct string syntax; - FILE *fp = fopen (arg, "r"); - if (NULL == fp) - { - const int errnum = errno; - fprintf (state->err_stream, _("Cannot open %s: %s.\n"), - arg, strerror (errnum)); - return 0; - } - if ( sfm_detect (fp)) - { - ds_init_cstr (&syntax, "GET FILE="); - goto close; - } - rewind (fp); - if (pfm_detect (fp)) - { - ds_init_cstr (&syntax, "IMPORT FILE="); - goto close; - } - - fclose (fp); - msg (ME, _("%s is neither a system nor portable file"), arg); - break; - - close: - fclose (fp); - - syntax_gen_string (&syntax, ss_cstr (arg)); - ds_put_cstr (&syntax, "."); - - getl_append_source (ss, - create_syntax_string_source (ds_cstr (&syntax)), - GETL_BATCH, - ERRMODE_CONTINUE); - - ds_destroy (&syntax); - - psppire_window_set_filename (PSPPIRE_WINDOW (the_data_window), arg); - + psppire_data_window_load_file (PSPPIRE_DATA_WINDOW (the_data_window), + arg); break; } default: