struct import_assistant *
init_assistant (GtkWindow *parent_window)
{
- struct import_assistant *ia = NULL;
- ia = xzalloc (sizeof *ia);
+ struct import_assistant *ia = xzalloc (sizeof *ia);
struct assistant *a = &ia->asst;
a->builder = builder_new ("text-data-import.ui");
a->assistant = GTK_ASSISTANT (gtk_assistant_new ());
+ ia->sheet_spec = sheet_spec_page_create (ia);
ia->intro = intro_page_create (ia);
- ia->sheet_spec = xzalloc (sizeof *ia->sheet_spec);
+
ia->first_line = xzalloc (sizeof *ia->first_line);
ia->separators = xzalloc (sizeof *ia->separators);
ia->formats = xzalloc (sizeof *ia->formats);
/* Choose a file */
static char *choose_file (GtkWindow *parent_window, gchar **encodingp);
-enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
-/*
- Update IA according to the contents of DICT and CREADER.
- CREADER will be destroyed by this function.
-*/
-void
-update_assistant (struct import_assistant *ia)
-{
- struct sheet_spec_page *ssp = ia->sheet_spec;
-
- struct file *file = &ia->file;
- struct separators_page *sepp = ia->separators;
- int rows = 0;
- if (ssp->dict)
- {
- struct ccase *c;
- int col;
-
-
- sepp->column_cnt = dict_get_var_cnt (ssp->dict);
- sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
- for (col = 0; col < sepp->column_cnt ; ++col)
- {
- const struct variable *var = dict_get_var (ssp->dict, col);
- sepp->columns[col].name = xstrdup (var_get_name (var));
- sepp->columns[col].contents = NULL;
- }
-
- for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
- {
- rows++;
- for (col = 0; col < sepp->column_cnt ; ++col)
- {
- char *ss;
- const struct variable *var = dict_get_var (ssp->dict, col);
-
- sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
- sizeof (struct substring) * rows);
-
- ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict),
- var_get_print_format (var));
-
- sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
- }
-
- if (rows > MAX_PREVIEW_LINES)
- {
- case_unref (c);
- break;
- }
- }
- }
-
- file->line_cnt = rows;
-}
/* Obtains the file to import from the user and initializes IA's
struct sheet_spec_page *ssp = ia->sheet_spec;
struct spreadsheet_read_info sri;
struct spreadsheet_read_options opts;
+ struct spreadsheet *spreadsheet = NULL;
file->lines = NULL;
file->file_name = choose_file (parent_window, &file->encoding);
sri.read_names = true;
sri.asw = -1;
- if (ssp->spreadsheet == NULL)
- ssp->spreadsheet = gnumeric_probe (file->file_name);
+ if (spreadsheet == NULL)
+ spreadsheet = gnumeric_probe (file->file_name);
- if (ssp->spreadsheet == NULL)
- ssp->spreadsheet = ods_probe (file->file_name);
+ if (spreadsheet == NULL)
+ spreadsheet = ods_probe (file->file_name);
- if (ssp->spreadsheet)
+ if (spreadsheet)
{
// update_assistant (ia);
}
struct import_assistant;
-\f
/* The "sheet-spec" page of the assistant. */
+/* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */
+struct sheet_spec_page
+ {
+ GtkWidget *page;
+ struct casereader *reader;
+ struct dictionary *dict;
+ struct spreadsheet *spreadsheet;
+
+ struct spreadsheet_read_info sri;
+ struct spreadsheet_read_options opts;
+ };
+
+
+
+
/* Initializes IA's sheet_spec substructure. */
-void
-init_sheet_spec_page (struct import_assistant *ia)
+struct sheet_spec_page *
+sheet_spec_page_create (struct import_assistant *ia)
{
GtkBuilder *builder = ia->asst.builder;
- struct sheet_spec_page *p = ia->sheet_spec;
+ struct sheet_spec_page *p = xzalloc (sizeof (*p));
p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"),
GTK_ASSISTANT_PAGE_INTRO);
+ return p;
}
/* Prepares IA's sheet_spec page. */
}
}
+
+/*
+ Update IA according to the contents of DICT and CREADER.
+ CREADER will be destroyed by this function.
+*/
+void
+update_assistant (struct import_assistant *ia)
+{
+ struct sheet_spec_page *ssp = ia->sheet_spec;
+ // struct file *file = &ia->file;
+ struct separators_page *sepp = ia->separators;
+ int rows = 0;
+
+
+ if (ssp->dict)
+ {
+ struct ccase *c;
+ int col;
+
+ sepp->column_cnt = dict_get_var_cnt (ssp->dict);
+ sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns));
+ for (col = 0; col < sepp->column_cnt ; ++col)
+ {
+ const struct variable *var = dict_get_var (ssp->dict, col);
+ sepp->columns[col].name = xstrdup (var_get_name (var));
+ sepp->columns[col].contents = NULL;
+ }
+
+ for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c))
+ {
+ rows++;
+ for (col = 0; col < sepp->column_cnt ; ++col)
+ {
+ char *ss;
+ const struct variable *var = dict_get_var (ssp->dict, col);
+
+ sepp->columns[col].contents = xrealloc (sepp->columns[col].contents,
+ sizeof (struct substring) * rows);
+
+ ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict),
+ var_get_print_format (var));
+
+ sepp->columns[col].contents[rows - 1] = ss_cstr (ss);
+ }
+
+ if (rows > MAX_PREVIEW_LINES)
+ {
+ case_unref (c);
+ break;
+ }
+ }
+ }
+
+ // file->line_cnt = rows;
+}
}
ssp = ia->sheet_spec;
- if (ssp->spreadsheet == NULL)
- {
- init_first_line_page (ia);
- init_separators_page (ia);
- }
- else
- {
- init_sheet_spec_page (ia);
- }
+ init_first_line_page (ia);
+ init_separators_page (ia);
init_formats_page (ia);
break;
}
- if (ssp->spreadsheet == NULL)
- {
- destroy_formats_page (ia);
- destroy_separators_page (ia);
- }
+ destroy_formats_page (ia);
+ destroy_separators_page (ia);
destroy_assistant (ia);
destroy_file (ia);
struct string s = DS_EMPTY_INITIALIZER;
+#if 0
if (ssp->spreadsheet == NULL)
{
size_t var_cnt;
apply_dict (ia->formats->dict, &s);
}
else
+
{
const struct sheet_spec_page *ssp = ia->sheet_spec;
- printf ("%s:%d %p %d\n", __FILE__, __LINE__, ssp->spreadsheet, ssp->spreadsheet->type);
-
syntax_gen_pspp (&s,
"GET DATA"
"\n /TYPE=%ss"
syntax_gen_pspp (&s, ".");
}
+#endif
return ds_cstr (&s);
}
#include "libpspp/str.h"
+enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
+
/* The file to be imported. */
struct file
{
};
-/* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */
-struct sheet_spec_page
- {
- GtkWidget *page;
- struct casereader *reader;
- struct dictionary *dict;
- struct spreadsheet *spreadsheet;
-
- struct spreadsheet_read_info sri;
- struct spreadsheet_read_options opts;
- };
-
/* Page where the user chooses the first line of data. */
struct first_line_page