X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fspreadsheet-test.c;h=bec577821a68076fc20831580b00ed1bf3739677;hb=4e3feede0f6b3d2e67d6e41a9ddea3738e574dc3;hp=098858287923d0c5cd973cedb76c992ac2bc972c;hpb=ffe5ba65c269e9207308608139ea2cbb4fcb761f;p=pspp diff --git a/src/ui/gui/spreadsheet-test.c b/src/ui/gui/spreadsheet-test.c index 0988582879..bec577821a 100644 --- a/src/ui/gui/spreadsheet-test.c +++ b/src/ui/gui/spreadsheet-test.c @@ -28,30 +28,11 @@ #include "data/spreadsheet-reader.h" #include "data/casereader.h" #include "data/case.h" +#include "data/settings.h" +#include "libpspp/message.h" +#include "libpspp/i18n.h" -#if 0 -#define N 10 - - -static GtkListStore * -make_store () - { - int i; - GtkTreeIter iter; - - GtkListStore * list_store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING); - - for (i = 0; i < N; ++i) - { - gtk_list_store_append (list_store, &iter); - gtk_list_store_set (list_store, &iter, - 0, N - i, - 1, "xxx", - -1); - } - return list_store; - } -#endif +#include "gl/xalloc.h" struct xxx @@ -72,28 +53,40 @@ on_clicked (GtkButton *button, struct xxx *stuff) struct casereader *reader ; struct spreadsheet_read_options opts; - g_print( "%s %d\n", __FUNCTION__, x); - - opts.sheet_index = x + 1; - opts.cell_range = NULL; - opts.sheet_name = NULL; + opts.sheet_index = -1; + opts.cell_range = spreadsheet_get_sheet_range (stuff->sp, x); + opts.sheet_name = CONST_CAST (char *, + spreadsheet_get_sheet_name (stuff->sp, x)); opts.read_names = TRUE; opts.asw = -1; reader = spreadsheet_make_reader (stuff->sp, &opts); + + if (reader == NULL) + return; + proto = casereader_get_proto (reader); nvals = caseproto_get_n_widths (proto); - for (; - (c = casereader_read (reader)) != NULL; case_unref (c)) + for (; (c = casereader_read (reader)) != NULL; case_unref (c)) { int i; for (i = 0; i < nvals ; ++i) { - const double val = case_data_idx (c, i)->f; - printf ("%g ", val); + const int width = caseproto_get_width (proto, i); + const union value *val = case_data_idx (c, i); + if (0 == width) + printf ("%g ", val->f); + else + { + char *ss = xzalloc (width + 1); + memcpy (ss, value_str (val, width), width); + + printf ("%s ", ss); + free (ss); + } } printf ("\n"); } @@ -101,6 +94,12 @@ on_clicked (GtkButton *button, struct xxx *stuff) casereader_destroy (reader); } +static void +print_msg (const struct msg *m, void *aux UNUSED) +{ + fprintf (stderr, "%s\n", m->text); +} + int main (int argc, char *argv[] ) @@ -114,11 +113,16 @@ main (int argc, char *argv[] ) GtkWidget *button; struct xxx stuff; + i18n_init (); + settings_init (); + gtk_init (&argc, &argv); if ( argc < 2) g_error ("Usage: prog file\n"); + msg_set_handler (print_msg, 0); + stuff.sp = NULL; if (stuff.sp == NULL) @@ -187,7 +191,7 @@ main (int argc, char *argv[] ) gtk_main (); - // gnumeric_destroy (sp); - + spreadsheet_destroy (stuff.sp); + return 0; }