X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-window.c;h=1475398b03b6725bb3bb162e48610f1410914460;hb=339f1956cc72;hp=15f8503de26589aba8b82de8bcccdce830b8a01e;hpb=196b7e19f0b117076d740b5809e9ecfec34982b2;p=pspp diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 15f8503de2..1475398b03 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -32,11 +32,9 @@ #include "data/file-handle-def.h" #include "data/dataset.h" #include "libpspp/version.h" -#include "output/group-item.h" +#include "output/output-item.h" #include "output/pivot-table.h" #include "output/spv/spv.h" -#include "output/spv/spv-output.h" -#include "output/spv/spv-select.h" #include "helper.h" #include "psppire-data-window.h" @@ -698,85 +696,11 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) return dialog; } -struct item_path - { - const struct spv_item **nodes; - size_t n; - -#define N_STUB 10 - const struct spv_item *stub[N_STUB]; - }; - -static void -swap_nodes (const struct spv_item **a, const struct spv_item **b) -{ - const struct spv_item *tmp = *a; - *a = *b; - *b = tmp; -} - -static void -get_path (const struct spv_item *item, struct item_path *path) -{ - size_t allocated = 10; - path->nodes = path->stub; - path->n = 0; - - while (item) - { - if (path->n >= allocated) - { - if (path->nodes == path->stub) - path->nodes = xmemdup (path->stub, sizeof path->stub); - path->nodes = x2nrealloc (path->nodes, &allocated, - sizeof *path->nodes); - } - path->nodes[path->n++] = item; - item = item->parent; - } - - for (size_t i = 0; i < path->n / 2; i++) - swap_nodes (&path->nodes[i], &path->nodes[path->n - i - 1]); -} - -static void -free_path (struct item_path *path) -{ - if (path && path->nodes != path->stub) - free (path->nodes); -} - -static void -dump_heading_transition (const struct spv_item *old, - const struct spv_item *new) -{ - if (old == new) - return; - - struct item_path old_path, new_path; - get_path (old, &old_path); - get_path (new, &new_path); - - size_t common = 0; - for (; common < old_path.n && common < new_path.n; common++) - if (old_path.nodes[common] != new_path.nodes[common]) - break; - - for (size_t i = common; i < old_path.n; i++) - group_close_item_submit (group_close_item_create ()); - for (size_t i = common; i < new_path.n; i++) - group_open_item_submit (group_open_item_create ( - new_path.nodes[i]->command_id)); - - free_path (&old_path); - free_path (&new_path); -} - void read_spv_file (const char *filename) { - struct spv_reader *spv; - char *error = spv_open (filename, &spv); + struct output_item *root; + char *error = spv_read (filename, &root, NULL); if (error) { /* XXX */ @@ -784,24 +708,7 @@ read_spv_file (const char *filename) return; } - struct spv_item **items; - size_t n_items; - spv_select (spv, NULL, 0, &items, &n_items); - struct spv_item *prev_heading = spv_get_root (spv); - for (size_t i = 0; i < n_items; i++) - { - struct spv_item *heading - = items[i]->type == SPV_ITEM_HEADING ? items[i] : items[i]->parent; - dump_heading_transition (prev_heading, heading); - if (items[i]->type == SPV_ITEM_TEXT) - spv_text_submit (items[i]); - else if (items[i]->type == SPV_ITEM_TABLE) - pivot_table_submit (spv_item_get_table (items[i])); - prev_heading = heading; - } - dump_heading_transition (prev_heading, spv_get_root (spv)); - free (items); - spv_close (spv); + output_item_submit_children (root); } /* Callback for the file_open action.