/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009, 2010, 2011, 2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
}
+#define RADIX 26
+
+static void
+reverse (char *s, int len)
+{
+ int i;
+ for (i = 0; i < len / 2; ++i)
+ {
+ char tmp = s[len - i - 1];
+ s[len - i -1] = s[i];
+ s[i] = tmp;
+ }
+}
/* Convert a string, which is an integer encoded in base26
ABC = 2 + 2*26 + 1*26^2 ....
*/
int
-pseudo_base26 (const char *str)
+ps26_to_int (const char *str)
{
int i;
int multiplier = 1;
int result = 0;
int len = strlen (str);
- for ( i = len - 1 ; i >= 0; --i)
+ for (i = len - 1 ; i >= 0; --i)
{
int mantissa = (str[i] - 'A');
- if ( mantissa < 0 || mantissa > 25 )
- return -1;
+ assert (mantissa >= 0);
+ assert (mantissa < RADIX);
- if ( i != len - 1)
+ if (i != len - 1)
mantissa++;
result += mantissa * multiplier;
-
- multiplier *= 26;
+ multiplier *= RADIX;
}
return result;
}
+char *
+int_to_ps26 (int i)
+{
+ char *ret = NULL;
+
+ int lower = 0;
+ long long int base = RADIX;
+ int exp = 1;
+
+ assert (i >= 0);
+
+ while (i > lower + base - 1)
+ {
+ lower += base;
+ base *= RADIX;
+ assert (base > 0);
+ exp++;
+ }
+
+ i -= lower;
+ i += base;
+
+ ret = malloc (exp);
+
+ exp = 0;
+ do
+ {
+ ret[exp++] = (i % RADIX) + 'A';
+ i /= RADIX;
+ }
+ while (i > 1);
+
+ ret[exp]='\0';
+
+ reverse (ret, exp);
+ return ret;
+}
+
char *
create_cell_ref (int col0, int row0, int coli, int rowi)
{
- return c_xasprintf ("%c%d:%c%ld",
- col0 + 'A', row0 + 1,
- coli + 'A', rowi + 1);
+ char *cs0 = int_to_ps26 (col0);
+ char *csi = int_to_ps26 (coli);
+ char *s = c_xasprintf ("%s%d:%s%ld",
+ cs0, row0 + 1,
+ csi, rowi + 1);
+ free (cs0);
+ free (csi);
+
+ return s;
}
return false;
str_uppercase (startcol);
- *col0 = pseudo_base26 (startcol);
+ *col0 = ps26_to_int (startcol);
str_uppercase (stopcol);
- *coli = pseudo_base26 (stopcol);
+ *coli = ps26_to_int (stopcol);
*row0 = startrow - 1;
*rowi = stoprow - 1 ;
int asw ; /* The width of string variables in the created dictionary */
};
-int pseudo_base26 (const char *str);
+int ps26_to_int (const char *str);
+char * int_to_ps26 (int);
bool convert_cell_ref (const char *ref,
int *col0, int *row0,
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->separators = separators_page_create (ia);
-
-
a->prop_renderer = gtk_cell_renderer_text_new ();
g_object_ref_sink (a->prop_renderer);
a->fixed_renderer = gtk_cell_renderer_text_new ();
"family", "Monospace",
(void *) NULL);
- ia->first_line = first_line_page_create (ia);
-
- ia->formats = formats_page_create (ia);
-
g_signal_connect (a->assistant, "prepare", G_CALLBACK (on_prepare), ia);
g_signal_connect (a->assistant, "cancel", G_CALLBACK (on_cancel), ia);
g_signal_connect (a->assistant, "close", G_CALLBACK (on_close), ia);
gtk_window_set_transient_for (GTK_WINDOW (a->assistant), parent_window);
gtk_window_set_icon_name (GTK_WINDOW (a->assistant), "pspp");
+
return ia;
}
int pn = gtk_assistant_get_current_page (assistant);
g_print ("%s:%d Page %d %p\n", __FILE__, __LINE__, pn, page);
- if (pn == 0)
- prepare_sheet_spec_page (ia);
+ if ( ia->spreadsheet)
+ {
+ if (pn == 0)
+ prepare_sheet_spec_page (ia);
+ else if (pn == 1)
+ {
+ post_sheet_spec_page (ia);
+ prepare_formats_page (ia);
+ }
+ }
-#if 0
if (gtk_assistant_get_page_type (assistant, page)
== GTK_ASSISTANT_PAGE_CONFIRM)
gtk_widget_grab_focus (assistant->apply);
gtk_widget_grab_focus (assistant->forward);
+
+#if 0
/* Prepare .... */
if (page == ia->separators->page)
prepare_separators_page (ia);
else if (page == ia->formats->page)
prepare_formats_page (ia);
- else if (page == ia->sheet_spec->page && ssp->spreadsheet)
- {
- prepare_sheet_spec_page (ia);
- }
-
+
+
gtk_widget_show (ia->asst.reset_button);
if (page == ia->formats->page)
gtk_widget_show (ia->asst.paste_button);
if (ia->spreadsheet == NULL)
ia->spreadsheet = gnumeric_probe (file->file_name);
- printf ("%s:%d %p\n", __FILE__, __LINE__, ia->spreadsheet);
-
if (ia->spreadsheet == NULL)
ia->spreadsheet = ods_probe (file->file_name);
- if (! ia->spreadsheet)
+ printf ("%s:%d %p\n", __FILE__, __LINE__, ia->spreadsheet);
+
+ if (ia->spreadsheet == NULL)
{
struct string input;
struct line_reader *reader = line_reader_for_file (file->encoding, file->file_name, O_RDONLY);
GtkBuilder *builder = ia->asst.builder;
struct formats_page *p = xzalloc (sizeof *p);
-#if 0
p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Formats"),
- GTK_ASSISTANT_PAGE_CONFIRM);
-#endif
+ GTK_ASSISTANT_PAGE_CONFIRM);
+
p->data_tree_view = GTK_TREE_VIEW (get_widget_assert (builder, "data"));
p->modified_vars = NULL;
p->modified_var_cnt = 0;
fg = fmt_guesser_create ();
for (column_idx = 0; column_idx < ia->column_cnt; column_idx++)
{
- struct variable *modified_var;
-
- modified_var = (column_idx < p->modified_var_cnt
- ? p->modified_vars[column_idx] : NULL);
+ struct variable *modified_var =
+ (column_idx < p->modified_var_cnt ? p->modified_vars[column_idx] : NULL);
if (modified_var == NULL)
{
struct column *column = &ia->columns[column_idx];
g_signal_connect (combo_box, "changed", G_CALLBACK (on_sheet_combo_changed), ia);
+ add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"),
+ GTK_ASSISTANT_PAGE_INTRO);
+
return p;
}
const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
- gint num = 0;
- if ( num < 1 )
- num = 1;
+ gint num = 1;
ssp->opts.sheet_name = NULL;
ssp->opts.cell_range = NULL;
ssp->opts.sheet_index = num;
+ printf ("%s:%d Range is %s\n", __FILE__, __LINE__, range);
+ printf ("%s:%d Sheet Number is %d\n", __FILE__, __LINE__, num);
+
if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
{
ssp->opts.cell_range = range;
+ printf ("%s:%d Range is valid\n", __FILE__, __LINE__);
}
ssp->sri.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
{
case SPREADSHEET_ODS:
{
+ printf ("%s:%d\n", __FILE__, __LINE__);
creader = ods_make_reader (ia->spreadsheet, &ssp->sri, &ssp->opts);
dict = ia->spreadsheet->dict;
}
break;
case SPREADSHEET_GNUMERIC:
{
+ printf ("%s:%d\n",__FILE__, __LINE__);
creader = gnumeric_make_reader (ia->spreadsheet, &ssp->sri, &ssp->opts);
dict = ia->spreadsheet->dict;
+ printf ("%s:%d Reader %p Dict %p\n",__FILE__, __LINE__, creader, dict);
}
break;
default:
struct sheet_spec_page *ssp = ia->sheet_spec;
int rows = 0;
+ printf ("%s:%d\n");
if (ssp->dict)
{
struct ccase *c;
int col;
+ printf ("%s:%d\n");
ia->column_cnt = dict_get_var_cnt (ssp->dict);
ia->columns = xcalloc (ia->column_cnt, sizeof (*ia->columns));
for (col = 0; col < ia->column_cnt ; ++col)
ssp = ia->sheet_spec;
- add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"),
- GTK_ASSISTANT_PAGE_INTRO);
-
- add_page_to_assistant (ia, get_widget_assert (builder, "Formats"),
- GTK_ASSISTANT_PAGE_CONFIRM);
-
+ if (ia->spreadsheet)
+ {
+ ia->sheet_spec = sheet_spec_page_create (ia);
+ }
+ else
+ {
+ ia->intro = intro_page_create (ia);
+ ia->separators = separators_page_create (ia);
+ ia->first_line = first_line_page_create (ia);
+ }
+ ia->formats = formats_page_create (ia);
gtk_widget_show_all (GTK_WIDGET (ia->asst.assistant));
break;
}
- destroy_formats_page (ia);
- destroy_separators_page (ia);
+ if (ssp)
+ {
+ destroy_formats_page (ia);
+ destroy_separators_page (ia);
+ }
destroy_assistant (ia);
destroy_file (ia);